MONAN BIAN VSFX 755 PROCEDURAL 3D & SHADER PROGRAMMING PORTFOLIO
CONTANT bianmonan@gmail.com

This page demonstrates the use of OSL (Open Shading Language) in RenderMan.

 

 

Color By Distance

SHADER EXAMPLE:

Color By ID

OSL SHADER WORK FLOW

osl

rib

oso

Maya project folder

rib-box

TCL UI WORK FLOW

osl

tcl

mel

rib-box

Maya project folder

Maya script editor

TIPS: hold shift key when you export TCL files will export all the control parameter otherwise only export the parameter exist in the OSL shader

shader

noiseColorByID(color A = color (1,1,1),

               color B = color (0.2,0.4,0.7),

               int randomize = 1,

               float cycles = 10,

            output color resultRGB = 0)

{

float id = 1;

getattribute ("identifier:id", id);

float ratio;

if (randomize)

    ratio = noise ("cell", cycles, id);

else

    ratio = fmod (id/cycles, 1.0);

resultRGB = mix (A,B,ratio);

}

 

Color By Distance

shader

colorByDist(float cycle = 1,

            float satuation = 1,

            float value = 1,

            float cutoff = 0.5,

            output color resultRGB = 0,

            output float resultF = 0)

{

point p = transform("world", P);

point origin = point(0, 0, 0);

float dist = distance (p, origin);

float grayscale = luminance(resultRGB);

 

resultRGB = color ("hsv", dist/cycle, satuation, value);

resultF = (grayscale < cutoff) ? 1:0;

}

MODEL:

The model I used in many scenes are called Menger Sponge. The python code and mel function shows below

:Click Here

It will generate several parameter that base on default cube.

It will compute the cube and divide into cubes matrix. Each cube

have different attributes can be used drive the color.

Conclusion:

OSL as a new shading language can be using widely in many 3D software package. But the most fit one should be Houdini. From my previous study I learned how to use attribute drive color in the OSL shader. However, there is a very not convent is we need use mel command create attribute before we use it. In Houdini all the attributes already exist when you create a scene. It means we can grab the attribute and use it directly. Moreover, we also can create our own attribute.

 

RenderMan has been built into Houdini for several years. But only few people use it inside Houdini because the pipeline is too long that make the render process too complex. That's why FX artist more prefer use Houdini default render package Mantra. We always call it little RenderMan. But Mantra only can be used inside Houdini and It's compatibility is not as good as RenderMan. Because this I believe the new OSL language will make the RenderMan step forward a long distance.