Class TGLShadowVolumeRenderer

Unit

Declaration

type TGLShadowVolumeRenderer = class(TBaseShadowVolumeRenderer)

Description

Shadow volume rendering in OpenGL. This class provides various utilities related to shadow volume rendering. It provides everything, except it doesn't actually render the 3D models or their shadow volumes (actual rendering is provided by T3D descendants, like TCastleScene.RenderShadowVolume).

For general usage tutorial of this class, see [http://castle-engine.sourceforge.net/vrml_engine_doc/output/xsl/html/chapter.shadows.html]

Hierarchy

  • TGLShadowVolumeRenderer

Overview

Methods

Public constructor Create;
Public procedure GLContextOpen;
Public procedure InitFrustumAndLight( const Frustum: TFrustum; const ALightPosition: TVector4);
Public procedure InitCaster(const CasterBox: TBox3D);
Public procedure Render( const Params: TRenderParams; const Render3D: TSVRenderParamsProc; const RenderShadowVolumes: TSVRenderProc; const DrawShadowVolumes: boolean);

Properties

Public property WrapAvailable: boolean read FWrapAvailable;
Public property LightPosition: TVector4 read FLightPosition;
Public property CasterShadowPossiblyVisible: boolean read FCasterShadowPossiblyVisible;
Public property ZFail: boolean read FZFail;
Public property ZFailAndLightCap: boolean read FZFailAndLightCap;
Public property StencilTwoSided: boolean read FStencilTwoSided;
Public property StencilSetupKind: TStencilSetupKind read FStencilSetupKind write FStencilSetupKind default ssFrontAndBack;
Public property Count: boolean read FCount write FCount default true;
Public property CountCasters: Cardinal read FCountCasters;
Public property CountShadowsNotVisible: Cardinal read FCountShadowsNotVisible;
Public property CountZPass: Cardinal read FCountZPass;
Public property CountZFailNoLightCap: Cardinal read FCountZFailNoLightCap;
Public property CountZFailAndLightCap: Cardinal read FCountZFailAndLightCap;

Description

Methods

Public constructor Create;
 
Public procedure GLContextOpen;

Call this when OpenGL context is initialized, this will set some things. For now, this sets StencilOpIncrWrap, StencilOpDecrWrap.

Public procedure InitFrustumAndLight( const Frustum: TFrustum; const ALightPosition: TVector4);

Call this when camera frustum is known and light position (of the shadow casting light) is known, typically at the beginning of your drawing routine. You have to call this before InitCaster.

This prepares some things (so that each InitCaster call doesn't have to) and all subsequent InitCaster calls assume that Frustum and LightPosition are the same.

It also resets CountCasters etc. counters for debug purposes.

Public procedure InitCaster(const CasterBox: TBox3D);

Call this when the bounding box of shadow caster is known.

This calculates various things related to shadow volumes rendering of this scene. 1. checks whether you need to render shadow of the object inside CasterBox, settting CasterShadowPossiblyVisible. 2. checks whether ZFail method is needed, setting ZFail.

This assumes that Frustum and LightPosition values given in InitFrustumAndLight are OK.

Also note that after InitFrustumAndLight, all InitCaster will assume that they have complete control over glStencilOp states for the time of rendering shadow volumes. In other words: InitCaster will setup some stencil configuration, depending on ZFail state and StencilSetupKind. For the sake of speed, we try to avoid setting the same state twice, so we optimize it: first InitCaster after InitFrustumAndLight does always setup stencil confguration. Following InitCaster will only change stencil configuration if ZFail value will actually change. This means that if e.g. all objects will be detected to be in z-pass method, then stencil configuration will be done only once.

The above optimization works OK if you do not change StencilOp configuration yourself during SV rendering.

Public procedure Render( const Params: TRenderParams; const Render3D: TSVRenderParamsProc; const RenderShadowVolumes: TSVRenderProc; const DrawShadowVolumes: boolean);

Do actual rendering with shadow volumes.

You have to provide the appropriate callbacks that render given scene parts.

Params.Transparent and Params.ShadowVolumesReceivers and Params.InShadow are changed here (their previous values are ignored). They cannot be modified by our callbacks.

Render3D renders part of the scene.

  • With Params.ShadowVolumesReceivers = True, renders only things that may be in the shadow. You should use Params.InShadow to either display the version of the scene in the shadows (so probably darker, probably with some lights off) or the version that is currently lighted (probably brighter, with normal scene lights on).

  • With Params.ShadowVolumesReceivers = False, renders only things that must never be considered in shadow (are not shadow receivers). Params.InShadow is always False when Params.ShadowVolumesReceivers = False.

Render3D must also honour Params.Transparent, rendering only opaque or only transparent parts. For Transparent = True, always Params.InShadow = False. Shadow volumes simply don't allow transparent object to function properly as shadow receivers. Reading [http://developer.nvidia.com/object/fast_shadow_volumes.html] notes: they also just do separate rendering pass to render the partially-transparent parts, IOW they also note that transparent parts simply don't work at all with shadow volumes.

RenderShadowVolumes renders shadow volumes from shadow casters.

If DrawShadowVolumes then shadow volumes will be also actually drawn to color buffer (as yellow blended polygons), this is useful for debugging shadow volumes.

Properties

Public property WrapAvailable: boolean read FWrapAvailable;
 
Public property LightPosition: TVector4 read FLightPosition;

Light casting shadows position, initialized by InitFrustumAndLight.

Public property CasterShadowPossiblyVisible: boolean read FCasterShadowPossiblyVisible;

Does the shadow need to be rendered, calculated by last InitCaster call.

Public property ZFail: boolean read FZFail;

Is the ZFail method needed, set by InitCaster.

Public property ZFailAndLightCap: boolean read FZFailAndLightCap;

Is the ZFail with light caps method needed, set by InitCaster.

Public property StencilTwoSided: boolean read FStencilTwoSided;

Is two-sided stencil test (that allows you to make SV in a single pass) available.

This is initialized by GLContextOpen, and is true if OpenGL provides one of:

  • glStencilOpSeparate (in OpenGL >= 2.0)

  • GL_ATI_separate_stencil extension, glStencilOpSeparateATI

  • We could also handle GL_EXT_stencil_two_side extension, glActiveStencilFaceEXT. But, since OpenGL >= 2.0 is now common, don't try.

Public property StencilSetupKind: TStencilSetupKind read FStencilSetupKind write FStencilSetupKind default ssFrontAndBack;

What kind of stencil settings should be set by InitCaster.

Set ssFrontAndBack only if StencilTwoSided is True. Otherwise, you have to use 2-pass method (render everything 2 times, culling front one time, culling back second time) — in this case use ssFront or ssBack as appropriate.

Public property Count: boolean read FCount write FCount default true;

Statistics of shadow volumes. They are enabled by default, as calculating them takes practically no time.

Public property CountCasters: Cardinal read FCountCasters;
 
Public property CountShadowsNotVisible: Cardinal read FCountShadowsNotVisible;
 
Public property CountZPass: Cardinal read FCountZPass;
 
Public property CountZFailNoLightCap: Cardinal read FCountZFailNoLightCap;
 
Public property CountZFailAndLightCap: Cardinal read FCountZFailAndLightCap;
 

Generated by PasDoc 0.15.0.