Castle Game EngineIntroduction Units Class Hierarchy Classes, Interfaces, Objects and Records Types Variables Constants Functions and Procedures Identifiers
|
Class TGLShadowVolumeRenderer
Unit
CastleGLShadowVolumes
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
Overview
Methods
Properties
Description
Methods
 |
constructor Create; |
|
 |
procedure GLContextOpen; |
Call this when OpenGL context is initialized, this will set some things. For now, this sets StencilOpIncrWrap, StencilOpDecrWrap.
|
 |
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.
|
 |
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.
|
 |
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
 |
property WrapAvailable: boolean read FWrapAvailable; |
|
 |
property CasterShadowPossiblyVisible: boolean read FCasterShadowPossiblyVisible; |
Does the shadow need to be rendered, calculated by last InitCaster call.
|
 |
property ZFail: boolean read FZFail; |
Is the ZFail method needed, set by InitCaster.
|
 |
property ZFailAndLightCap: boolean read FZFailAndLightCap; |
Is the ZFail with light caps method needed, set by InitCaster.
|
 |
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.
|
 |
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.
|
 |
property CountCasters: Cardinal read FCountCasters; |
|
 |
property CountShadowsNotVisible: Cardinal read FCountShadowsNotVisible; |
|
 |
property CountZPass: Cardinal read FCountZPass; |
|
 |
property CountZFailNoLightCap: Cardinal read FCountZFailNoLightCap; |
|
 |
property CountZFailAndLightCap: Cardinal read FCountZFailAndLightCap; |
|
Generated by PasDoc 0.15.0.
|