view_to_light (VIEW* view, var num,var mode);
Sets the given view to the position of a shadow throwing dynamic light, for rendering a scene from a light position.
Parameters:
view - the view to be set to the light position.
num - the light number from 1 = closest to 8 = furthest.
mode - CAST = consider only lights with a CAST flag; SPOTLIGHT = consider only spot lights.
Returns:
Number of lights yet to render that overlap with the frustum of the current view, including the current light (0..8).
Modifies:
view.x y z - set to the light position.
view.clip_near- set to 1.
view.clip_far - set to the light range.
view.pan tilt - set to the light angles if it is a spot or directional light; otherwise unaffected.
view.genius - set to the light emitting entity, or at NULL if it's a light placed
in the level.
Remarks:
-
Only lights with a range fully or partially within the view frustum, and the sun light are considered for this function.
- If this function is called during rendering, i.e. in a view material render event, the frustum of the current view is used for determining the closest lights. Otherwise the camera view frustum is used. Note: the view passed as parameter has no affect on determining the closest lights!
Speed:
Slow when called the first time for the current view; fast in subsequent calls.
Edition:
A7.07C LC
Example (lite-C):
// sets up to six views for rendering from a light position
// returns 0, 1, or 6 dependent on how many views are to render for this light
function shadowmap_view_setup(light_num)
{
view_light_front.pan = -1; // for checking whether it's a spot light
var num = view_to_light(view_light_front,light_num,CAST); // set view to the light position
if (num == 0) return 0; // no further shadow throwing lights to render
if (view_light_front.pan >= 0) return 1; // sun or spot light? render front view only
view_light_front.pan = 0;
view_to_light(view_light_right,light_num,CAST);
view_to_light(view_light_back,light_num,CAST);
view_to_light(view_light_left,light_num,CAST);
view_to_light(view_light_up,light_num,CAST);
view_to_light(view_light_down,light_num,CAST);
return 6;
}
See also:
VIEW, stage, c_scan
► latest
version online