surface blobby7(float Kd = 1, iso = 0.5; float rad[3] = { 1, 1, 1 }; float polarity[3] = { 1, 1, 1 }; point pnt[3] = { 0, 0, 0 }) { normal nf, n; color diffusecolor, surfcolor = 1, surfopac = Os; point p; /* STEP 1 - make a copy of the surface normal one unit in length */ n = normalize(N); nf = faceforward(n, I); /* STEP 2 - set the apparent surface opacity */ Oi = surfopac; float totalfield = 0, dist; uniform float j; for(j = 0; j < 3; j = j + 1) { p = transform("current", pnt[j]); dist = distance(P, p); if(polarity[j] == 1) totalfield += 1 - smoothstep(0, rad[j], dist); else totalfield -= 1 - smoothstep(0, rad[j], dist); } float blend = smoothstep(iso-0.07,iso,totalfield) * (1 - smoothstep(iso,iso+0.07,totalfield)); surfcolor = mix(Cs, color(1,0,0), blend); /* STEP 3 - calculate the diffuse lighting component */ diffusecolor = Kd * diffuse(nf); /* STEP 4 - calculate the apparent surface color */ Ci = Oi * Cs * surfcolor * diffusecolor; }