surface
spd (float Ka = 1,
     float Kd = .5,
     float Ks = .5,
     float roughness = .1,
     color specularcolor = 1,
     float reflected = 0.,
     float transmitted = 0.,
     float index = 1.0)
{
  normal Nn = faceforward (normalize(N),I);
  normal In = normalize( I );
  color r = 0, tr = 0;
     
  if (reflected > .001) {
   r = reflected * trace (P, reflect(I, Nn));
  }
  if (transmitted > .001) {
   vector T = refract(In, Nn, dot(N,I)>0 ? index : 1/index ); 
   if ( length( T ) != 0.0 )
   tr = transmitted * trace (P, T);
  }
     
  C = opacity * ( C * ( Kd*diffuse(Nn) + r + tr) +
       specularcolor * Ks*specular(Nn,-In,roughness));
}