Renderman Shaders

Non-Photorealistic Rendering

Independent Research by Mayilan Krishnamoorthy

(VSFX 785-02 Prof.Malcolm Kesson)


Texture mapping

This shader was written to experiment with texture mapping. I.e. to rotate scale and translate textures over a surface.

The part printed in white is the code that rotates the texture to the desired angle.

surface  npr01(varying float outline_thickness = 0.2;/*outline thickness*/
               varying float outline_offset = 0.1;/*outline offset*/
               )
               {
color	ambientcolor, diffusecolor, speccolor,
surfcolor = 1;
float brushspacing  = 0.2, q;
color white  = (1,1,1),outline;
color black = (0,0,0);
normal	n = normalize(N);
normal	nf = faceforward(n, I);
Oi = 1;
float ss = s/brushspacing;
float tt = t/brushspacing;
color paint = 0;
for(q=1; q<=2 ;q = q+1)
                 {
                 float ang = radians( 30 * q );
                 float costheta = cos(ang);
                 float sintheta = sin(ang);
                 float x = ss - 0.5;
                 float y = tt - 0.5;
                 float tss = x * costheta - y * sintheta + 0.5;
                 float ttt = x * sintheta + y * costheta + 0.5;
                 paint +=  color texture ( "M:/vsfx755/texture/brush4.tx", tss, ttt );
                 //Oi  +=  color texture ( "brush4.tx"[3], tss, ttt );
                 };
vector i = normalize(-I);
if (((i.nf)>outline_offset) && ((i.nf)<outline_offset+outline_thickness)){
    outline = white;
}else
{
    outline =black;
}

surfcolor  = paint*1.5 + outline;
Ci = Oi * Cs * surfcolor ;
                 }
             


Simple halftone shader

This is a simple halftone shader that can be applied in any space (world, object, shader, etc.)

 

           #include "M:/vsfx755/rsl_source/noises.h"
           surface npr_woodcut01(
               float lineWidth = 0.25;
               float lineOffset = 0.15;
               float lineBlend = 0.75;
               float border = 0.12;
               color outline = (0,0,0);
               float outlineWidth = 0.25;
               float outlineBlend = 0.25; 
               color black = (0,0,0);
               color white = (1,1,1);
               float	Kd = 1; 
               string PSpace = "shader"; 
               )
               {
               color	surfcolor = 1;
               /* STEP 1 - make a copy of the surface normal one unit in length */
               normal	n = normalize(N);
               normal	nf = faceforward(n, I);
               normal Nn = normalize (-N);
               float dot = Nn . normalize(I);
               point objP = transform (PSpace, P); 
               float screenx = ycomp(objP);
               float swidth = 0;
               swidth = lineWidth;
               float ss = screenx/swidth;
               float sss = ss - floor(ss);
               float do = smoothstep(0,lineOffset,abs((sss*2)-1));
               surfcolor = mix(white,black,do);
               color solidOutline = mix(outline,surfcolor,smoothstep(outlineWidth,1,dot));
               color blendOutline = mix(outline,surfcolor,smoothstep(outlineWidth,outlineBlend,dot));
               Oi = Os;
               Ci = Oi * Cs * (solidOutline+blendOutline) * Kd;
             }

 


 

 

mayilan krishnamoorthy mayilan@gmail.com