refractlight VEX function

Computes the illumination of surfaces refracted by the current surface.

Contexts: fog, surface

  1. void refractlight(vector cf&, vector of&, float af&, vector P, vector D, float bias, float max_contrib)

  2. void refractlight(vector cf&, vector of&, float af&, vector P, vector N, vector I, float eta, float bias, float max_contrib)

Computes the illumination of surfaces refracted by the current surface. Computes and outputs the output color (cf), opacity (of) and alpha (af). See opacity vs. alpha .

bias is typically a small number (for example 0.005) used to help eliminate self-reflection.

max_contrib tells the renderer how much the reflected light will contribute to the final color of the pixel. This has no effect on the resultant color.

The first form of the refractlight() function takes a position and direction, typically computed by the refract or fresnel functions.

To prevent the renderer from computing standard transparency (i.e. non-refracted transparency), the Of variable must be set to {1,1,1} to make the surface “opaque”. The Af variable can be set to any arbitrary value.

See optional parameters .

surface glass(float eta=1.3, bias = 0.005)
{
    float    Kr, Kt;
    vector    R, T;
    vector    cf, of;
    float    af;
    frensel(normalize(I), normalize(N), eta, Kr, Kt, R, T);
    Cf  = Kr * reflectlight(P, R, bias, Kr);
    refractlight(cf, of, af, P, T, bias, Kt);
    Cf += Kt * cf;
    Af = clamp(Kr + af*Kt, 0, 1);
    Of = 1;
}