/* Attempt at using polar coordinate system to define the swirling motion */ /* of a surface texture. */ surface swirl(float Ka = 1, /* ambient brightness */ Kd = 0.5, /* basic brightness */ Ks = 0.7, /* hilite brightness */ s_cen = 0.5, /* s value offset */ t_cen = 0.5, /* t value offset */ s_theta = 0.5, /* increase or decrease theta for s */ t_theta = 0.5, /* increase or decrease theta for t */ roughness = 0.1;/* hilite spread */ color hilitecolor = 1;/* hilite color */ string texname = "") { color ambientcolor, diffusecolor, speccolor, surfcolor = 1; normal n = normalize(N); normal nf = faceforward(n, I); Oi = Os; ambientcolor = Ka * ambient(); diffusecolor = Kd * diffuse(nf); vector i = normalize(-I); speccolor = Ks * specular(nf, i, roughness) * hilitecolor; /* this calculates the r (radius) of the point from the origin and theta */ /* angle from the arc tangent of t/s */ float r = sqrt((s-s_cen)*(s-s_cen)+(t-t_cen)*(t-t_cen)), theta = atan(t/s); /* this calculates the new s and t values based off of the above calculations */ float ss = (r * cos(theta * s_theta)), tt = (r * sin(theta * t_theta)); /* "stretches" the texture to the new coordinates */ surfcolor = texture(texname,ss,tt); Ci = Oi * Cs * surfcolor * (ambientcolor + diffusecolor + speccolor); }