appendixA.html, appendixF.html, index.html, section01.html, section02.html, section03.html, section04.html, section05.html, section06.html, section07.html, section08.html, section09.html, section10.html, section11.html, section12.html, section13.html, section14.html, section15.html, section16.html


A - Standard Shaders


Surface Shaders


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

surface
matte(
    float Ka = 1;
    float Kd = 1;)
{
  point Nf;

  Nf = faceforward(normalize(N), I);

  Oi = Os;
  Ci += Os * Cs * Ka * ambient();
  Ci += Os * Cs * Kd * diffuse(Nf);
}
    

surface
metal(
    float Ka = 1;
    float Ks = 1;
    float roughness = 0.1; )
{
  point Nf, V;

  Nf = faceforward(normalize(N), I);
  V = -normalize(I);

  Oi = Os;
  Ci += Os * Cs * Ka * ambient();
  Ci += Os * Cs * Ks * specular(Nf, V, roughness);
}
    

surface
shinymetal(
    float Ka = 1;
    float Ks = 1;
    float Kr = 1;
    float roughness = 0.1;
    string texturename = "";)
{
  normal Nf, V;
  point D;

  Nf = faceforward(N, I);
  V = -normalize(I);

  D = reflect(I, normalize(Nf));
  D = transform("world", point "world" (0,0,0) + D);
  if(texturename != "") {
    Ci += Os * Cs * Kr * color environment(texturename, D);
  }

  Oi = Os;
  Ci += Os * Cs * Ka * ambient();
  Ci += Os * Cs * Ks * specular(Nf, V, roughness);
}
    

surface
tracedmetal(
    float Ka = 1;
    float Ks = 1;
    float Kr = 1;
    float roughness = 0.1;)
{
  point Nf, V, D;

  Nf = faceforward(normalize(N), I);
  V = -normalize(I);
  D = reflect(I, Nf);

  Oi = Os;
  Ci += Os * Cs * Ka * ambient();
  Ci += Os * Cs * Ks * specular(Nf, V, roughness);
  Ci += Os * Cs * Kr * trace(P, D);
}
    

This is a version of the shinymetal shader which uses ray-traced reflections instead of an environment map. Use in preference to shinymetal.


surface
plastic( 
    float Ka = 1;
    float Kd = 0.5;
    float Ks = 0.5;
    float roughness = 0.1;
    color specularcolor = 1; )
{
  point Nf, V;

  Nf = faceforward(normalize(N), I);
  V = -normalize(I);

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

    

surface
paintedplastic( 
    float Ka = 1;
    float Kd = 0.5;
    float Ks = 0.5;
    float roughness = 0.1;
    color specularcolor = 1;
    string texturename = "";)
{
  point Nf, V;
  color Ct;

  Nf = faceforward(normalize(N), I);
  V = -normalize(I);

  if(texturename != "") {
    Ct = color texture(texturename);
  } else {
    Ct = 0;
  }

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

Light Source Shaders


light
ambientlight(
    float intensity = 1;
    color lightcolor = 1; )
{
  Cl = intensity * lightcolor;
}
    

light
distantlight( 
    float intensity = 1;
    color lightcolor = 1;
    point from = point "shader" (0,0,0);
    point to = point "shader" (0,0,1); )
{
  solar(to - from, 0) {
    Cl = intensity * lightcolor;
  }
}

    

light
pointlight(
    float intensity = 1;
    color lightcolor = 1;
    point from = point "shader" (0,0,0); )
{
  illuminate(from) {
    Cl = intensity * lightcolor / (L . L);
  }
}
    

light
spotlight(
    float intensity = 1;
    color lightcolor = 1;
    point from = point "shader" (0,0,0);
    point to = point "shader" (0,0,1);
    float coneangle = radians(30);
    float conedeltaangle = radians(5);
    float beamdistribution = 2; )
{
  float atten, cosangle;
  point A;

  A = normalize(to - from);
  illuminate(from, A, coneangle) {
    cosangle = (L . A) / length(L);
    atten = pow(cosangle, beamdistribution) / (L . L);
    atten *= smoothstep(cos(coneangle), cos(coneangle - conedeltaangle),
	cosangle);
    Cl = atten * intensity * lightcolor ;
  }
}
    

Volume Shaders


volume
depthcue(
    float mindistance = 0;
    float maxdistance = 1;
    color background = 0;)
{
  float d;

  d = clamp((depth(P) - mindistance) / (maxdistance - mindistance), 0, 1);
  Ci = mix(Ci, background, d);
  Oi = mix(Oi, color (1,1,1), d);
}
    

volume
fog(
    float distance = 1; 
    color background = 0;)
{
  float d;

  d = 1 - exp (-length(I) / distance);
  Ci = mix(Ci, background, d);
  Oi = mix(Oi, color (1,1,1), d);
}

Displacement Shaders

No standard displacement shaders are provided.