eval_light VEX function

Runs light shaders for a light and exports evaluated information.

Contexts: displace, fog, light, shadow, surface

See also: sample_light, luminance

  1. eval_light(int lightid, vector pos, vector dir, float time, vector &clr, float &scale)

lightid

An integer identifying a light. You can get a list of light IDs for lights affecting the currently shaded surface with getlights.

pos

The position on the surface being evaluated (such as the global variable P).

dir

Vector from the surface to a point on the light source. The length of this vector must be the distance to the light.

time

Time to shade at.

The function modifies the values of the following arguments:

clr

The light color set by the light shader.

scale

The light average hemispherical intensity (for area lights).

Depending on how the light direction was generated, you may need to post-process the clr/scale outputs differently. If the light source position was sampled (for example using sample_light), you should normalize clr to scale:

clr *= scale / luminance(clr);

If the light direction was generated by hemispherical sampling of a surface, you should use clr without normalization.