![]() |
VR-Forces Developer's Guide
|
Implements cascaded shadow mapping (CSM) for the VRV rendering pipeline.
Manages the full shadow rendering lifecycle per-channel: shadow camera setup, cascade split computation, light view/projection matrix construction, shadow texture allocation, and receiver shader configuration.
Key features:
One instance is shared across all channels. Per-channel state (cameras, textures, uniforms, and visualizers) is stored in DtPerChannelData, keyed by view camera.

Classes | |
| struct | CameraDescription |
| struct | MulticastDebugInfo |
Public Member Functions | |
| DtOsgShadowTechnique (DtDe &de) | |
| DtOsgShadowTechnique (const DtOsgShadowTechnique &es, const osg::CopyOp ©op=osg::CopyOp::SHALLOW_COPY) | |
| virtual osg::Object * | cloneType () const |
| virtual osg::Object * | clone (const osg::CopyOp ©op) const |
| virtual bool | isSameKindAs (const osg::Object *obj) const |
| virtual const char * | libraryName () const |
| virtual const char * | className () const |
| virtual void | init () |
| virtual void | postConstructionInit () |
| virtual void | update (osg::NodeVisitor &nv) |
| virtual void | cull (osgUtil::CullVisitor &cv) |
| virtual void | cleanSceneGraph () |
| void | setChannelShadowState (DtOsgChannel *osgChannel, bool enable) |
| bool | getChannelShadowSettings (DtOsgChannel *osgChannel, DtShadowSettingsObject **shadowSettingObject, bool *isPlanView) |
| void | setGlobalLight (osg::LightSource *light) |
| const osg::LightSource * | getGlobalLight () const |
| const osg::StateSet * | mapCameraToStateSet (const osg::Camera *camera) const |
| virtual void | resizeGLObjectBuffers (unsigned int maxSize) override |
| virtual void | releaseGLObjects (osg::State *=0) const override |
Static Public Member Functions | |
| static const std::string & | shadowCameraPrefixString () |
Protected Types | |
| typedef std::map< const osg::Camera *, osg::ref_ptr < DtPerChannelData > > | PerChannelDataMap |
| typedef std::vector < osg::ref_ptr < DtPerChannelData > > | PerChannelDataVector |
Protected Member Functions | |
| virtual | ~DtOsgShadowTechnique () |
| virtual void | reInitialize (unsigned int quality) |
| virtual void | cleanupOldPerChannelData () |
| virtual bool | configureShadowTraversalNodeMask (bool traverseEntities, bool traverseProps, bool traverseTerrain) |
| virtual void | slot_refresh_maps () |
| unsigned int | getFilterCount (DtShadowSettingsObject *shadowSettingObject) |
| bool | getReceiveShadows (const DtShadowSettingsObject *shadowSettings) const |
| virtual void | computeFrustumPoints (const osg::Matrix &projectionMat, bool reverseZ, const osg::Matrix &inverseViewMat, double nearPlane, double farPlane, osg::Vec3d *outFrustumPoints) |
| virtual const osg::Vec3 | computeLightDirection (osg::Camera *viewCamera) const |
| virtual void | updateSplitDistancesAndUniforms (DtPerChannelData *perChannelData, DtShadowSettingsObject *shadowSettings, const DtCurrentPassData ¤tPassData) |
| virtual void | updateShadowUniformsAndFilters (DtPerChannelData *perChannelData, DtShadowSettingsObject *shadowSettings, osg::Camera *viewCamera, DtCurrentPassData ¤tPassData, bool &bRefreshFarCascade, unsigned int &unbindingIndex) |
| virtual void | updateAndRenderCascade (unsigned int splitIndex, DtCurrentPassData ¤tPassData, DtPerChannelData *perChannelData, const DtShadowSettingsObject *shadowSettings, const osg::Camera *viewCamera, osgUtil::CullVisitor &cv, unsigned int &unbindingIndex, bool bRefreshFarCascade, DtCVMarkerSeries &series, int &cascades_rendered) |
| virtual void | updateShadowOverlayGui (const DtPerChannelData *perChannelData, const DtCurrentPassData ¤tPassData, int cascadesRendered) |
| virtual void | updateOsgEarthUniforms (const osg::Camera *viewCamera, osg::Camera *cascadeCamera) |
Protected Attributes | |
| PerChannelDataMap | myPerChannelDataMap |
| PerChannelDataVector | myPerChannelDataDeleteList |
| osg::ref_ptr< osg::LightSource > | myGlobalLight |
| osg::ref_ptr< osg::Uniform > | myLightDirectionUniform |
| osg::ref_ptr< osg::Uniform > | myReceiveShadowsUniform |
| DtShadowTweakables * | myShadowUI |
| DtDe & | myDe |
| std::vector< osg::ref_ptr < osg::Camera > > | myDeferredDeleteCamera |
| tbb::mutex | myDeferredCameraDeletionMutex |
| bool | myMulticastIsSupported |
| bool | myShadingRateIsSupported |
| DtSkyObjectManager & | mySkyObjectManager |
| boost::signalslib::connection | myTerrainPatchAddedConnection |
| boost::signalslib::connection | myTerrainPatchDeletedConnection |
| DtOsgShaderFilesCache & | myShaderFilesCache |
| osg::Vec2f | myMaxViewportDims |
| float | myAnisotropy |
Static Protected Attributes | |
| static const std::string | myShadowCameraPrefixString |
Private Member Functions | |
| int | farShadowMapCascadeSize () const |
| bool | getCameraSettings (osg::Camera *viewCamera, DtPerChannelData **perChannelData, DtShadowSettingsObject **shadowSettingObject, bool *isPlanView) |
| void | initPerChannelData (DtPerChannelData *perChannelData, DtShadowSettingsObject *shadowSettingObject) |
| void | setupMulticastMask (DtPerChannelData *perChannelData, DtShadowSettingsObject *shadowSettings) |
| bool | initShadowSplitCamera (DtPerChannelData *perChannelData, DtShadowSettingsObject *shadowSettings, unsigned int numberOfSplits, const osg::ref_ptr< osg::Texture2DArray > &depthTexture2DArray, const osg::ref_ptr< osg::Texture2DArray > &depthTextureFarCascade, const osg::ref_ptr< osg::Texture2DArray > &textureColor2DArray, const osg::ref_ptr< osg::Texture2DArray > &textureColor2DFarCascade, DtCascadeData &cascade) |
| osg::StateSet * | setupShadowCamera (DtCascadeData &cascade, DtPerChannelData *perChannelData, DtShadowSettingsObject *shadowSettings, bool farCascade, unsigned int splitIndex, int farCascadeSize, const osg::ref_ptr< osg::Texture2DArray > &depthTexture2DArray, const osg::ref_ptr< osg::Texture2DArray > &depthTextureFarCascade, const osg::ref_ptr< osg::Texture2DArray > &textureColor2DArray, const osg::ref_ptr< osg::Texture2DArray > &textureColor2DFarCascade) |
| void | setupShadowSplitStateSet (osg::StateSet *cameraStateSet, DtCascadeData &cascade, DtPerChannelData *perChannelData, DtShadowSettingsObject *shadowSettings, unsigned int splitIndex) |
| void | initShadowTextures (DtPerChannelData *perChannelData, DtShadowSettingsObject *shadowSettings, osg::ref_ptr< osg::Texture2DArray > &depthTexture2DArray, osg::ref_ptr< osg::Texture2DArray > &depthTextureFarCascade, osg::ref_ptr< osg::Texture2DArray > &textureColor2DArray, osg::ref_ptr< osg::Texture2DArray > &textureColor2DFarCascade, osg::ref_ptr< osg::Texture2D > &depthTexture2DAtlas, osg::ref_ptr< osg::Texture2D > &debugColor2DAtlas) |
| void | initDebugVisualizers (DtPerChannelData *perChannelData, DtShadowSettingsObject *shadowSettings, DtOsgRenderer *osgRenderer, const osg::ref_ptr< osg::Texture2DArray > &textureColor2DArray, const osg::ref_ptr< osg::Texture2DArray > &textureColor2DFarCascade, const osg::ref_ptr< osg::Texture2DArray > &depthTextureFarCascade, const osg::ref_ptr< osg::Texture2D > &depthTexture2DAtlas, const osg::ref_ptr< osg::Texture2D > &debugColor2DAtlas) |
| void | installReceiverVPandSharedStateSet (DtPerChannelData *perChannelData, DtShadowSettingsObject *shadowSettingObject) |
| void | createPreProcessorDefines (std::string &defines, osg::StateSet &stateSet, DtShadowSettingsObject *shadowSettings) |
| void | triggerExternalModuleShaderRefresh () |
| osg::Program * | getProgramFromFile (const std::string &szVertexShader, const std::string &szFragmentShader) |
| osg::Texture2DArray * | createTexture2DArray (int width, int height, int depth, GLenum internalFormat, GLenum sourceFormat, GLenum sourceType, bool shadowComparisonMode, osg::Texture2DArray::FilterMode minFilter=osg::Texture2DArray::NEAREST, osg::Texture2DArray::FilterMode magFilter=osg::Texture2DArray::NEAREST) |
| osg::Camera * | createCamera (int width, int height, GLbitfield clearMask) |
| osg::Geode * | createFullScreenQuad (const osg::Vec2 &size, const osg::Vec2 &uvStart, const osg::Vec2 &uvStop) |
| osg::Camera * | createHudCamera (int width, int height, GLbitfield clearMask, const char *name=nullptr) |
| double | computeUniformSplit (double nearDistance, double farDistance, unsigned int splitIndex, unsigned int numSplits) |
| double | computeLogarithmicSplit (double nearDistance, double farDistance, unsigned int splitIndex, unsigned int numSplits) |
| osg::Matrix | buildShadowBiasMatrix (bool useReverseZ, const osg::Vec2f &scaleFactor) const |
| CameraDescription | constructSplitLightCamera (const DtCurrentPassData &d, int split_index, bool farCascade=false) |
| void | updateCameras (const DtCurrentPassData &d) |
| void | getSplitCameraDistances (const DtCurrentPassData &d, int split_index, double &splitCamNear, double &splitCamFar) |
| void | setDirty (bool dirty) |
| void | frustumBoundingBoxLightViewSpace (const DtCurrentPassData &d, int split_index, const osg::Matrix &lightViewMatrix, double nearPlane, double farPlane, osg::Vec3d &minFrustum, osg::Vec3d &maxFrustum) |
| osg::Matrix | computeExactLightViewMatrix (const osg::Vec3d &targetPos, const DtCurrentPassData &d, double maxCasterDistance, osg::Vec3d *outLightPos=nullptr) const |
| void | computeFrustumCornerRays (const osg::Matrix &projectionMat, bool reverseZ, const osg::Matrix &inverseViewMat, osg::Vec3d outRays[4]) const |
| void | computeCascadeCenterAndRadius (const DtCurrentPassData &d, const osg::Vec3d rays[4], double nearPlane, double farPlane, osg::Vec3d &outCenter, double &outRadius) const |
| void | quantizeCascadeCenter (const osg::Vec3d &inCenter, double radius, int shadowMapSize, const osg::Vec3d &lightCamUp, const osg::Vec3d &lightCamSide, const osg::Vec3d &lightDirection, osg::Vec3d &outCenter) const |
| void | drawMulticastDetailsGui (const MulticastDebugInfo &info) |
Friends | |
| struct | DtCurrentPassData |
|
protected |
|
protected |
| makVrv::DtOsgShadowTechnique::DtOsgShadowTechnique | ( | DtDe & | de | ) |
CTOR.
| makVrv::DtOsgShadowTechnique::DtOsgShadowTechnique | ( | const DtOsgShadowTechnique & | es, |
| const osg::CopyOp & | copyop = osg::CopyOp::SHALLOW_COPY |
||
| ) |
DTOR.
|
protectedvirtual |
DTOR.
|
inlinevirtual |
Creates a new object of Type DtOsgShadowTechnique.
|
inlinevirtual |
Creates a new copy of DtOsgShadowTechnique object.
|
inlinevirtual |
Returns true if object is of the DtOsgShadowTechnique class. Otherwise, returns false.
|
inlinevirtual |
Returns the namespace string.
|
inlinevirtual |
Returns the class name string.
|
virtual |
Overrides the osgShadow::ShadowTechnique::init method.
|
virtual |
another init function
|
virtual |
Overrides the osgShadow::ShadowTechnique::update method.
|
virtual |
Overrides the osgShadow::ShadowTechnique::cull method.
|
virtual |
Overrides the osgShadow::ShadowTechnique::cleanSceneGraph method.
| void makVrv::DtOsgShadowTechnique::setChannelShadowState | ( | DtOsgChannel * | osgChannel, |
| bool | enable | ||
| ) |
Set the shadow mode for channels.
| bool makVrv::DtOsgShadowTechnique::getChannelShadowSettings | ( | DtOsgChannel * | osgChannel, |
| DtShadowSettingsObject ** | shadowSettingObject, | ||
| bool * | isPlanView | ||
| ) |
Gets the shadow settings for this channel.
| void makVrv::DtOsgShadowTechnique::setGlobalLight | ( | osg::LightSource * | light | ) |
Sets global light source.
| const osg::LightSource* makVrv::DtOsgShadowTechnique::getGlobalLight | ( | ) | const |
Gets global light source.
|
static |
| const osg::StateSet* makVrv::DtOsgShadowTechnique::mapCameraToStateSet | ( | const osg::Camera * | camera | ) | const |
returns shared state set uniform infor for this camera, may be null
|
overridevirtual |
override from osg::ShadowTechnique
|
overridevirtual |
override from osg::ShadowTechnique
Re-initialize perChannelData using the specified quality setting.
|
protectedvirtual |
Since the perChannelData can hold graphics objects we need to clear them in the main render thread. only call this from the main render thread.
|
protectedvirtual |
|
protectedvirtual |
|
protected |
Gets the number of taps for percentage closer filtering(PCF)
|
protected |
True if scene receives shadows from any light casting source. This is used to bypass some shadow work otherwise.
|
protectedvirtual |
Computes 8 world space frustum points: (near bl, br, tl, tr), (far bl, br, tl, tr). The frustum is computed from the given projection and view matrix. The points will be located in world space at the given near and far frustum plane distances.
| projectionMat | The projection matrix |
| reverseZ | Set to true if the projection matrix is using reverse Z |
| inverseViewMat | The inverse view matrix |
| nearPlane | the desired near plane distance to project the near points to |
| farPlane | the desired far plane distance to project the far points to |
| outFrustumPoints | should be an array of 8 osg::Vec3d to accept the computed points |
|
protectedvirtual |
Computes the main directional light vector for shadowing. Determines the direction of the primary light source (e.g., sun or moon) to be used for shadow calculations, based on the current view camera, global light, and environmental settings. Handles special cases such as geocentric coordinate systems, XR/sky-off modes, and developer overrides.
| viewCamera | The current view camera (may be nullptr). |
|
protectedvirtual |
Updates per-cascade split far distances and associated shader uniforms.
Computes and stores the far plane distance for each shadow cascade split based on the current camera and shadow settings. Also updates the corresponding shader uniforms for split distances in both normalized device coordinates and world space. This is used to ensure correct shadow mapping and filtering across all cascades.
| perChannelData | The per-channel shadow data to update. |
| shadowSettings | The current shadow settings object. |
| currentPassData | The current pass data containing camera and matrix information. |
|
protectedvirtual |
Updates shadow-related uniforms and filtering parameters for the current rendering pass.
This method updates all per-frame and per-pass shadow uniforms and filtering parameters required for correct shadow map rendering. It sets the light direction uniform, shadow ambient factor, and per-cascade filter sizes, and manages refresh logic for far cascades and shadow map updates. This function should be called once per frame for each channel before rendering shadow cascades.
| perChannelData | The per-channel shadow data to update. |
| shadowSettings | The current shadow settings object. |
| viewCamera | The current view camera. |
| currentPassData | The current pass data containing camera and light information. |
| bRefreshFarCascade | Output: set to true if the far cascade should be refreshed this frame. |
| unbindingIndex | Output: set to the last rendered split index for FBO unbinding. |
|
protectedvirtual |
Updates and renders a single shadow cascade split.
Sets up the shadow camera and state for the specified cascade split, updates its view/projection matrices, and triggers rendering for that split if needed. Handles both regular and far cascades, manages polygon offset, culling, and uniforms, and ensures only the required cascades are refreshed and rendered based on the current pass state and shadow settings.
| splitIndex | The index of the cascade split to update and render. |
| currentPassData | The current pass data containing camera, matrices, and state. |
| perChannelData | The per-channel shadow data for this rendering pass. |
| shadowSettings | The current shadow settings object. |
| viewCamera | The main view camera for this pass. |
| cv | The cull visitor used for scene traversal and rendering. |
| unbindingIndex | Output: set to the last rendered split index for FBO unbinding. |
| bRefreshFarCascade | True if the far cascade should be refreshed this frame. |
| series | Marker series for performance profiling. |
| cascades_rendered | Output: incremented for each cascade actually rendered. |
|
protectedvirtual |
Updates the shadow overlay GUI with the current per-channel data.
|
protectedvirtual |
Updates the shader uniforms related to OSG Earth integration for the current shadow pass.
|
private |
Gets the size of the far cascade.
|
private |
Gets camera shadow settings.
|
private |
Initializes per channel data.
|
private |
Sets up the viewport multicast mask and related shader functions for shadow rendering. Configures the mask and shader state for each shadow split camera, enabling or disabling viewport multicast acceleration based on the shadow settings.
|
private |
Initializes a shadow split camera for a specific cascade. Configures camera parameters, state set attributes, buffer attachments, and uniforms for each split in the shadow mapping cascade, including far cascade handling and visualization aids. Called during per-channel shadow data initialization. returns true on success, false on failure.
|
private |
Creates and configures a shadow split camera for a given cascade. This method initializes the camera object, sets up its state set, callbacks, buffer attachments, and other properties required for shadow map rendering. Returns the configured StateSet for further customization.
|
private |
Configures the OpenGL state attributes for a shadow split camera's StateSet. Sets up polygon offset, cull face, shade model, alpha test, blending, and related uniforms for the specified split in the shadow mapping cascade. This method centralizes all per-split StateSet configuration required for shadow map rendering.
|
private |
Initializes the shadow textures for perChannelData based on the shadow settings.
|
private |
Initializes the debug visualizer textures for perChannelData based on the shadow settings.
|
private |
Initializes the virtual program and shared stateset for perChannelData.
|
private |
Creates shader defines based on the shadow settings.
|
private |
|
private |
Creates a Program with a vertex and fragment shader.
|
private |
Creates 2d texture array.
|
private |
Creates a simple camera.
|
private |
Creates a full screen quad.
|
private |
Creates a hud camera with a full screen quad.
|
private |
Compute uniform split distance for specified cascade.
|
private |
Compute logarithm split distance for specified cascade.
|
private |
Builds the shadow bias matrix that transforms NDC coordinates to shadow map UV space.
Converts the [-1, 1] NDC range to [0, 1] UV range for shadow map lookups. A scale factor is provided for viewport multicast support. In the standard case (non-multicast), scaleFactor should be (1, 1) producing the identity bias. For reverse Z, the Z component is left unscaled (mapped to [0, 1] as-is). For standard depth, Z is remapped from [-1, 1] to [0, 1].
| useReverseZ | True if the projection uses a reverse Z buffer. |
| scaleFactor | XY scale applied to the UV mapping; use (1, 1) for the non-multicast path. |
|
private |
Compute logarithm split distance for specified cascade.
|
private |
|
private |
|
inlineprivate |
Sets dirty for shadow technique's to true or false.
|
private |
|
private |
Computes a stable light view matrix for the exact anti-flickering stabilization case.
Places the light camera at targetPos + (lightDirection * maxCasterDistance), then constructs a view matrix looking back toward the targetPos position along the light direction.
| targetPos | The target world-space position toward which the light camera is aimed. |
| d | The current pass data containing camera position, light direction, and up vector. |
| maxCasterDistance | Distance along the light direction to offset the light camera origin. |
| outLightPos | Optional output for the computed light position in world space. |
|
private |
Computes 4 normalized world-space ray directions for the camera frustum corners.
The rays are ordered: bottom-left, bottom-right, top-left, top-right. Each ray originates from the camera position and points toward the corresponding frustum corner. Scale by a plane distance to obtain a world-space frustum point.
| projectionMat | The camera projection matrix. |
| reverseZ | True if the projection uses reverse Z. |
| inverseViewMat | The camera inverse view matrix. |
| outRays | Output array of exactly 4 normalized direction vectors. |
|
private |
Computes the world-space center and bounding sphere radius for a cascade frustum slice.
Given the 4 pre-computed world-space corner rays from computeFrustumCornerRays, scales them to the cascade near and far planes to build 8 world-space frustum corners. The center is computed as the midpoint of the corners' axis-aligned bounding box (AABB), which gives a tighter fit than averaging vertices for asymmetric frusta (e.g. wide aspect ratios where near corners are tightly clustered and far corners are spread wide). The radius is then the maximum distance from that AABB center to any corner.
| d | Current pass data providing camera position and orientation. |
| rays | 4 normalized world-space frustum corner rays (bl, br, tl, tr). |
| nearPlane | Cascade near plane distance. |
| farPlane | Cascade far plane distance. |
| outCenter | Output world-space AABB center of the cascade frustum slice. |
| outRadius | Output bounding sphere radius from the AABB center to the farthest corner. |
|
private |
Snaps a world-space cascade center to the nearest shadow map texel boundary.
Quantizing the center in light-camera space prevents sub-texel shimmer as the main camera moves, because the shadow map coverage shifts only in whole-texel increments. The texel world-size is derived from the shadow map's world coverage (radius) and its pixel resolution. The center is decomposed along the light camera's up and side axes, each component snapped independently, then the center is reconstructed.
| inCenter | World-space cascade center to quantize. |
| radius | World-space half-coverage of the shadow map ortho projection. Typically the bounding sphere radius from computeCascadeCenterAndRadius. |
| shadowMapSize | Shadow map resolution in pixels (width == height assumed). |
| lightCamUp | Normalized up vector of the light camera (world space). |
| lightCamSide | Normalized side/right vector of the light camera (world space). |
| lightDirection | Normalized light direction vector (world space). |
| outCenter | Output quantized world-space center. |
|
private |
|
friend |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |