/* surface shader: square_screen creator: Nick Meshes, DePaul University description: Based on screen.sl Makes a surface that looks like a metal screen. Strips of metal run parallel to lines of two dimensions. You can adjust the Ka, Kd, Ks, etc. to change the material appearance. parameters: Ka, Kd, Ks, roughness, specularcolor - work just like the plastic shader frequency - how many cycles of screen in st space density - how much of each cycle is opaque? dimensions - x = 1, y = 2, z = 4, add the two you want i.e x+y = 3, x+z = 5, y+z = 6 widthoffset will be between 0 and (windowwidth + wallwidth) heightoffset will be between 0 and (windowheight + wallheight) */ surface square_screen (float Ka = 1, Kd = 0.75, Ks = 0.4, roughness = 0.1; color specularcolor = 1; color screencolor = color(1, 0, 0); float dimensions = 3; float windowwidth = 1, wallwidth = 1; float windowheight = 1, wallheight = 1; float widthoffset = 0, heightoffset = 0; ) { normal Nf; vector V; float apart; float bpart; float sum; if (dimensions == 5){ apart = abs(xcomp(P)); bpart = abs(zcomp(P)); } else if (dimensions == 6){ apart = abs(ycomp(P)); bpart = abs(zcomp(P)); } else{ apart = abs(xcomp(P)); bpart = abs(ycomp(P)); } Cs = screencolor; apart = mod((apart + widthoffset), (windowwidth + wallwidth)); bpart = mod((bpart + heightoffset), (windowheight + wallheight)); sum = 0; if (apart > (wallwidth/2)) if (apart < (windowwidth + (wallwidth/2))) sum = sum + 1; if (bpart > (wallheight/2)) if (bpart < (windowheight + (wallheight/2))) sum = sum + 1; if (sum == 2) Os = 0; Nf = faceforward(normalize(N),I); V = -normalize(I); Oi = Os; Ci = Oi * ( Cs * (Ka*ambient() + Kd*diffuse(Nf)) + specularcolor * Ks*specular(Nf,V,roughness)); }