Halloween Costume ideas 2015

OSL / Disk Grid

Decided to have a look at another RSL code and convert it to OSL. This time, it is the infamous POLKA DOTS style!

Shall we dance, Renderman Teapot?

Porting RSL Disk to OSL Disk

Yayoi Kusama's style of dots...

/*
SOURCE:
http://nccastaff.bournemouth.ac.uk/jmacey/Renderman/slides/RendermanShaders1.pdf

Ported by Jimmy Gunawan @ Blender Sushi 2013

*/

shader Disk(
    point center = point (0.5, 0.5, 0.0),
    float fuzz = 0.025,
    float Radius = 0.5,
    float RepeatS = 5,
    float RepeatT = 5,
    color ColorA = color(1,0,0),
    color ColorB = color(0,1,0),
    point Vector = P,
    output color Col_Out = color(0.2)
)

{
    float x = Vector[0];
    float y = Vector[1];
    
    float s = x;
    float t = y;

    float ss = mod(s*RepeatS, 1);
    float tt = mod(t*RepeatT, 1);
    
    point here = point (ss, tt, 0);
    float dist = distance(center, here);
    float inDisk = 1 - smoothstep(Radius/2.0 - fuzz, Radius/2.0+fuzz, dist);
    
    Col_Out = mix(ColorA, ColorB, inDisk);

}

This simple Texture has some neat adjustable attributes such as "fuzz" aka "Blurriness":

Blurriness seems to be the effect of function smoothstep().

This disk shader also repeats in grid fashion and stretch the Disks based on the Surface span:


This procedural 2D texture is applicable to 3D objects, but it stretches as expected:

SNIPPET: Sharp Banding vs Fuzzy Blurry Smooth Blend

I studied the PDF documentation from Jon Macey on RSL and found useful information regarding smoothstep() that I think needed to be translated to OSL. I believe this is covered in previous posts, but not as straightforward. We can basically create blending that is either SHARP or SMOOTH.

SHARP BLEND

shader bands(
    color C1 = color(1,0,0),
    color C2 = color(0,1,0),
    float begin = 0.3,
    float end = 0.6,
    float Orient = 0,
    output color Col_Out = color(0.2)

)

{
    float s = P[0];
    float t = P[1];
    color Ct;
    float inTop;
    if(Orient==0)
        inTop = smoothstep(begin, end, s);
    else
        inTop = smoothstep(begin, end, t);
        
    Ct = mix(C1, C2, inTop);    
    
    Col_Out = Ct;
}


That is a FLIP-FLOP effect, basically. If TRUE, color the pixel with Color A, if FALSE, color the pixel with Color B. Hence the SHARP EDGE with no blending.

SMOOTH BLEND
shader bands(
    color C1 = color(1,0,0),
    color C2 = color(0,1,0),
    float begin = 0.3,
    float end = 0.6,
    float Orient = 0,
    output color Col_Out = color(0.2)

)

{
    float s = P[0];
    float t = P[1];
    color Ct;
    float inTop;
    if(Orient==0)
        inTop = smoothstep(begin, end, s);
    else
        inTop = smoothstep(begin, end, t);
        
    Ct = mix(C1, C2, inTop);    
    
    Col_Out = Ct;
}


In many of the OSL codes previously written, you may noticed that SMOOTH BLEND is also given for free by using sin()or cos() wave functions. And to make it sharp blend, we use step(), floor(), ceil(), round() functions. So in sine or cosine style, we go from smooth to sharp, which is the opposite of above.

Apart from giving SMOOTH BLEND for free, sin()or cos()are also introducing REPETITION. REPETITION itself is more closely related to mod()function.

Two colors that are placed really close (blend "begin" and "end" values) will introduce SHARP BLEND also.

Don't you think the usage of Math Functions in low level Computer Graphic (in context of OSL Shader Writing) are both weird and fun? And that is just the basic.

LAYERING TEXTURES USING NODES

We can piggy back this OSL texture using Cycles nodes, non procedural way of layering.

This resembles pattern of certain brand of EXPENSIVE LUXURY bags.



Would be nice to be able to Offset the texture like this in X and Y, so I decided to play around with the code a bit. This is the fun part.

OFFSET TEST 1

shader Disk(
    point center = point (0.5, 0.5, 0.0),
    float fuzz = 0.025,
    float Radius = 0.5,
    float RepeatS = 5,
    float RepeatT = 5,
    color ColorA = color(1,0,0),
    color ColorB = color(0,1,0),
    point Vector = P,
    output color Col_Out = color(0.2)
)

{
    float x = Vector[0];
    float y = Vector[1];
    
    float s = x;
    float t = y;

    float ss = mod(s*RepeatS, 1);
    float tt = mod(t*RepeatT, 1);
    
    point here = point (ss+0.5, tt, 0);
    float dist = distance(center, here);
    float inDisk = 1 - smoothstep(Radius/2.0 - fuzz, Radius/2.0+fuzz, dist);
    
    Col_Out = mix(ColorA, ColorB, inDisk);

}

Wrong adjustment, but interesting. Almost fish/snake like but no stagger or overlap.

OFFSET TEST 2

This is more correct in term of Offsetting the texture in X or/and Y.

shader Disk(
    point center = point (0.5, 0.5, 0.0),
    float fuzz = 0.025,
    float Radius = 0.5,
    float RepeatS = 5,
    float RepeatT = 5,
    color ColorA = color(1,0,0),
    color ColorB = color(0,1,0),
    float OffsetX = 0.0,
    float OffsetY = 0.0,
    point Vector = P,
    output color Col_Out = color(0.2)
)

{
    float x = Vector[0];
    float y = Vector[1];
    
    float s = x;
    float t = y;

    float ss = mod(s*RepeatS + OffsetX, 1);
    float tt = mod(t*RepeatT + OffsetY, 1);
    
    point here = point (ss, tt, 0);
    float dist = distance(center, here);
    float inDisk = 1 - smoothstep(Radius/2.0 - fuzz, Radius/2.0+fuzz, dist);
    
    Col_Out = mix(ColorA, ColorB, inDisk);

}
Fake 3D-ish effect, only look right from this angle.
If we keep layering the dots, we can get some interesting effects, feel free to do that yourself.


Remember we can always do something simple like overlaying this OSL Disk Grid on top of an image. I always name the variables Color A and Color B, but Color A can simple be the Base Color.


If we use OSL Disk as Factor for Mix Shader Transparency...





ADD NOISE NODE

Sometimes out of curiosity, I plug the Noise Cycle node or other noise to the OSL node. We can easily get weird alien texture like below:



Or maybe plug it like this?



Do you see the purple rabbit?
The interesting thing here is that by mixing Noise into Vector, we get 3D vector wrapping for free... I think.


MORE MAGICS OF DISKS


I am quite surprised that Grid of Circles are apparently quite magical....




Probably we can push Circles a bit so that it creates some kind of basic Islamic Geometry Patterns.



Not sure when texture become a bit too much, this is Magical + Voronoi + OSL Disk:




ANY QUESTIONS?

Moreover, some questions already appear:

Picture property of PMOXY, one of screen app for iPad.
  • Can we actually use some functions here to create simple GRID TILE function that we can use to repeats some of the Texture Pattern we made?
  • How do we translate 2D Texture like DISK/POLKA DOTS above into 3D Textures?
  • Can we make textures that is more psychedelic? Like above.
  • I want OUTLINE on the Disks, how?
  • Instead of GRID, can we STAGGER the pattern?

SPIRAL... how to create SPIRAL?

I asked my old friend, Nitz Saputra, he said:

"I tried using MATLAB to plot something."

For 2D spiral:
a = 0: 3*pi/100 : 6*pi;  %Vector
x = a.*cos(a);
y = a.*sin(a);
plot(x,y)
 
For 3D spiral:
a = 0: 3*pi/100 : 6*pi; %vector
x = cos(a);
y = sin(a);
z = a;
plot3(x,y,z)

Maybe it is possible to have function like that in OSL... I am not 100% sure the different. There are many kind of SPIRAL as well.

OSL: Better Line

Still from Jon Macey's codes, I ported some of the RSL into OSL.

I need to add this here, this is probably a better function for LINE.

/*
    SOURCE: http://nccastaff.bournemouth.ac.uk/jmacey/Renderman/ 
*/

shader Lines (
    color LineColor = color(1,0,0),
    color MixColor = color(1,1,1),
    float fuzz = 0.025,
    float LineSize = 0.1,
    float Orient = 0,
    float offset = 0.5,
    output color Col_Out = color(0.2)
)

{
    color Ct;
    float s = P[0];
    float t = P[1];
    
    // we care about texturing only
    float inTop;
    float dist;
    
    if(Orient==0)
        dist = abs(t-offset);
    else
        dist = abs(s-offset);
    
    float inLine;
    
    inTop = 1 - smoothstep(LineSize/2.0 - fuzz, LineSize/2.0+fuzz, dist);
    
    Ct = mix(MixColor, LineColor, inTop);
    Col_Out = Ct;
    
}

OSL: User Custom Lines

Line between 2 Points. Interesting, but I do not quite got this one. I changed ptlined() function from RSL to distance(pointA, pointB, pointC) of OSL. Not sure if this is right.

shader UserLines(
    color LineColor = color(1,0,0),
    float LineSize = 0.01,
    point P1 = point (0.1,0.7,0),
    point P2 = point (0.7,0.7,0),
    float fuzz = 0.025,
    output color Col_Out = color(0.2)
)


{
    color Ct;
    float s = P[0];
    float t = P[1];
    point Here = point(s,t,0);
    float dist = distance(P1, P2, Here);
    float inLine = 1-smoothstep(LineSize/2.0 - fuzz, LineSize/2.0 +fuzz, dist);
    Ct = mix(Ct, LineColor, inLine);
    
    Col_Out = Ct;

}



REFERENCES


http://accad.osu.edu/~smay/RManNotes/RegularPatterns/txtr_coords.html
http://renderman.pixar.com/resources/current/rps/rslFunctions.html
http://openshadinglanguage.googlecode.com/svn-history/r901/trunk/src/doc/languagespec.tex

Post a Comment

MKRdezign

Contact Form

Name

Email *

Message *

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