/* Shader description goes here */ surface blobby3(float Kd = 1, iso = 0.5; float rad[3] = { 1, 1, 1 }; point pnt[3] = { 0, 0, 0 }; color col[3] = { 1, 1, 1 }; ) { 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, field, dist; color totalcolor = 0; uniform float j; for(j = 0; j < 3; j = j + 1) { dist = distance(pnt[j], p); field = 1 - smoothstep(0, rad[j], dist); totalcolor += col[j] * field; totalfield += field; } float r = comp(totalcolor, 0); float g = comp(totalcolor, 1); float b = comp(totalcolor, 2); r /= 3; g /= 3; b /= 3; setcomp(totalcolor, 0, (r > 1) ? 1 : r); setcomp(totalcolor, 1, (g > 1) ? 1 : g); setcomp(totalcolor, 2, (b > 1) ? 1 : b); float blend = smoothstep(iso - 0.05, iso + 0.05, totalfield); surfcolor = mix(Cs, totalcolor, blend); /* STEP 3 - calculate the diffuse lighting component */ diffusecolor = Kd * diffuse(nf); /* STEP 4 - calculate the apparent surface color */ Ci = Oi * Cs * surfcolor * diffusecolor; }