Halloween Costume ideas 2015
Articles by "function"
@dorothiar #arttips #interview 101 2 Column Template 2012 mentee 2013 2013 mentee 2014 2014 mentee 2014 Portfolio Winner 2014 SCBWI Portfolio Mentorship Winner 2015 mentee 3 Column Template 360 3d 3d print 3d printing 3delight 8bit Abbey McCulloch abstract acryla gouache acrylic action addon adobe Adobe Flash CS3 Adobe Illustrator Advanced Tutorials advection Advertising advice Agata Wierzbicka agents airplane Al Wiseman ALA Alan E. Cober Alan Lee Alex Ross Alexandra Compain-Tissier Alexandra Lekias Alexandra Levasseur Alexandre Korobov Alexis Winter algorithm alien ALT Amelie Hegardt Amit Shimoni amusement an Ana Aranda analog Andrea Hrjnak Andrea Hrnjak andrea offermann andreaoffermann andreazuill Andy Musser Angela DiTerlizzi Angelika Peißker animal logic animals animation animation nodes anime anisculpt Anja Kroencke Anna Higgie Anna Jensen Anna McKay Annabel Briens AnneBerry Anneke Krull Annu Kilpeläinen anstudy anthology António Soares ar arduino area armature arrange array array modifier arrow art art director art directors Art is fun! art reps art tools Artaksiniya arthictecture arthur rackham artists artwork ase Ashlyn Anstee Asian aspiring asset atom attribute attribute transfer audio Audrey Kawasaki augmented reality aurasma Aurelius Battaglia author illustrator automatic automation Autumn Whitehurst avatar Avrom Yanovsky AW14/15 award awards Babeth Lafon Babies baboon Baby Love Background background color bacteria bake baking ball Bamboo banner Banner images banner making Barbara Dziadosz barcode basic bbox beads beats Bec Winnel beginner Bel Johnstone Ben Denison Bernie Fuchs Berto Martinez Beth Krush better photos bge Bijou Karman Bike biscuit bishop black and white black and white art Blair Breitenstein blam blender blender game engine blender3d blending Blinkie Blinky blob blocks Blog Tips blogger Blogging Friends blogs Blonde blur effect in pixlr and photoshop blur images and pictures bmesh bmesh viewer bolognaragazziaward bombing bone bone modeling bones book book launch books boomerang bottle bounding box bowl bpy brian eno brian ormiston Brian Sanders brian won brick bridge Bridget Davies bright Brooke Boynton Hughes build modifier building burns business Buttons bvh cage Caitlin Shearer caldecott calibration camera camera settings camera tips Candle capcom card career Carole Wilmet cartoony Cassandra Rhodin cast Catherine Campbell Cecilia Carlstedt cell center pivot centipede cg cg photography chair challenge Chanel changin color in pixlr changing color chaos character Character Bible character development charcoal charles Charlie Dot Charlie Hebdo Children children's book illustration chocolate Christina Drejenstam christina forshay Christina K christinaforshay Christmas Cindy Derby circle circle dance city cityengine clock clones cloning cloth Cloud based clover CMYK Coco Chanel Cody and the Fountain of Happiness coffee collect collection Collections collision color color balance color cast color correction color mode color study colorful Commercial Use complexity component compositing composition computational thinking computer concept art Condensed Posts conference connect connect the dot connection Connie Lim Conrad Roset constrain constrast contagion content Contest contracts control converter copy copyright Corinna Luyken count Courtney Brims crack Craft craftsmanship Craig & Karl creative creativity creature cricket Cristina Garcia Martin critic criticism critique Crop Crop Tool cross section crowd csv cubism curve curve modifier custom Custom Blog Design Custom Blog Design Tutorial Custom Blog Designers Custom Illustration custom properties Custom Signature custom xml cut cutting plane cycle cycles dae Damien Florébert Cuypers Dan Hillier dance Daniel Egnéus Daniel Segrove Danny Roberts Daren Newman Dasha Tolstikova data data path David Blossom david diaz David Shrigley David Stone Martin Dean Hardscrabble Debbie debbie ohi debbieohi deform deformer degrees deleting background in pixler demo demoscene desaturation of images design design by numbers design process Design Tips dictionaries dictionary Different Text Writing in Pixlr digital digital paint Digital Scrapbook Freebies Digital Scrapbooking disk distance distractions distribute diversion DIY DIY Contest Dolf Veenvliet Doll Doll Bones dolls domino domino effect doodle Doodles door doraemon Doris Jackson Dorothia Rohner dots dpi draw drawing drill driven driver drivers dual versions dummy duplicate duplicates duplication dupliframe dvd dynamic dynamic paint dynamic text E Simms Campbell Easy easy pixlr Easy Tutorials Ed Graham Ed Vebell editing editing photos editors education effect effects ego Eleanor Dalton electric Elia Fernández eliza wheeler Elizabeth Mayville elizawheeler Emily Forgot Emma Zanelli emoticon happy-face Emotional storytelling empathetic characters empty entoforms envy epicycloid EPS Illustration Epson scanner erasers Erin Armstrong Erin Petson erinoshea ernest shepard Esra Roise euler evaluate line Eveline Tarunadjaja evenly spacing vertex event everywhere door exhibition Expandable Posts experiments explode exploded view export expression extrude eye eye color in pixlr eye trick eyeball face rig facial expressions facial setup factory Faiyaz Jafri Families fashion illustration fashion week fcurve feature Featured Fee Harding Feedback fence Fernanda Guedes fibonacci Fifi Lapin file File Types Finalists Finding Nemo fire fix photos Flash Tutorials flicker flip flip flop floor flop flow flower Flowers fnmatch focal point follow up font Fontaine Anderson Fonts food footage For Sale force form formula fractal fracture frame Frames Francois Berthoud Frank Bellamy Frank Furlong Franklin McMahon freckles Fred Steffen FrederiqueBertrand Free for Commercial Use Free for Personal Use Free Stock Photography Free transform tool Freebies Frenchillustration Fritz Siebel frosted mylar fruit ninja Fumi Mini Nakamura Fun function futurism FW2017 fx Gabriel Moreno Gabriella Ibarra game game animation gameart gamma gangnam style Garance Doré Gary Fernandéz gel medium generate generative generator geometric geometry Gerald Lazare Géraldine Georges GIF Gildo Medina Girl Giuseppe Castellano Giveaway glorar goals golden ratio google google docs Google Tools Grant Young graph graphite graphite transfer grease pencil grid group group node growth Gucci Guest Guil Godier gustave dore hair handbook Harper's Bazaar harpercollins Harvey Schmidt Haute Couture head Headers heat map Helena Hauss hexagon hexagonal grid Hiroshi Mizuno Hiroshi Tanabe Holiday Holly Black homology honeycomb hook horror houdini how to how to blur a face or an object in pixlr How to change eye color how to delete an object how to desaturate an image how to edit a image in pixlr how to erase an object how to fix red eye problem how to fix red eyes in pixlt How to fix the parts in pixlr in photoshop How to make a banner in pixlr How to overlap the nevus how to remove a object How to remove an object in pixlr how to remove red eyes How to Remove the Background of an Image in Pixlr How to remove the parts that you don't want in pixlr and photoshop how to replace color How to write a Patterned Text in Pixlr how-to Hsiao-Ron Cheng hsv hue humor Hyshil I love illustration magazine idea ideas Igor+André illusion illustrating illustration illustration board Illustration Books Illustration Intensive Illustration Now! Fashion illustration process Illustrations Illustrative Berlin illustrator Illustrator Intensive Illustrator Tutorials iloveillustration magazine image ediditing lessons Image Ready image sequences image theft imaginative import import text import vertex color improving photos inbetween index visualizer Info Ingrid Bockting ink inktober input Inspiration inspirational quotes install instance instance switching intensive interaction Intermediate Tutorials internet interoperability interpolation intersect intersect edges intersecting intersection interview introduction invoke subprogram io ipad Irana Doucer Isabella Hemmersbach islam islamic iteration Izzie Klingels Jack Hearne Jack Tremblay James Dignan James Gurney japanese Jason Brooks Jean Kim Jeanne Detallante Jen and Chris Creed Photography jen betton Jen Rofé Jenny Mörtsell Jeremy Combot Jeslyn Kate Jesse Auersalo Jessica Jessica Lanan jessicalanan jewellery jewelry jiggle Jim Schaeffing Joe Bowler Joe Cleary Joe Isom Joe Krush Johanna Goodman john maeda John Vernon Lord joint Jordan Sondler JPEG JPG jpop juana martinez-neal juanamartinezneal Judge Judit Garcia Talavera Judith van den Hoek Judy Byron Schachner Jules Julien Julian Beever Julie Verhoeven Jump Break Tool JW Anderson K-Fai Steele Kaethe Butcher Kareem Iliya karel zeman Kate van Harreveld Kathrin Kuhn Kathryn Ault Noble Kathryn Noble Katie Kath kdtree Kei Meguro Kelly Beeman Kelly Light Kelly Smith kelly sonnack Kelly Thompson keyframe keyframing kidlit kidlitartists kimberlygee Kirkus Review Kisoo Chai Kodak Konstantin Kakanias Korean illustration Kotaro Chiba Kozue Himi Kremos Ksenia Finogeeva KT Smail kuler Kustaa Saksi Lanan Laptop larry gritz lasso tool latte lattice Laura Callaghan Laura Laine Lauren Rille layer layering Layla Holzer layout leaf learning learning blender LED Leendert meets Ingrid lego length Leonard Starr lessons levels LFW A/W 14 liangzhu liero lightbox lighting lightning Lina Bodén Lina Ekstrand Linda Dorn line line connect line drawing lines Links Linky Love Linn Olofsdotter Lionel Gilbert Lisa Anchin Lisa Billvik Lisa Krannichfeld lisaanchin lisbeth zwerger Liselotte Watkins list list comprehension List First Last listing locator lofting logo Logo Design Lola Dupré London Fashion Week loop looping loops looptools Lorraine Fox lossless lossy lost weekend lostweekend lotte reininger Louis Glanzman louis vuitton Luciana Rondolini luciograph LULU* lv Lynnie Zulu Mac macgyver macouno maeda Magda Antoniuk magic Magnus Voll Mathiassen mailing mailings maker Makiko Sugawa making banners Malika Favre MAMP mandala manga map map range maplelam mapping Marcel George Maren Esdar Margot Macé Margot van Huijkelom Maribeth Olson Marie El-Ahmar Marilyn Conover Marina Esmeraldo Marine Marbleindex mario Marlies Niemeijer Marsha Riti Martha Rago Martin Krusche Martine Johanna mask masking material materials math matrix matrix apply matryoshka Matt Baker matte medium Matthew Woodson maya maze mdd Meagan Morrison measure megaman Megan Hess Meizhen Xu Mel Crawford memory mentee mentees mentors mentorship program Mercer Mayer Meridth McKean Gimbel mesh mesh cutter meshlab Meta Tags metal gear rising Meyoko Mia Overgaard Micca mice Michael Sanderson Michela Picchi middle grade midi miku Milan milipede minidom Minima Mio Matsumoto mirror cut Misc Miss Blackbirdy miss maple's seeds Miss Take Mitchell Hooks mixamo mixing Mobile Apps mocap mod model modeling modifier modular modulation modulus mold molecule molly idle Molly Ruttan Molly Ruttan Illustration money monitors monkey mono-zero monster monster university morph morpher mosaic mosquito motion motion capture motion capture mouse motion trail moto360 mountain muji Muriel Wood Murray Tinkelman mushroom Music and Podcasts My dead pony Nadia Flower Naiad Einsel Naja Conrad-Hansen Natalie Brockett Natalie Foss nathan vegdahl nautilus Nav Bar navigation needle-felting negotiating Neil Boyle neon nescbwi14 nested New Blogger Questions New Blogger Template Tutorials new user pixlr new year new york New York Fashion week Newbery nicholas nicholas bishop Nicholas Hong Niki Pilkington Niso Ramponi nla No Software node node-based nodebox noise non linear animation Non-Web Font normal Noumeda Carbone npr number NURBS NYFW object object color change object info octopus offset Ola Volo Olaf Hayek old formats opaque projector open movie open shading language open source openshadinglanguage opensoundcontrol optical organization origami original art show Ornaments osc Oscar Schlienger osipa osl outline outliner output Pages paint paint weight painting painting on illustration board painting on wood painting with movie painting with numbers Pair pandas panorama Paper paper lantern parabola parametric parent parenting particle particle info node particles pat david Pat Zietlow Miller pattern Patterned Text Paul Faassen Paul X. Johnson Paula Sanz Caballero PC pdb pebbles pencil Pencil Sketch pencils Penguin perfume perlin Peter Helck Photo CD.8B photo editing software Photo Reference Photobucket photographing art Photographs photography photomerge photoshop Photoshop Brushes Photoshop CS3 Photoshop elements photoshop pixlr desaturaion Photoshop tips Photoshop Tutorials Picture Book Builders picture books Pierre Louis Mascia Piet Paris Pietari Posti pingpong pinnochio pipes pixar pixel pixel art pixel generator pixlr Pixlr advanced Pixlr blog pixlr desaturate keep a colorful part pixlr editting pixlr express Pixlr forum Pixlr free transform Pixlr Lesson Pixlr lessons Pixlr mobile Pixlr resizing images pixlr shortcuts Pixlr tools pixlr tutorial pixlr tutorial with pictures Pixlr Tutorials pixlr white black pixlr.com plant plot plotting ply PNG PNG Illustration podcast point point color pointilism polka dots polyCut polygon Pomme Chan pop-overs portfolio Portfolio award portfolio showcase portfolio-advice portrait position Post Dividers postcard poster Posting pot powdered graphite powerhousemuseum Prada presentation print printmaking Prize procedular procedural process processing programming projection Promotion property prototype PSD psy publishing pulse puppet puppetry pydriver pydrivers pyhandler pyhandlers pyramide python quad quick select set quick tips qumarion Rabbit Moon Rachel Ryle radians radius ramp random random motion randomization randomize range float raspi Ray Houlihan reading reading XML READY-TO-WEAR realflow Rebecca Clarke rebecca dautremer Rebecka Skog rebuild recursive recursivedrawing red eye remove reducing glare reference referencing release remesh modifier remix removal remove remove red eyes remove unwanted objects Removing backgroung render rendering renderman repeat repeater repeating replace replacement replacing color representation rerouter resample resampling research Resizing image resolutions retopology retro review revolve rgb rib Ricardo Fumanal Richard Scarry rig rigging rigify Rikke Jorgensen ring ripple roadkill Robert Heindel Robert J. Lee Robert McCloskey Robert Shore Roberta Zeta Robin Rosenthal robot robotic rocks Rodolfo Montalvo Roller Coaster rotation Rousseau rsl Rubin Pfeffer ruler tool Russ Mills russian rut S/S14 S/S15 S/S16 Sabine Pieper sadako Saftey Pins Sainte Maria Sale Sam Weber Sanda Suy Sandy Kossin santoso Sara Andreasson Sara Singh Sarah Jacoby saturation artist tools scan scanners scanning scatter scbwi SCBWI 2015 mentee SCBWI conference scbwi germany SCBWI mentorship scbwi-la scratch scratchboards screensaver screw screw modifier script scrub sculpting seamless Seamless Patterns Search Engines select by material select by name select by type SEO sequence series set keyframe set keyframes shader shading shadow Shannon Stirnweis shape grammars shape key shapekeys shapes shards shatter Sheilah Beckett shell ship shipping shipwright Shoes SHOWstudio shuffle Sid Barron Sidebar Titles Signature Silja Goetz silkworm Simon and Schuster Simon Varela simple simplicity simulation sine Site Engine Optimization Sjoukje Bierma sketch Sketches sketching skin skin modifier skinning slice slicing slides sloth slow parent smoke smoothstep SN snake Sneek Peek snippet Snow Snow White Snowflakes soccerball social media Social Media Buttons Social Networking society of illustrators Society6 soft body softbody Sonia Menti sound sound wave space spaceship sparta special spider spiderman spiderweb spin spiral Spiros Halaris Spiros Halaris x Urban Decay spline Spot Healing Tool spreadsheet SS16 stack stacking stair stamp Stan Galli star starfish stencyl step Steven G. Dobson still Stina Persson stone stones storytelling strand strand info strands street art string stripes structure studies studio style stylistic summary Summary Posts Summer sun supplies surface Susan Farrington suzanne Suzanne Kaufman sverchok swatch switch sydney system table table of contents take out background Tal Drori tangent tangled Taschen teaching teapot Template Templates tentacle Tess Jacobson Tex Avery text text editor Text Formats Text Styles in Pixlr texture texturing The Cartorialist The Grudge Keeper The Purple Book thinker1 Thomas B. Sawyer thread TIFF tile tilecam tiling time time code Tina Berning Tina Kugler tips tips for artists Toby Neilan Tom Baxter Tom Bjarnason tombow tomie depaola tool tools topology tower Tracy Turnbull Train transfer drawing transferring sketch transform transformation transit travel triangle wave Tricia Springstubb trigger tris tristan lock tube tubes Tutorials twitter type tool typeface typography unbake unity3d universal unquad utah uv valentine Valentino Valerie Servais vanilla variable variation variety vase vector vectorized Velwyn Yossy venus Veronica Ballart Lilja vertex vertex color vertex group vertex paint vertex weight VFX Victoria Boysen video Videos viewer Vintage virtual virtual studio visualization vivid vividfestival VOGUE volumetric voronoi Vote voxel voxelated voxelation walking teapot Walter Einsel wand tool water soluble graphite watercolor wav wave we need diverse books web webbing Week Themes weight welcome Wendy magazine Wendy Plovmand what casues red eyes What is Pixlr Wherever You Go Wide Awake Bear wiggle Will Davies Winner Winnie Fitch Winnie Truong Winter wire wired wireframe wolfram Woman wood woodwork wool wooly wordpress work workflow World writing writing XML www.pixlr.com XML YA yayoi kusama Yelena Bryksenkova yoda Yoko Furusho Yuliya zaha hadid zen zsphere

One only really knows how deep the water when he jumps, otherwise he will only be touching the surface.

After reading that book titled "Open Shading Language for Blender" by Michel Anders which I reviewed in previous post, I decided to revisit some of previous OSL topics and hopefully can make some parts clearer and will explore further some basic concepts.

From this post onward, I am going to write OSL shaders following the structure that Michel uses. And I will probably use some snippet of codes from Michel book, such us when we like to Rotate or Scale or to Mirror procedural textures. When I do so, I will give credit to Michel.

My focus is still on the Procedural Texture and Patterns Generation only, but overtime, I want to also start discovering some useful OSL features we can use.

CONTROLLING SIGNAL USING THE FORCE

I use word "The Force" in the previous posts to help some beginners to grasp the basic concept of pattern generation. Whenever using "The Force", we are really using Math FUNCTIONS (2D or 3D functions) that generates pattern or further modify and reshape pattern. It is okey, you can still think of function as the force.

As you may already see in previous posts, the easiest way we can apply a FUNCTIONS and to actually generate a procedural texture is: to insert the function as a FACTOR of mix() function that will then modulate between 2 colors. The mix() function does this kind of job of MIXING 2 colors really well as we can see later.

Ok, if above paragraph might sound very alien to you, do not worry, I am really going to go back to the basic and slowly building up the complexity.

MATH, FUNCTIONS, AND OSL

Function is a "magical force" that takes input and gives you an output. The "magical force" is Math operations. The Math can be very simple like addition, but can also be really complex.

We do not need to worry about the complexity of functions, all we need to care is to know which function does what to the input and just apply it to get the output.

In computer graphics, we really use functions all the time. Maybe some of you have some computer animation background and you know that you can graph a motion.

With OSL, we will be dealing with function, but especially to see how function can modify and generate pattern of colors.

For example:
Let say we have a function (x + x), which takes input x.
If x = 2, function f(x + x) will give you result of 4.
If x = 4, function f(x + x) will give you result of 8.

We will be dealing with functions all the time when writing OSL.  Time to time, I refer to Renderman documentation on its built-in functions.
http://renderman.pixar.com/resources/current/rps/rslFunctions.html
http://web.engr.oregonstate.edu/~mjb/prman/shaderfunctions.html

INCLUDE
If you see #include notation at the beginning of OSL shader, it means that the shader loads some additional functions in C language that we can use later. <-- Let me know if I am wrong, I am only guessing.

For example:
#include "stdosl.h"

This is stdosl.h file if you open it and look inside. It has some additional variable we can use such as M_PI, etc.

Of course not all functions in Renderman available in OSL, but there are plenty of similar functions, and we can always create/write own function that mimics certain function.
  • sin(), cos() -> wave pattern
  • mod() aka MODULUS
  • abs()
  • sign()
  • step()
  • max()
  • min()
  • smoohstep()
  • ...

More interesting function:
  • distance()
  • noise() -> this function comes in many multiple forms




I want to slowly showing and visualizing each functions that are available in OSL by default and adding reference related to it. Read also OSL specification PDF documentation about functions.
http://www.openshading.com/osl/getting-started/

OSL AND MIX FUNCTION

I am afraid that I started to become very wordy, so now time to get inside Blender and start making things.

My favourite layout is like below:


STEP 001
shader basic_function(
    color ColA = color(1, 0, 0),
    color ColB = color(0, 1, 0),
    output color ColOut = color(0, 0, 1)
)
{
}

That OSL shader above is already working, but it really does nothing much other than:

  • Create color variable ColA and assign RED color.
  • Create color variable ColB and assign GREEN color.
  • With OSL shader to work, we need to have output, so we create a color output and assign it the default color of BLUE. Hence the shader resulting of plain BLUE color.
  • We have not done anything yet inside the shader. 
STEP 002
shader basic_function(
    color ColA = color(1, 0, 0),
    color ColB = color(0, 1, 0),
    output color ColOut = color(0, 0, 1)
)
{
    ColOut = mix(ColA, ColB, 0.5); 
}

We can do something like above which simply mixes 2 colors ColA and ColB and give a result of color that is yellowish. That is our first use of mix() function inside the shader.


Although that is not particularly interesting.

STEP 003
shader basic_function(
    point Pos = P,
    color ColA = color(1, 0, 0),
    color ColB = color(0, 1, 0),
    output color ColOut = color(0, 0, 1)
)
{
    float x = Pos[0];
    float y = Pos[1];
    float z = Pos[2];
    
    ColOut = mix(ColA, ColB, x); 
}

We modify the code and here we bring in P. P is a built-in Global Variable, it is basically storing the pixel position of a surface geometry.

P is really a set of array of 3 values that can be broken up into 3 x Float values, and for ease of use, we just tell Blender to think of it as the X, Y, Z.

Here, things started to get interesting. As you can see, we can mix the 2 colors using X, Y, or Z and it will give a result.


This is fine and dandy. Eventhough we are getting a result, it is still hard to figure out what is really happening in the background. Why is is when we insert the X into mix(), it gives us the result above? What does the function really do to the input values of P?


STEP 004: Experiment time!

COOL: Visualizing Function Using Google Search Plotter

A function can be more easily visualized using graph. The graph itself can be 2D or 3D. Thanks to Google, we can use Google Search to quickly plot graph of function.

For the above function, we are really just using the X values (that goes from minus infinity to zero all the way to positive infinity). And so we get that almost sharp blend between RED and GREEN.

Let's try below:

Google Search: x + y



Let's apply that function inside Blender:

Now, we can really see what is happening! That function is kind of mixing color by slicing into two big area inside square, so that whatever underneath the slice gets the RED and the other half gets the GREEN.

It is very exciting, let's continue with other functions!

Google Search: x * x



You see how it is just a bit touching and it gives that nice blurry red line along Y axis? Apparently we can get more blurry when we divide the X.


Let's try something different:

Google Search: abs(x)



Absolute function abs() will return the absolute value, when we insert X position, we are getting value that is always positive.

In term of writing the function, let's write it like below:

shader basic_function(
    point Pos = P,
    color ColA = color(1, 0, 0),
    color ColB = color(0, 1, 0),
    output color ColOut = color(0, 0, 1)
)
{
    float x = Pos[0];
    float y = Pos[1];
    float z = Pos[2];
    
    float f = abs(x);
    
    ColOut = mix(ColA, ColB, f); 
}

With the absolute function, we can further do something like maybe OFFSET the graph slightly above or below the axis, by modifying the function slightly:



You can see now how we can OFFSET or TRANSLATE that RED "line" quite easily.


Google Search: sin(x)




SNIPPET: sign() function


Google Search: sin(x) + sin(y)

Occasionally, Google gave back a 3D graph, like when we use function above. How would that affect our procedural texture inside OSL?


That is pretty interesting, right?


Of course, not everything can be graphed by Google Plotter, sometimes we need to further test it inside Blender, however, it is a good start. You can also use Wolfram Alpha sometimes for graphing, although the feature is limited unless you have pro account.

RIPPLE FUNCTION

If you do a bit more research on function, you might find "basic functions" that gives a pattern you need.

A quick search using Google leads me to this:

Very useful website and we can certainly borrow the example functions. Of course, things are not always clear cut and of the way we write the function may need to be converted to OSL way of writing function, for example:

x^2 => pow(x,2);

Things like this you learn by looking at examples, by trial and error, you gain experience.

Google Search: sin(10 * ((x/10)^2+(y/10)^2))/10

BLENDER OSL
shader basic_function(
    point Pos = P,
    color ColA = color(1, 0, 0),
    color ColB = color(0, 1, 0),
    output color ColOut = color(0, 0, 1)
)
{
    float x = Pos[0];
    float y = Pos[1];
    float z = Pos[2];
       
    float f = sin(10 * (pow(x/10,2)+pow(y/10,2)))/10;
    
    ColOut = mix(ColA, ColB, sign(f)); 
}




OTHER USEFUL FUNCTIONS

Based on this website:

POWER FUNCTION pow()
To increase the contrast. See below how we can implement it:


SAWTOOH WAVE FUNCTION

x - floor(x)

We can use Wolframalpha for graphing, but I do not like how Wolframalpha keeps asking to sign up for pro feature. So, usually I rely more on blogs and Wiki for informations.


The SAWTOOTH function is interestingly similar to MODULUS function graph, that we have used in previous post when we are generating repeating stripes pattern.


NOISE FUNCTION

noise(x) -> there are many ways we can use the noise function.

Noise gives output that range from 0-1, some other noise may give different range.


Noise function is one of the most interesting and useful functions to generate procedural pattern that is more natural and less repetitive.






cellnoise()


Those are all just the basic of functions, hopefully you can understand this part alright.

SINGLE DOT

I think I wrote about how we can create a single dot using OSL, after reading Michel's book, I am thinking to revisit the idea. It is basically related to distance() function.


distance() and sin()


distance() & modulus mod()



Disturbing the HSV Color Space using Noise.




FURTHER TWEAKING.... or FURTHER TWERKING WITH SHADER? (Updated: 2013.11.28)


sign() function results in texture that is crisp, I think we can assume it creates -1 or 1, no in between. This might be good, but in some cases, we actually want a bit of blur/fuzz, so that we do not get moire pattern. This relates to Anti-Aliasing.

Above started to look like WOOD or WATERMELON shader. However, we need to remember the LAYERING method that I mentioned in the previous post.

It's fun to play around with Math function. Sometimes you get interesting complex pattern by accident. For me, the harder parts will be:
  • To understand what is happening and use it to advantage
  • To make distinction of 2D and 3D procedural texture
  • To organize the shader code so it can be expanded
Maybe with more experience, thing gets a lot easier.

FURTHER SHADER TWEAKING: Combining Star Shader and Other Snippet
THE CODE:
#include "stdosl.h"

shader DPStar(
    int npoints = 5,
    float sctr = 0.5,
    float tctr = 0.5,
    color Color_A = color(1,0,0),
    color Color_B = color(0,1,0),
    float rmin = 0.07,
    float rmax = 0.2,
    float freq = 1.0,
    point Pos = P, // added this so that Vector can be plugged
    output color Col_Out = color(0.8)
)

{
    float PI = M_PI; 
    float ss;
    float tt;
    float angle;
    float r;
    float a;
    float in_out;
    float starangle = 2*PI/npoints;
    
    point p0 = rmax * point(cos(0),sin(0),0);
    point p1 = rmin * point(cos(starangle/2),sin(starangle/2),0);
    
    point d0 = p1 - p0;
    point d1;
    
    float x = Pos[0];
    float y = Pos[1];
    
    ss = x - sctr;
    tt = y - tctr; // s t become u v or X and Y
    angle = atan2(ss, tt) + PI;
    r = sqrt(ss*ss + tt*tt);
    a = mod(angle, starangle)/starangle;
    
    if (a >= 0.5)
        a = 1 - a;

    d1 = r * point(cos(a), sin(a),0) - p0;

    in_out = step(0, d1[0]);
    

    // snippet of my little code
    point myPoint = point(0,0,0);
    float f = distance(d1, a);
    
    Col_Out = mix(Color_A,Color_B, sin(f * freq));
   
}

Psychedelic Christmas..?


ADD NOISE FUNCTION....

THE CODE:
#include "stdosl.h"

shader DPStar(
    int npoints = 5,
    float sctr = 0.5,
    float tctr = 0.5,
    color Color_A = color(1,0,0),
    color Color_B = color(0,1,0),
    float rmin = 0.07,
    float rmax = 0.2,
    float freq = 1.0,
    point Pos = P, // added this so that Vector can be plugged
    output color Col_Out = color(0.8)
)

{
    float PI = M_PI; 
    float ss;
    float tt;
    float angle;
    float r;
    float a;
    float in_out;
    float starangle = 2*PI/npoints;
    
    point p0 = rmax * point(cos(0),sin(0),0);
    point p1 = rmin * point(cos(starangle/2),sin(starangle/2),0);
    
    point d0 = p1 - p0;
    point d1;
    
    float x = Pos[0];
    float y = Pos[1];
    
    ss = x - sctr;
    tt = y - tctr; // s t become u v or X and Y
    angle = atan2(ss, tt) + PI;
    r = sqrt(ss*ss + tt*tt);
    a = mod(angle, starangle)/starangle;
    
    if (a >= 0.5)
        a = 1 - a;

    d1 = r * point(cos(a), sin(a),0) - p0;

    in_out = step(0, d1[0]);
    

    // snippet of my little code
    point myPoint = point(0,0,0);
    float f = distance(d1, a);
    
    Col_Out = mix(Color_A,Color_B, sin(f * freq * noise(f, freq)));
   
}

It feels like Christmas alraedy!
How to turn this shader into something that looks more like "explosion", does anyone know? If you do, please let me know. Thanks!


OTHER LINKS

It is as if we are going back in time and start again with OSL from zero...

I want to touch few OSL functions to create basic procedural texture (regular pattern).

This writing about basic OSL functions will be based on:
http://accad.osu.edu/~smay/RManNotes/RegularPatterns/transitions.html
http://accad.osu.edu/~smay/RManNotes/RegularPatterns/mod.html

And I will also reference the "Open Shading Language Specification" PDF.

On top of that, I also will use the concept of LAYERING in the code. Read my 2 previous posts before this one to be clear.

STEP() FUNCTION

You are probably familiar with step keys in animation curve which result in having "no transition" whatsoever between 2 keyframes.

There is a built in function called step() in OSL, it takes 2 values.

From OSL specs:
float step (float edge, float x)
Returns 0 if x<edge and 1 if x >= edge.

We can pass in point, vector, normal, or color into step function, as long we do it separately per value.

It will be clear when we use it in code, let me show you.

NOTE:
In my code, I almost always do this below in regards to assigning vector P to vector Pos and the using the Pos values as s, t, and u.



EXAMPLE CODE:
// Helper Function
// We will always need this blend() function
// to help to do the layering effect
color blend(
    color a,
    color b,
    color x
)

{
    return ((a) * (1-(x)) + (b) * (x));
}

shader simpleStep(
    color ColA = color(1,0,0), // red
    color ColB = color(0,1,0), // green
    vector Pos = P,
    output color Col_Out = color(0.2)
)
{
    // initialize color value into our LAYERING concept
    color surface_color = ColA; // assign ColA as base color
    color layer_color = ColB; // assign ColB as the layer on top of base
    color layer_opac = color(1);
    
    // s, t value from Pos
    float s = Pos[0];
    float t = Pos[1];
    
    // here we use the function
    layer_opac = step(s, 0);
    
    // layering
    surface_color = blend(surface_color, layer_color, layer_opac);
    
    // output
    Col_Out = surface_color;
    
}


THE RESULT:
If I modify the step(s,0) to step(t,0), we get result like below:


For beginner, I think it is OKEY to think our procedural texture in 2D coordinate. 

My plane geometry above is 1 x 1 in dimension. We can modify the "bias" in step() function to adjust the edge position. For example:
step(s, 0.2);
step(s, -0.5);
step(s, 4);

That will slide or offset the edge.

WAVE FUNCTION: sin(), cos()

We will get a more interesting result when we start to mix other Math function, such as the SINE and COSINE function that is basically going up and down like wave, where we usually can modify: frequency, amplitude and offset the wave.

EXAMPLE CODE:
// Helper Function
// We will always need this blend() function
// to help to do the layering effect
color blend(
    color a,
    color b,
    color x
)

{
    return ((a) * (1-(x)) + (b) * (x));
}

shader simpleStep(
    color ColA = color(1,0,0), // red
    color ColB = color(0,1,0), // green
    vector Pos = P,
    output color Col_Out = color(0.2)
)
{
    // initialize color value into our LAYERING concept
    color surface_color = ColA; // assign ColA as base color
    color layer_color = ColB; // assign ColB as the layer on top of base
    color layer_opac = color(1);
    
    // s, t value from Pos
    float s = Pos[0];
    float t = Pos[1];
    
    // here we use the function
    layer_opac = step(sin(s * 20), 0);
    
    // layering
    surface_color = blend(surface_color, layer_color, layer_opac);
    
    // output
    Col_Out = surface_color;
    
}

THE RESULT:
That seems like a quick and fast way to get repeating stripes. But later below you will see that we can also use mod() aka modulus function to get repeating stripes.

And look if I change the function slightly:
layer_opac = step(s, sin(t * 4));

SEE ALSO: 
Repater.osl from Geoffrey

MOD() FUNCTION

Mod (%) or modulus or modulation is an interesting function. It gives an effect of repeating pattern. If we use number:
10 % 5 = 0
9 % 5 = 4
8 % 5 = 3
7 % 5 = 2
6 % 5 = 1
5 % 5 = 0

It gives a see-saw pattern when drawn as curve. Let's try that:

EXAMPLE CODE:
// Helper Function
// We will always need this blend() function
// to help to do the layering effect
color blend(
    color a,
    color b,
    color x
)

{
    return ((a) * (1-(x)) + (b) * (x));
}

shader simpleStep(
    color ColA = color(1,0,0), // red
    color ColB = color(0,1,0), // green
    vector Pos = P,
    output color Col_Out = color(0.2)
)
{
    // initialize color value into our LAYERING concept
    color surface_color = ColA; // assign ColA as base color
    color layer_color = ColB; // assign ColB as the layer on top of base
    color layer_opac = color(1);
    
    // s, t value from Pos
    float s = Pos[0];
    float t = Pos[1];
    
    // here we use the function
    layer_opac = step(s, mod(t,2));
    
    // layering
    surface_color = blend(surface_color, layer_color, layer_opac);
    
    // output
    Col_Out = surface_color;
    
}

THE RESULT:
Later on, we will be using repeat() function, which is basically a modified version of mod(), where we have additional frequency input.

float repeat(
    float x,
    float freq
)
{
    return (mod((x) * (freq), 1.0));
}


The thing with having "no transition" using step() is that it tends to result in noise or jaggy or moire pattern when texture get complex. This was actually mentioned few times in many books. So later on, we learn how to code anti-aliasing.

But for our SIMPLE texture, we can simply use smoothstep() function instead of step()

SMOOTHSTEP() FUNCTION

This smoothstep() function allows us to have blending effect, similar to mix() function.

EXAMPLE CODE:
// Helper Function
// We will always need this blend() function
// to help to do the layering effect
color blend(
    color a,
    color b,
    color x
)

{
    return ((a) * (1-(x)) + (b) * (x));
}



float repeat(
    float x,
    float freq
)
{
    return (mod((x) * (freq), 1.0));
}


shader simpleStep(
    color ColA = color(1,0,0), // red
    color ColB = color(0,1,0), // green
    vector Pos = P,
    int freq = 5,
    output color Col_Out = color(0.2)
)
{
    // initialize color value into our LAYERING concept
    color surface_color = ColA; // assign ColA as base color
    color layer_color = ColB; // assign ColB as the layer on top of base
    color layer_opac = color(1);
    
    // s, t value from Pos
    float s = Pos[0];
    float t = Pos[1];
    
    // ss, tt, because of modulus inside repeat function
    float ss;
    float tt;
    
    ss = repeat(ss, freq);
    tt = repeat(tt, freq);
    
    // here we use the function
    layer_opac = smoothstep(-2, 2, s);
    
    // layering
    surface_color = blend(surface_color, layer_color, layer_opac);
    
    // output
    Col_Out = surface_color;
    
}

THE RESULT:

Blurred lines effect can be created by modifying the smoothstep function like below:
layer_opac = smoothstep(-2, 2, sin(s));



PULSE() FUNCTION

Now, we also have a modification of smoothstep() which is called pulse(). This pulse gives additional control over the fuzziness, the MIN and MAX of "the stripe".

float pulse (
    float a, 
    float b, 
    float fuzz, 
    float x
)
{
    return (smoothstep((a)-(fuzz), (a), (x)) - smoothstep((b)-(fuzz), (b), (x)));
}



EXAMPLE CODE:
// Helper Function
// We will always need this blend() function
// to help to do the layering effect
color blend(
    color a,
    color b,
    color x
)

{
    return ((a) * (1-(x)) + (b) * (x));
}



float repeat(
    float x,
    float freq
)
{
    return (mod((x) * (freq), 1.0));
}

float pulse (
    float a, 
    float b, 
    float fuzz, 
    float x
)
{
    return (smoothstep((a)-(fuzz), (a), (x)) - smoothstep((b)-(fuzz), (b), (x)));
}

shader simpleStep(
    color ColA = color(1,0,0), // red
    color ColB = color(0,1,0), // green
    vector Pos = P,
    int freq = 5,
    float fuzzy = 0.2,
    output color Col_Out = color(0.2)
)
{
    // initialize color value into our LAYERING concept
    color surface_color = ColA; // assign ColA as base color
    color layer_color = ColB; // assign ColB as the layer on top of base
    color layer_opac = color(1);
    
    // s, t value from Pos
    float s = Pos[0];
    float t = Pos[1];
    
    // ss, tt, because of modulus inside repeat function
    float ss;
    float tt;
    
    ss = repeat(ss, freq);
    tt = repeat(tt, freq);
    
    // here we use the function
    layer_opac = pulse(-4, 4, fuzzy, s);
    
    // layering
    surface_color = blend(surface_color, layer_color, layer_opac);
    
    // output
    Col_Out = surface_color;
    
}

THE RESULT:
MODIFICATION #001
layer_opac = pulse(-4, sin(t), fuzzy, s);


MODIFICATION #002
layer_opac = pulse(-cos(t*5)-3, sin(t), fuzzy, s);

MODIFICATION #003
layer_opac = pulse(sin(t)-2, sin(t), fuzzy, s);


ABS() / ABSOLUTE FUNCTION
Just to add one more useful function, the abs() function. It takes any positive or negative values and return positive values. This is often used to create a "bouncing ball" effect. The value never goes below the zero.

layer_opac = pulse(-2, abs(sin(t)), fuzzy, s);

SPLINE() / RAMP FUNCTION

I decided to add one more function to this post.

EXAMPLE CODE:
// Helper Function
// We will always need this blend() function
// to help to do the layering effect
color blend(
    color a,
    color b,
    color x
)

{
    return ((a) * (1-(x)) + (b) * (x));
}

shader simpleStep(
    color ColA = color(1,0,0), // red
    color ColB = color(0,1,0), // green
    vector Pos = P,
    output color Col_Out = color(0.2)
)
{
    // declare the SPLINE COLOR ARRAY 
    color MYSPLINE = color(1,0,0);
    
    
    color colorarray[17]= {color(0,0,0), 
    color(0,0,0),
    color(0.10588235294117647, 0.0, 0.0),
    color(0.21176470588235294, 0.0, 0.0),
    color(0.3176470588235294, 0.0, 0.0),
    color(0.42745098039215684, 0.0, 0.0),
    color(0.5333333333333333, 0.0, 0.0),
    color(0.6509803921568628, 0.0196078431372549, 0.0),
    color(0.6509803921568628, 0.0196078431372549, 0.0),
    color(0.8274509803921568, 0.23529411764705882, 0.0),
    color(0.9058823529411765, 0.3568627450980392, 0.0),
    color(0.9333333333333333, 0.5019607843137255, 0.0),
    color(0.9568627450980393, 0.6352941176470588, 0.047058823529411764),
    color(0.9725490196078431, 0.7333333333333333, 0.22745098039215686),
    color(0.984313725490196, 0.8196078431372549, 0.45098039215686275),
    color(0.996078431372549, 0.9254901960784314, 0.8235294117647058),
    color(1.0, 0.9450980392156862, 0.9019607843137255),
    color(1.0, 0.9450980392156862, 0.9019607843137255)
    };

    
    // initialize color value into our LAYERING concept
    color surface_color = ColA; // assign ColA as base color
    color layer_color = ColB; // assign ColB as the layer on top of base
    color layer_opac = color(1);
    
    // s, t value from Pos
    float s = Pos[0];
    float t = Pos[1];
    
    // here we use the function
    layer_opac = step(sin(s * 20), 0);
    
    // spline color, similar to ramp
    MYSPLINE = spline("constant",s,colorarray);
    
    // layering
    surface_color = blend(surface_color, layer_color, layer_opac);
    
    // output
    Col_Out = MYSPLINE;
    
}

THE RESULT:

That fire-ish Color Array was borrowed from:
http://blenderartists.org/forum/showthread.php?274730-OSL-Porting-from-RSL

But you could always make your own Color Array preset, simply by modifying and writing your own color "Ramp", for example below only creates 3 colors R, G, B:

    color colorarray[3]= {color(1,0,0), 
    color(0,1,0),
    color(0,0,1)
    };



You can plug ColorRamp node after the code like this to adjust and remap the Color gradient, even after the OSL code:



You may also notice the notation/syntax we use for spline() function:
spline("constant",s,colorarray);

From the OSL specification document, it mentions something like below:
spline(string basis, float x, type y[] array)

That just means for input of spline() function, we need to give it 3 inputs:
- string --> "constant", "linear", "bspline", "cardinal", "ease"
- float --> any float number or changing float numbers
- array --> the color array

That is pretty much it with basic functions.

I gotta mention Inigo Quilez again and his notes and videos below:
http://www.iquilezles.org/www/articles/functions/functions.htm
http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
http://www.youtube.com/user/mari1234mari
https://www.shadertoy.com/

With Shader Writing and Procedural Texture, again, I must say this is pretty abstract and not everyone's cup of tea. However, even by typing and attempting to understand the OSL syntax, we can started to see the capability of OSL in other areas, such as for utilities.

ADDITIONAL NOTE 2014.02.14:


CODE:
#include "/Users/jimmygunawan/Desktop/rmannotes.sl"
//#include "/Users/jimmygunawan/Desktop/patterns.h"

shader 
blah
(
    vector Pos = P,
    color ColA = color(1,0,0),
    color ColB = color(0,1,0),
    float Scale = 1.0,
    float Fuzz = 0.5,
    float Freq = 10,
    float Blah = 0.2,
    float Amp = 0.2,
    float Min = 0.5,
    float Max = 0.6,
    
    output color ColOut = 0
)
{
    float x,y,z;
    x = Pos[0] * 1/Scale;
    y = Pos[1] * 1/Scale;
    z = Pos[2] * 1/Scale;
    
    float f = sin(x) + atan(y);
    float sf = smoothstep(0.5, 0.6, abs(f));
    float pf = pulse(0.5, 0.8, Fuzz, abs(f));
    
    float steppy = step(x, sin(y));
    
    float xx = repeat(x, Freq);
    float yy = repeat(y, Freq);
    
    
    float sforce = pulse(Min * noise(0.02 * Pos) + Amp*sin(y*Blah), Max* noise(0.02 * Pos) + Amp*sin(y*Blah), Fuzz, xx);
    
    ColOut = mix(ColA, ColB, sforce );
}




MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget