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;
}
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;
}
Comments
Post a Comment