/*
 * aachrome: anti-aliased reflective chrome shader.
 * This shader shoots 'samples' rays to reduce aliasing in directly visible
 * surfaces.  It only shoots 1 ray at secondary reflections to avoid an
 * exponential explosion in the number of rays.
 *
 * Warning: only use this shader on objects that have normals facing out!
 */

#include "material.h"

surface
aachrome (float Kr = 1, float samples = 1, string envmap = "raytrace")
{
    color Crefl;
    float s;

    s = (raylevel() == 0) ? samples : 1; /* only 1 ray for secondary reflections */

    if (dot(N,I) < 0) {
        normal Nn = normalize(N);
        vector In = normalize(I);
        vector reflDir = reflect(In,Nn);
        Crefl = Environment(envmap, reflDir, "", 0, s, 1);
    } else { /* don't reflect inside object */
        Crefl = 0;
    }

    C = Kr * Crefl;
    opacity = 1;
}
