Shaders

READ

Bake out Texture – RSL NODE SHADER DOWNLOAD

rendermancode utility coding
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
shading parameters
string bake_file = “”
color i_color
output color o_color
shading code
extern point P;
extern normal N;
normal Nf = normalize(N);
bake ( bake_file, s, t, i_color);
o_color=i_color;

+++++++++++++++++++++++++++++++++++++++++++++++++++++++
put in “texturename.bake” in shader parameter
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
set up geometry –
1. set attribute on geometry in 3delight- cull hidden surfaces, cull backfacing surfaces, raster orientated dicing to off
2. set up camera view to encompass the geometry
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Bake out bake map on command line
tdlmake -bakeres 1200(or whatever texture size you want) C:\texture.bake C:\texture.tdl
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

////////////////////////////////////////////////////////////////////////////////////////////////////////////

Bake out AO TEXTURE – DOWNLOAD

////////////////////////////////////////////////////////////////////////////////////////////////////////////

constantTexture.sl – DOWNLOAD

////////////////////////////////////////////////////////////////////////////////////////////////////////////

AOVanisotropic.sl – DOWNLOAD

////////////////////////////////////////////////////////////////////////////////////////////////////////////

bake_occlusion_Pref.sl – DOWNLOAD

POINT CLOUD BAKING FOR GEOMETRY THAT IS GOING TO DEFORM
1) Select Geometry – Maya Menu – Rendering – Texturing – Create Texture ref object.
2) Add attribute Reference Geometry in 3delight, output Pref, output Nref

//////////////////////////////////////////////////////////////////////////////////////////////////////////

ONE LINE CODE
Ci is a global variable in surface shaders and is the output color. The parameters are hard-coded into the shader, because there are no parameter variables set up in between the ().

surface whateverthenameis()
{
// put one line code in here
}

COLOR
Ci = color “hsv” (0.2, 0.6, 0.9);
Ci = color (1,0,0);
Ci = color (0, t, 0);
Ci = color (s, 0, 0);
Ci = color “hsv” (s, 1, 1);
Ci = color (s, t, 0);
S & T
Ci = s;
Ci = t;
MOD FUNCTION
Ci = mod(s * 5, 1.0);
Ci = mod(s, 1.0);
STEP WITH MOD FUNCTION
Ci = step(0.25, mod(s * 5, 1.0));
Ci = step(0.5, mod(s * 5, 1.0));
NOISE FUNCTION
Ci = noise(s, t);
Ci = noise(s*10,t*10);
Ci = noise(s * 50, t * 50);
SMOOTHSTEP FUNCTION
Ci = smoothstep(0.4, 0.6, s);
Ci = smoothstep(0.4, 0.6, mod(s * 5, 1.0));
SPLINE FUNCTION
Ci = spline(t, color (1,1,0), color (1,1,0), color (0,1,0), color (0,0,1), color (0,0,1));
STEP FUNCTION
Ci = step(t, s);
Ci = step(0.2, s);
Ci = step(0.5, s);
SIN FUNCTION

Ci = 0.5+0.5*sin(s*2*PI*4);

CELL NOISE
Ci=color cellnoise(s*5);
Ci=color cellnoise(t*10);
Ci=color cellnoise(s*10,t*10);
COS FUNCTION
Ci = cos(10*s*10*t);
ATAN FUNCTION
Ci = atan(1*s*1*t);
ASIN FUNCTION

Ci = asin(-1*s*2*t);

SHADERS 101

Shader Structure

ShaderType ShaderName (ShaderParameters)
{RSL code that gets executed………..
}

Global Variables of Surface Shaders

NameTypeStorage ClassDescription
Oi



color
varyingOpacity output
Oscolorvarying/uniformOpacity input from RIB stream
CicolorvaryingColor Output
Cscolorvarying/uniformcolor input from RIB stream
Nnormalvaryingsurface shading normal
u,vfloatvaryingSurface parameters
NgnormalvaryingSurface geometric normal
Ppointvaryingsurface Position
s,tfloatvaryingsurface texture coordinates
du,dvfloatvarying/uniformchange in surface parameters
dPduvectorvaryingDerivative of P along u
dPdvvectorvaryingDerivative of P along v
Lvectorvarying/uniformdirection from surface to light source
Clcolorvarying/uniformincoming light color (use inside illuminance statements)
Ivectorvaryingdirection of the light ray hitting the surface
Epointuniformposition of the eye
Olcolorvarying/uniformincoming light color (use inside illuminance statements)
ncompsfloatuniformnumber of color components
timefloat uniformcurrent shutter time
dtimefloatuniformamount of time covered by this shading sample
dPdtimevectorvaryingsurface position P changing per unit of time, as described by motion blur on the scene




CONSTANT SHADER
surface constant()
{Oi = Os;
Ci = Oi * Cs;
}


CONSTANT COLOR SHADER
surface constant_surfaceColor(
color surfaceColor = (1,0,0);
color surfaceOpac = (1,1,1);
)
{Oi = surfaceOpac;
Ci = Oi * surfaceColor;
}


DIFFUSE SHADER
surface lambert(
uniform float Ka = 0.5;
uniform float Kd = 0.85;
color surfaceColor = color (1,1,1);
color surfaceOpac = color (1,1,1);
)
{
/* Variables */
normal Nf = faceforward( normalize(N), I );
Oi = surfaceOpac;
Ci = Oi * surfaceColor * (Ka * ambient() + Kd * diffuse(Nf));
}


PLASTIC SHADER
surface plastic( float Ka = 1.0,
Kd = 1.0,
Ks = 0.5,
roughness = 0.1;
color specularColor = 1,
surfaceColor = color (1, 0, 0);)
{
normal Nf = faceforward(normalize(N), I);
vector V = -normalize(I);

Ci = surfaceColor * (Ka*ambient() + Kd*diffuse(Nf)) + Ks*specularColor*specular(Nf, V, roughness);
Oi = Os; Ci *= Oi;
}

Operators in Shading Language

SymbolNameReturns 1 (True) if
==equalleft is equal to right
!=not equalleft is not equal to right
<less thanleft is less than right
<=less or equal toleft is less than or equal to right
>greater thanleft is greater than right
>=greater or equal toleft is greater than or equal to right

3 comments for “Shaders

  1. December 29, 2011 at 3:38 pm

    wow!
    I love your blog and this introduction to RSL.
    I would love if you can extend this section by more math and more advanced math functions!!

    thank you so much for the effort you put into this.

    • Admin
      January 23, 2012 at 1:25 pm

      Thanks for the kind words bastiant. I’m not a natural with Maths so I don’t know how advanced I can get 🙂
      As always if anybody out there would like to submit some useful notes / tutorials – that would indeed be a beautiful thing.

  2. November 21, 2012 at 3:51 pm

    Thank you so much for this!
    very helpful.

Leave a Reply

Your email address will not be published. Required fields are marked *