/* wire_occlusion * * by Andrew Osiow * based on the wire.sl that ships with Renderman and simple occlusion code * from the RenderMan App. Notes #35 * for poly meshes that had all faces unitized */ normal shadingnormal(normal N) { normal Ns = normalize(N); uniform float sides = 2; uniform float raydepth; attribute("Sides", sides); rayinfo("depth", raydepth); if (sides == 2 || raydepth > 0) Ns = faceforward(Ns, I, Ns); return Ns; } surface wire_occlusion( float hwidth=0.0075; color line_color = 0.0; float samples = 64, maxvariation = 0.02) { color C = Cs; normal Ns = shadingnormal(N); // normalize N and flip it if backfacing // Compute occlusion float occ = occlusion(P, Ns, samples, "maxvariation", maxvariation); // Compute line width based on UV space float rim = 2*hwidth; float s_mid = length(dPdu)*(0.5 - abs(mod(s,1.0) - 0.5)); float t_mid = length(dPdv)*(0.5 - abs(mod(t,1.0) - 0.5)); float mid = (s_mid > t_mid) ? t_mid : s_mid; // assigns mid to lowest // Compute color if (mid < hwidth) C = line_color; else if ( mid < (hwidth+rim)) C = mix (line_color,Cs,(mid-hwidth)/rim); Ci = Oi * C; // Set Ci and Oi Ci = (1 - occ) * C * Os; Oi = Os; }