Skip to main content

Posts

Showing posts from May, 2012

Simplest shader tutorial for renderman

Hi, here a simple shader example tutorial. With this code we'll realize a lambert shader with 3 custom parameter: diffuse color, texture color, opacity. Here the code with some comment due to explain all the lines. \\definition of the shader tipe "surface" and the name. Between the brackets there's the parameter, one of color type, one of string type and one of float type. surface Lambert(color diffuseColor=color(1,0,0); string colorTexture=""; float opacity=1) {          \\definition of the texture projection coordinates in world space     point worldP = transform("world",P);         \\function to normalize vector normal     normal Nn = normalize(N);     \\with this function we normalize the vector for pointing to the camera eye ("I")     vector Nf = faceforward(Nn,I);     \\definition of a texture file with path passed by the parameter with the coordinates u and v (s,t)     color textureFile = texture(colorTextu

mandlebrot fractal shader

Here an example of the code for a mandlebrot fractal noise written for renderman. In this particular simple shader, you can change the color of the fractal using a spline color. I use 3delight to test the shader inside maya. surface Mandelbrot(color c1=(1,0,0);color c2=(0,0,1);color c3=(0,0,0)) {     float u = s;     float v = t;          //Z^2 + C     float Zx = 0;     float Zy = 0;     float Cx = u;     float Cy = v;          float i;     for(i=0;i<100;i=i+1)     {         float a = Zx*Zx-Zy*Zy;         float b = 2*Zx*Zy;         Zx = a;         Zy = b;         Zx = Zx+Cx;         Zy = Zy+Cy;         if (Zx*Zx+Zy*Zy>4)             break;                   }     float value = i/100;     Ci = spline(value,c1,c1,c2,c3,c3)*diffuse(normalize(N));     Oi = Os; }