Houdini 12 VEX VEX functions

Samples a 3D position on a light source and runs the light shader at that point.

  1. int sample_light(int lightid, vector pos, vector sam, float time, vector &pos, vector &clr, float &scale)

The return value from sample_light is a bitmask indicating which types of bounces the light affects.

The following bitmask constants are defined in pbr.h:

  • PBR_DIFFUSE_MASK - diffuse component

  • PBR_GLOSSY_MASK - glossy component

  • PBR_SPECULAR_MASK - mirror specular component

  • PBR_VOLUME_MASK - volume component

The function takes the following arguments:

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 surface point from which lights should be sampled. Area light sources will attempt to distribute samples by solid angle from the position - that is, light geometry that is closer to the position will receive more samples.

sam

A vector of random values, such as those generated by nextsample. Currently only the first 2 components of sam are used. Different values of sam translate into different random positions on the geometry of the light source.

time

Time to shade at.

The function modifies the values of the following arguments:

pos

The sampled position on the light source.

clr

The light color set by the light shader.

scale

The light average hemispherical intensity (for area lights).

If you are using sample_light to generate light colors, for example to reproduce the Cl values that would be produced by a illuminance loop, you will need to normalize clr to scale:

clr *= scale / luminance(clr);

Contexts: displace, fog, light, shadow, surface

Related topics