#ifdef RCSIDS static char rcsid[] = "$Id: glass.sl,v 1.8 1998/09/18 23:09:29 lg Exp $"; #endif /* * glass.sl -- Shiny reflective & refractive glass, using ray tracing. * * DESCRIPTION: * Makes semi-transparent glass, using ray tracing to calculate * reflections and refractions of the environment. * * PARAMETERS: * Ka, Kd, Ks, roughness, specularcolor - The usual meaning * Kr - coefficient for mirror-like reflections of environment * Kt - coefficient for refracted transmission * transmitcolor - color of the glass * eta - the coefficient of refraction of the glass * reflectblur - how blurry are the reflections? (0 = perfectly sharp) * refractblur - how blurry are the refractions? (0 = perfectly sharp) * samples - set to higher than 1 for oversampling of blur * reflectsamples, refractsamples - individual settings * * AUTHOR: written by Larry Gritz, gritzl@acm.org * * $Revision: 1.8 $ $Date: 1998/09/18 23:09:29 $ * */ #include "locillum.h" #include "rayserver.h" #include "raytrace.h" surface glass ( float Ka = 0.2, Kd = 0, Ks = 0.5; float Kr = 1, Kt = 1, roughness = 0.05; float reflectblur = 0, refractblur = 0, eta = 1.5; color specularcolor = 1, transmitcolor = 1; float samples = 1, reflectsamples = 1, refractsamples = 1; ) { color ev = 0; /* Color of the environment reflections */ color cr = 0; /* Color of the refractions */ vector IN = normalize (I); normal Nf = faceforward (normalize(N), I); /* Compute the reflection & refraction directions and amounts */ vector Rfldir, Rfrdir; /* Smooth reflection/refraction directions */ float kr, kt; fresnel (IN, Nf, (I.N < 0) ? 1.0/eta : eta, kr, kt, Rfldir, Rfrdir); kt = 1-kr; /* Physically incorrect, but portable */ kr *= Kr; kt *= Kt; /* Calculate the reflection color */ if (kr > 0.001) { ev = kr * RayTrace (P, normalize(Rfldir), reflectblur, 1, max(samples,reflectsamples)); } /* Calculate the refraction color */ if (kt > 0.001) { cr = kt * RayTrace (P, normalize(Rfrdir), refractblur, 1, max(samples,refractsamples)); } Oi = 1; Ci = ( Cs * (Ka*ambient() + Kd*diffuse(Nf)) + specularcolor * (ev + Ks*LocIllumGlossy(P,Nf,-IN,roughness,0.5)) + transmitcolor * cr ); }