/* surface shader: shiny_building creator: Nick Meshes, DePaul University description: Based on loosely screen.sl and shiny.sl Makes a surface that looks like an office building with reflective windows. Walls look plastic-like though. parameters: Ka, Kd, Ks, roughness, specularcolor - work just like the plastic shader wallcolor and windowcolor window width and height set parts between windows set as well. up - x=0, y=1, z=2, building is square in this algorithm widthoffset will be between 0 and (windowwidth + wallwidth) heightoffset will be between 0 and (windowheight + wallheight) ceiling - top where no more windows exist floor - bottom where no more windows exist */ #include "rayserver.h" #include "raytrace.h" surface linewind_building (float Ka = .8, Kd = 0.75, Ks = 0.2, roughness = 0.2; color specularcolor = 1; color wallcolor = Cs; color windowcolor = color(1, .75, 0); float up = 2; float ceiling = 100, floor = -100; float windowwidth = 1, wallwidth = 1; float windowheight = 1, wallheight = 1; float widthoffset = 0, heightoffset = 0; float windowlines = 2; float linewidth = .2; color linecolor = color(0, 0, 0); float Kr = 0.5, blur = 0; float samples = 1; ) { normal Nf = faceforward(normalize(N),I); vector IN = normalize(I);; float xpart, ypart, zpart; float sum = 0; color ev = 0; if (up == 0){ xpart = abs(ycomp(P)); ypart = abs(zcomp(P)); zpart = abs(xcomp(P)); } else if (up == 1){ xpart = abs(zcomp(P)); ypart = abs(xcomp(P)); zpart = abs(ycomp(P)); } else{ xpart = abs(xcomp(P)); ypart = abs(ycomp(P)); zpart = abs(zcomp(P)); } Cs = wallcolor; xpart = mod((xpart + widthoffset), (windowwidth + wallwidth)); ypart = mod((ypart + widthoffset), (windowwidth + wallwidth)); zpart = mod((zpart + heightoffset), (windowheight + wallheight)); if (zpart <= floor) sum = 1; if (zpart >= ceiling) sum = 1; if (xpart > (windowwidth/2)) if (xpart < (wallwidth + (windowwidth/2))) sum = sum + .5; if (ypart > (windowwidth/2)) if (ypart < (wallwidth + (windowwidth/2))) sum = sum + .5; if (zpart > (windowheight/2)) if (zpart < (wallheight + (windowheight/2))) sum = sum + 1; if (sum < 1){ if (Kr > 0.001) { vector Rdir = normalize (reflect (IN, Nf)); ev = Kr * RayTrace (P, Rdir, blur, 1, samples); Cs = windowcolor; linewidth = linewidth/2; windowwidth = windowwidth/(windowlines + 1); xpart = mod(xpart, windowwidth); ypart = mod(ypart, windowwidth); if (xpart > (windowwidth - linewidth)) Cs = linecolor; else if (xpart < linewidth) Cs = linecolor; else if (ypart > (windowwidth - linewidth)) Cs = linecolor; else if (ypart > linewidth) Cs = linecolor; /* else if (Kr > 0.001) { * vector Rdir = normalize (reflect (IN, Nf)); * ev = Kr * RayTrace (P, Rdir, blur, 1, samples); * Cs = windowcolor; */ } } Ci = Cs * (Ka*ambient() + Kd*diffuse(Nf)) + specularcolor * (ev + Ks*specular(Nf,-IN,roughness)); Oi = Os; Ci *= Oi; }