surface beachball( uniform float Ka = 1, Kd = 1; uniform float Ks = .5, roughness = .1; uniform color starcolor = color (1,.5,0); uniform color bandcolor = color (1,.2,.2); uniform float rmin = .15, rmax = .4; uniform float npoints = 5; ) { color Ct; float angle, r, a, in_out; uniform float starangle = 2*PI/npoints; uniform point p0 = rmax*point(cos(0),sin(0),0); uniform point p1 = rmin* point(cos(starangle/2),sin(starangle/2),0); uniform vector d0 = p1 - p0; vector d1; angle = 2*PI * s; r = .5-abs(t-.5); a = mod(angle, starangle)/starangle; if (a >= 0.5) a = 1 - a; d1 = r*(cos(a), sin(a),0) - p0; in_out = step(0, zcomp(d0^d1)); Ct = mix(mix(Cs, starcolor, in_out), bandcolor, step(rmax,r)); normal Nf = normalize(faceforward(N,I)); Oi = Os; Ci = Os * (Ct * (Ka * ambient() + Kd * diffuse(Nf)) + Ks * specular(Nf,-normalize(I),roughness)); }