/* 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 barwall_building (float Ka = .8, Kd = 0.75, Ks = 0.2, roughness = 0.2; color specularcolor = 1; color wallcolor = color(0, 0, .5); color stripcolor = color(.2, .2, .2); color divcolor = color(0,0,0); float stripwidth = .1; float divwidth = 0.25; 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 Kr = 0.5, blur = 0; float samples = 1; ) { normal Nf = faceforward(normalize(N),I); vector IN = normalize(I); float xpart, ypart, zpart; float area = 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) area = 1; if (zpart >= ceiling) area = 1; if (zpart > (windowheight/2)) if (zpart < (wallheight + (windowheight/2))){ area += 1; if (zpart > (wallheight + (windowheight/2) - stripwidth)){ if (zpart < (wallheight + (windowheight/2) - stripwidth + divwidth)) Cs = divcolor; else if (zpart > (wallheight + (windowheight/2) - divwidth)) Cs = divcolor; else Cs = stripcolor; } } if (xpart > (windowwidth/2)) if (xpart < (wallwidth + (windowwidth/2))){ area += 1; if (xpart > (wallwidth + (windowwidth/2) - stripwidth)){ if (xpart < (wallwidth + (windowwidth/2) - stripwidth + divwidth)) Cs = divcolor; else if (xpart > (wallwidth + (windowwidth/2) - divwidth)) Cs = divcolor; else Cs = stripcolor; } } if (ypart > (windowwidth/2)) if (ypart < (wallwidth + (windowwidth/2))){ area += 1; if (ypart > (wallwidth + (windowwidth/2) - stripwidth)){ if (ypart < (wallwidth + (windowwidth/2) - stripwidth + divwidth)) Cs = divcolor; else if (ypart > (wallwidth + (windowwidth/2) - divwidth)) Cs = divcolor; else Cs = stripcolor; } } if (area == 0){ 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; }