Class TShadowVolumesHelper

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TShadowVolumesHelper = class(TObject)

Description

This class performs various initialization and calculations related to shadow volume rendering. It does everything, except the actual shadow volume rendering (this is handled elsewhere, for example in TVRMLFlatSceneGL.RenderShadowVolume).

To use this class: call InitGLContext, InitFrustumAndLight, InitScene at appropriate moments. Setup your stencil buffer by setting StencilSetupKind before InitScene. Pass the instance of this to TVRMLFlatSceneGL.RenderShadowVolume.

Hierarchy

Overview

Methods

Public procedure InitGLContext;
Public procedure InitFrustumAndLight( const Frustum: TFrustum; const ALightPosition: TVector4Single);
Public procedure InitScene(const SceneBox: TBox3d);
Public procedure InitSceneDontSetupStencil(const SceneBox: TBox3d);
Public procedure InitSceneOnlySetupStencil;
Public procedure InitSceneAlwaysVisible;

Properties

Public property WrapAvailable: boolean read FWrapAvailable;
Public property LightPosition: TVector4Single read FLightPosition;
Public property LightPositionDouble: TVector4Double read FLightPositionDouble;
Public property SceneShadowPossiblyVisible: boolean read FSceneShadowPossiblyVisible;
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 false;
Public property CountScenes: Cardinal read FCountScenes;
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 procedure InitGLContext;

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: TVector4Single);

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 InitScene.

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

It also resets CountScenes etc. counters for debug purposes.

Public procedure InitScene(const SceneBox: 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 SceneBox, settting SceneShadowPossiblyVisible. 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 InitScene will assume that they have complete control over glStencilOp states for the time of rendering shadow volumes. In other words: InitScene 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 InitScene after InitFrustumAndLight does always setup stencil confguration. Following InitScene 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 InitSceneDontSetupStencil(const SceneBox: TBox3d);

You can split InitScene call into these two calls, first InitSceneDontSetupStencil and then InitSceneOnlySetupStencil.

This is useful only in very special cases, in particular: if you only have one shadow caster object in your scene. Then you can call InitSceneDontSetupStencil only once, before any drawing, and later you can call InitSceneOnlySetupStencil multiple times to set stencil configuration for this object.

Public procedure InitSceneOnlySetupStencil;
 
Public procedure InitSceneAlwaysVisible;

This is an alternative version of InitScene that initializes the same variables as InitScene, but assumes that the scene, along with it's shadow, will always be visible. This means that for example SceneShadowPossiblyVisible, ZFail, ZFailAndLightCap will always be True.

Use this only if you have a scene that will really be always visible and z-fail will be needed. For example, level scene in FPS games will usually be always visible, so making optimizations in InitScene may be useless. Also, this is useful if for any reason you don't know bounding box of the scene.

Properties

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

Light casting shadows position, initialized by InitFrustumAndLight.

Public property LightPositionDouble: TVector4Double read FLightPositionDouble;
 
Public property SceneShadowPossiblyVisible: boolean read FSceneShadowPossiblyVisible;

Does the shadow need to be rendered, set by InitScene.

Public property ZFail: boolean read FZFail;

Is the ZFail method needed, set by InitScene.

Public property ZFailAndLightCap: boolean read FZFailAndLightCap;

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

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 InitGLContext, and is true if OpenGL provides one of:

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

What kind of stencil settings should be set by InitScene ?

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 false;
 
Public property CountScenes: Cardinal read FCountScenes;
 
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.10.0 on 2008-02-25 00:00:38