home *** CD-ROM | disk | FTP | other *** search
- // rh.glass -- a custom glass shader with fake caustic shadow.
- // In this shader the RIB surface color determines the glass color and
- // the glass surface itself has no color.
- // It is based on glass.sl by Larry Gritz.
-
- #include "locillum.h"
- #include "rayserver.h"
- #include "raytrace.h"
-
- surface
- rh_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;
- float samples = 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);
- kr *= Kr;
- kt *= Kt;
-
- /* Calculate the reflection color */
- if (kr > 0.001) {
- ev = kr * RayTrace (P, normalize(Rfldir), reflectblur, 1, samples);
- }
-
- /* Calculate the refraction color */
- if (kt > 0.001) {
- cr = kt * RayTrace (P, normalize(Rfrdir), refractblur, 1, samples);
- }
-
- if ( isshadowray() > 0 ) {
- Oi = Os * (1 - abs(IN.Nf) * Cs); /* fake caustics */
- } else {
- Oi = 1;
- Ci = ( (Ka*ambient() + Kd*diffuse(Nf)) +
- specularcolor * (ev + Ks*LocIllumGlossy(P,Nf,-IN,roughness,0.5)) +
- Cs * cr );
- }
- }
-