Will Cavanagh
TECH319
TECH319
SolidBegin "difference" SolidBegin "primitive" ### CODE FOR GENERATING SPOUT GOES HERE ### SolidEnd SolidBegin "primitive" ### THIS IS THE GEOMETRY TO SUBTRACT FROM THE SPOUT: TransformBegin Translate 0 -0.1 1.25 Rotate -35 1 0 0 Disk 2 1 360 Cylinder 1 0 2 360 Disk 0 1 360 TransformEnd SolidEnd SolidEnd
AttributeBegin Translate 0 .8 .3 ShadingInterpolation "smooth" Attribute "dice" "int roundcurve" [1] ReadArchive "metal_material.rib" Basis "b-spline" 1 "b-spline" 1 Curves "cubic" [10] "nonperiodic" "P" [-9 -.8 0 -7 -1.1 0 -5 -.8 0 -4.8 -.75 0 -4 -.85 0 -3.5 -1 0 -2.2 -1.5 0 -1 -1.5 0 0 -1 0 1 1 0] "width" [1.9 1.7 1.75 2.0 2.3 2.7 3 3.5] AttributeEnd
SolidBegin "difference" # Spout Primitive SolidBegin "primitive" #Interior ReadArchive "spout_curves_small.rib" ReverseOrientation ReadArchive "spout_curves_small.rib" #Exterior ReadArchive "spout_curves.rib" ReverseOrientation ReadArchive "spout_curves.rib" #End Cap TransformBegin Translate -7 -.35 .2 Rotate -90 0 1 0 Disk 0 .95 360 TransformEnd SolidEnd # Subtraction Primitive SolidBegin "primitive" TransformBegin Rotate -90 0 1 0 Translate 0 -0.1 6.5 Rotate -15 1 0 0 Scale 2 2 2 Surface "" Opacity 0 0 0 Disk 2 1 360 Cylinder 1 0 2 360 Disk 0 1 360 TransformEnd SolidEnd SolidEnd
if(sin(sFreq*s) <= t) surfcolor = patcolor;
if((1-t) >= s*s) surfcolor *= patcolor;
float newS = (s - 0.5); float newT = (t - 0.5); if((pow(newS, 2) + pow(newT, 2)) < pow(rad, 2)) surfcolor = patcolor;
float si = sin(rotation); float co = cos(rotation); float sFixed = (s - 0.5); float tFixed = (t - 0.5); float snew = sFixed * co - tFixed * si; float tnew = sFixed * si + tFixed * co;
if((pow(abs(snew), power) + pow(abs(tnew), power)) < pow(rad, power)) surfcolor = patcolor;
surface diagonal( float Kfb = 1 /* [group diagonal 0 1 Label "Intensity"] */; float shift = 1.0 /* [group diagonal 0 2 Label "Shift Edge"] */; float blur = 0.02 /* [group diagonal 0 .1 Label "Antialias Edge"] */; float sflip = 0; /* [group diagonal 0 or 1 Label "Flip S Coordinate"] */ float tflip = 0; /* [group diagonal 0 or 1 Label "Flip T Coordinate"] */ color patcolor = color (1,1,0); /* [group foreground Label "Color"] */ string pat_texname = ""; /* [group foreground Label "Texture"] */ float patTransS = 0.0; /* [group foreground -1 1 Label "Translate S"] */ float patTransT = 0.0; /* [group foreground -1 1 Label "Translate T"] */ float patScale = 1.0; /* [group foreground 0 2 Label "Scale"] */ color bakcolor = color (.6,.3,1); /* [group background Label "Color"] */ string bak_texname = ""; /* [group background Label "Texture"] */ float bakTransS = 0.0; /* [group background -1 1 Label "Translate S"] */ float bakTransT = 0.0; /* [group background -1 1 Label "Translate T"] */ float bakScale = 1.0; /* [group background 0 2 Label "Scale"] */ ) { color surfcolor; float tt = (sflip == 1) ? (1-s) : s; float ss = (tflip == 1) ? (1-t) : t; color patcolor_copy = patcolor; color bakcolor_copy = bakcolor; float sTex1 = (ss + patTransS) * (1 / patScale); float tTex1 = (tt + patTransT) * (1 / patScale); float sTex2 = (ss + bakTransS) * (1 / bakScale); float tTex2 = (tt + bakTransT) * (1 / bakScale); if(pat_texname != "") patcolor_copy = texture(pat_texname, sTex1, tTex1); if(bak_texname != "") bakcolor_copy = texture(bak_texname, sTex2, tTex2); float blend = smoothstep(shift - blur, shift + blur, ss+tt); surfcolor = mix(patcolor_copy, bakcolor_copy, blend); Oi = Os; Ci = Oi * Cs * surfcolor * Kfb; }
float rotateS(float rad;) { float si = sin(rad); float co = cos(rad); float sFixed = (s - 0.5); float tFixed = (t - 0.5); return (sFixed * co - tFixed * si); } float rotateT(float rad;) { float si = sin(rad); float co = cos(rad); float sFixed = (s - 0.5); float tFixed = (t - 0.5); return (sFixed * si + tFixed * co); } /* Shader description goes here */ surface squirgle( float Kfb = 1; /* [group squirgle 0 1 Label "Intensity"] */ float blur = 0.02; /* [group squirgle 0 .1 Label "Antialias Edge"] */ float rad = .5; /* [group squirgle 0 1 Label "Radius"] */ float power = 2; /* [group squirgle 1 2 Label "Power"] */ float rotDeg = 0.0; /* [group squirgle 0 1 Label "Rotation"] */ float sflip = 0; /* [group squirgle 0 or 1 Label "Flip S Coordinate"] */ float tflip = 0; /* [group squirgle 0 or 1 Label "Flip T Coordinate"] */ color patcolor = color (1,1,0);/* [group foreground Label "Color"] */ string pat_texname = "";/* [group foreground Label "Texture"] */ float rotDegT1 = 0.0; /* [group foreground 0 1 Label "Rotation"] */ float patTransS = 0.0;/* [group foreground -1 1 Label "Translate S"] */ float patTransT = 0.0;/* [group foreground -1 1 Label "Translate T"] */ float patScale = 1.0;/* [group foreground 0 2 Label "Scale"] */ color bakcolor = color (.6,.3,1); /* [group background Label "Color"] */ string bak_texname = "";/* [group background Label "Texture"] */ float rotDegT2 = 0.0; /* [group background 0 1 Label "Rotation"] */ float bakTransS = 0.0;/* [group background -1 1 Label "Translate S"] */ float bakTransT = 0.0;/* [group background -1 1 Label "Translate T"] */ float bakScale = 1.0;/* [group background 0 2 Label "Scale"] */ ) { float rotationShape = radians(rotDeg-45); float rotationImg1 = radians(rotDegT1); float rotationImg2 = radians(rotDegT2); float shapeS = rotateS(rotationShape); float shapeT = rotateT(rotationShape); float sTex1 = (rotateS(rotationImg1) + patTransS + (patScale / 2)) * (1 / patScale); float tTex1 = (rotateT(rotationImg1) + patTransT + (patScale / 2)) * (1 / patScale); float sTex2 = (rotateS(rotationImg2) + bakTransS + (bakScale / 2)) * (1 / bakScale); float tTex2 = (rotateT(rotationImg2) + bakTransT + (bakScale / 2)) * (1 / bakScale); color patcolor_copy = patcolor; color bakcolor_copy = bakcolor; if(pat_texname != "") patcolor_copy = texture(pat_texname, sTex1, tTex1); if(bak_texname != "") bakcolor_copy = texture(bak_texname, sTex2, tTex2); color surfcolor = bakcolor_copy; //(pow(snew, power) + pow(tnew, power)) < pow(rad, power) float val = pow(rad, power); float thresh = (pow(abs(shapeS), power) + pow(abs(shapeT), power)); float blend = smoothstep(thresh - blur, thresh + blur, val); surfcolor = mix(bakcolor_copy, patcolor_copy, blend); /* STEP 1 - set the apparent surface opacity */ Oi = Os; /* STEP 2 - calculate the apparent surface color */ Ci = Oi * Cs * surfcolor * Kfb; }
void calculateRelativeIOR( float n0; float n1; float n2; output varying float eta0; output varying float eta1; output varying float delta ) { eta0 = n0/n1; eta1 = n1/n2; float delta10 = (n1 > n0) ? PI : 0; float delta12 = (n2 > n1) ? PI : 0; delta = delta10 + delta12; }
void calculatePolarization( vector incLightVec; vector Nn; float n0; float n1; float n2; output varying float costheta1; output varying float alpha_s; output varying float alpha_p; output varying float beta_s; output varying float beta_p; output varying float lightRatio; output varying float frontside ) { /* Calculate Theta0 */ vector Ll = normalize(incLightVec); // normalized light vector float costheta0 = Ll.Nn; // calculate cos of angle of incidence frontside = (costheta0 > 0) ? 1 : 0; /* End Calculate Theta0 */ /* Calculate Theta1 */ float sintheta1 = pow(n0 / n1, 2) * (1 - pow(costheta0, 2)); // calculat sin of angle of refraction (sintheta1) sintheta1 = (sintheta1 > 1) ? 1 : sintheta1; // clamp total internal refraction costheta1 = sqrt(1 - sintheta1); // convert from sin to cos /* End Calculate Theta1 */ /* Calculate Theta2 */ float sintheta2 = pow(n0 / n2, 2) * (1 - pow(costheta0, 2)); // calculat sin of angle of refraction (sintheta1) sintheta2 = (sintheta2 > 1) ? 1 : sintheta2; // clamp total internal refraction float costheta2 = sqrt(1 - sintheta2); // convert from sin to cos /* End Calculate Theta2 */ //calculate alpha s and t separately alpha_s = ((n1 * costheta1 - n0 * costheta0) / (n1 * costheta1 + n0 * costheta0))*((n1 * costheta1 - n2 * costheta2) / (n1 * costheta1 + n2 * costheta2)); alpha_p = ((n0 * costheta1 - n1 * costheta0) / (n1 * costheta0 + n0 * costheta1)) * ((n2 * costheta1 - n1 * costheta2) / (n1 * costheta2 + n2 * costheta1)); //calculate beta s and t separately beta_s = (2 * n0 * costheta0 / (n0 * costheta0 + n1 * costheta1)) * (2 * n1 * costheta1 / (n1 * costheta1 + n2 * costheta2)); beta_p = (2 * n0 * costheta0 / (n0 * costheta1 + n1 * costheta0)) * (2 * n1 * costheta1 / (n1 * costheta2 + n2 * costheta1)); // calculate light ratio lightRatio = (n2 * costheta2) / (n0 * costheta0); }
float calculateIntensity( float lambda; float n1; float calculatedThickness; float costheta1; float delta; float alpha_s; float alpha_p; float beta_s; float beta_p; float lightRatio; float frontside ) { // calculate optical path difference float phi = (((2 * PI) / lambda) * (2 * n1 * calculatedThickness * costheta1) + delta); //transmitted intensity for two possible polarizations float ts = pow(beta_s, 2) / (pow(alpha_s, 2) - 2 * alpha_s * cos(phi) + 1); float tp = pow(beta_p, 2) / (pow(alpha_p, 2) - 2 * alpha_p * cos(phi) + 1); //Transmission based 50% average distribution float transIntensity = (ts + tp) * lightRatio / 2; //Reflectance based on transmission intensity (conservation of energy assumption) float reflectIntensity = 1 - transIntensity; if(frontside) return reflectIntensity; else return 1; }
illuminance(P) { float costheta1; float alpha_s; float alpha_p; float beta_s; float beta_p; float lightRatio; float frontside; calculatePolarization(L, Nn, n0, n1, n2, costheta1, alpha_s, alpha_p, beta_s, beta_p, lightRatio, frontside); // variables to store color based on varying lambda and reflectance and transmission intensities float X = 0; float Y = 0; float Z = 0; float i; // calculate transmission and reflectance intensitie for varying lambda for(i = 0; i < 81; i+=1) { float lambda = i * 5 + 380; float reflectIntensity = calculateIntensity(lambda, n1, thickness, costheta1, delta, alpha_s, alpha_p, beta_s, beta_p, lightRatio, frontside); //Add current color to color coordinate sums, multiplied by reflectance Intensity X += comp(lookup[i], 0) * reflectIntensity; Y += comp(lookup[i], 1) * reflectIntensity; Z += comp(lookup[i], 2) * reflectIntensity; } // identity of CIE x + y + z = 1, therefore xOut = x / (x + y + z) float XYZ = X + Y + Z; float outX = X / XYZ; float outY = Y / XYZ; float outZ = Z / XYZ; color outcolor = color "XYZ" (outX, outY, outZ); outcolor = adjustHSV(outcolor, "XYZ", hueShift, saturation, 0); interference_col *= (Cl * outcolor); }