18 #include <osgEarth/VirtualProgram>
20 #include <osgShadow/ShadowTechnique>
22 #include <osg/StateSet>
24 #include <osg/PolygonOffset>
25 #include <osg/FrameBufferObject>
26 #include <osg/Uniform>
27 #include <osg/LightSource>
28 #include <osg/RenderInfo>
32 #include <osg/MatrixTransform>
33 #include <osg/Program>
34 #include <osg/Texture2D>
35 #include <osg/Texture2DArray>
37 #include <osg/Geometry>
45 #include <tbb/mutex.h>
54 class DtOsgShaderFilesCache;
55 class DtShadowSettingsObject;
56 class DtOsgShadowTechnique;
57 class DtShadowTweakables;
58 class DtSkyObjectManager;
59 class TextureApplyAttribute;
62 class DtPerChannelData;
63 struct DtCurrentPassData;
110 virtual const char*
className()
const {
return "DtOsgShadowTechnique"; }
116 virtual void postConstructionInit();
119 virtual void update(osg::NodeVisitor& nv);
122 virtual void cull(osgUtil::CullVisitor& cv);
125 virtual void cleanSceneGraph();
128 void setChannelShadowState(
DtOsgChannel* osgChannel,
bool enable);
134 void setGlobalLight(osg::LightSource* light);
137 const osg::LightSource* getGlobalLight()
const;
139 static const std::string& shadowCameraPrefixString();
142 const osg::StateSet * mapCameraToStateSet(
const osg::Camera* camera)
const;
145 virtual void resizeGLObjectBuffers(
unsigned int maxSize)
override;
148 virtual void releaseGLObjects(osg::State* = 0)
const override;
156 virtual void reInitialize(
unsigned int quality);
160 virtual void cleanupOldPerChannelData();
162 virtual bool configureShadowTraversalNodeMask(
bool traverseEntities,
bool traverseProps,
bool traverseTerrain);
164 virtual void slot_refresh_maps();
182 virtual void computeFrustumPoints(
const osg::Matrix& projectionMat,
bool reverseZ,
const osg::Matrix& inverseViewMat,
183 double nearPlane,
double farPlane, osg::Vec3d* outFrustumPoints);
191 virtual const osg::Vec3 computeLightDirection(osg::Camera* viewCamera)
const;
203 virtual void updateSplitDistancesAndUniforms(
DtPerChannelData* perChannelData,
220 virtual void updateShadowUniformsAndFilters(
DtPerChannelData* perChannelData,
222 bool& bRefreshFarCascade,
unsigned int& unbindingIndex);
241 virtual void updateAndRenderCascade(
unsigned int splitIndex,
DtCurrentPassData& currentPassData,
243 const osg::Camera* viewCamera, osgUtil::CullVisitor& cv,
unsigned int& unbindingIndex,
251 virtual void updateOsgEarthUniforms(
const osg::Camera* viewCamera, osg::Camera* cascadeCamera);
256 int farShadowMapCascadeSize()
const;
259 bool getCameraSettings(osg::Camera* viewCamera,
DtPerChannelData** perChannelData,
295 void setupShadowSplitStateSet(osg::StateSet* cameraStateSet,
DtCascadeData& cascade,
314 void createPreProcessorDefines(std::string& defines, osg::StateSet& stateSet,
DtShadowSettingsObject* shadowSettings);
316 void triggerExternalModuleShaderRefresh();
319 osg::Program* getProgramFromFile(
const std::string& szVertexShader,
const std::string& szFragmentShader);
322 osg::Texture2DArray* createTexture2DArray(
int width,
int height,
int depth,
GLenum internalFormat,
GLenum sourceFormat,
323 GLenum sourceType,
bool shadowComparisonMode, osg::Texture2DArray::FilterMode minFilter = osg::Texture2DArray::NEAREST,
324 osg::Texture2DArray::FilterMode magFilter = osg::Texture2DArray::NEAREST);
327 osg::Camera* createCamera(
int width,
int height, GLbitfield clearMask);
330 osg::Geode* createFullScreenQuad(
const osg::Vec2&
size,
const osg::Vec2& uvStart,
const osg::Vec2& uvStop);
333 osg::Camera* createHudCamera(
int width,
int height, GLbitfield clearMask,
const char * name =
nullptr);
336 double computeUniformSplit(
double nearDistance,
double farDistance,
unsigned int splitIndex,
unsigned int numSplits);
339 double computeLogarithmicSplit(
double nearDistance,
double farDistance,
unsigned int splitIndex,
unsigned int numSplits);
352 osg::Matrix buildShadowBiasMatrix(
bool useReverseZ,
const osg::Vec2f& scaleFactor)
const;
365 void getSplitCameraDistances(
const DtCurrentPassData& d,
int split_index,
double& splitCamNear,
double& splitCamFar);
371 void frustumBoundingBoxLightViewSpace(
const DtCurrentPassData& d,
int split_index,
372 const osg::Matrix& lightViewMatrix,
double nearPlane,
double farPlane, osg::Vec3d& minFrustum, osg::Vec3d& maxFrustum);
383 osg::Matrix computeExactLightViewMatrix(
const osg::Vec3d& targetPos,
const DtCurrentPassData& d,
384 double maxCasterDistance, osg::Vec3d* outLightPos =
nullptr)
const;
396 void computeFrustumCornerRays(
const osg::Matrix& projectionMat,
bool reverseZ,
397 const osg::Matrix& inverseViewMat, osg::Vec3d outRays[4])
const;
414 void computeCascadeCenterAndRadius(
const DtCurrentPassData& d,
const osg::Vec3d rays[4],
double nearPlane,
415 double farPlane, osg::Vec3d& outCenter,
double& outRadius)
const;
433 void quantizeCascadeCenter(
const osg::Vec3d& inCenter,
double radius,
int shadowMapSize,
434 const osg::Vec3d& lightCamUp,
const osg::Vec3d& lightCamSide,
const osg::Vec3d& lightDirection,
435 osg::Vec3d& outCenter)
const;
443 int myShadowMapSize = 0;
447 float mySegmentSizeX = 0.f;
448 float mySegmentSizeY = 0.f;
DT_DLL_EXAMPLESCENEROOTPLUGIN void init(DtDe &anIG)
static const std::string myShadowCameraPrefixString
Definition: DtOsgShadowTechnique.h:479
void setDirty(bool dirty)
Sets dirty for shadow technique's to true or false.
Definition: DtOsgShadowTechnique.h:368
osg::Vec2f myPixelFrustumSize
Definition: DtOsgShadowTechnique.h:452
The DtOsgRenderer is the component responsible for rendering 3D images onto the screen via OpenSceneG...
Definition: DtOsgRenderer.h:92
Definition: DtPerChannelData.h:102
Definition: DtShadowSettingsObject.h:24
osg::Vec3d myFrustumMax
Definition: DtOsgShadowTechnique.h:442
Definition: DtOsgShadowTechnique.h:354
Holds all state for a single shadow cascade split.
Definition: DtPerChannelData.h:42
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
PerChannelDataMap myPerChannelDataMap
Definition: DtOsgShadowTechnique.h:468
boost::signalslib::connection myTerrainPatchAddedConnection
Definition: DtOsgShadowTechnique.h:492
Creates a series/span line in the CV tool.
Definition: DtConcurrencyViewerMacros.h:27
voidpf void uLong size
Definition: ioapi.h:39
Definition: DtSkyObjectManager.h:30
Contains the DtOsgTextureApplyAttribute class.
osg::Vec2f myMaxViewportDims
Definition: DtOsgShadowTechnique.h:499
DtDe & myDe
Definition: DtOsgShadowTechnique.h:477
osg::Matrix myProjectionMatrix
Definition: DtOsgShadowTechnique.h:357
This class provides the OSG-specific implementation of a DtChannel.
Definition: DtOsgChannel.h:58
class for holding loader shader files, so that they are not repeatedly loaded from disk ...
Definition: DtOsgShaderFilesCache.h:27
osg::ref_ptr< osg::Uniform > myReceiveShadowsUniform
Definition: DtOsgShadowTechnique.h:473
virtual const char * libraryName() const
Returns the namespace string.
Definition: DtOsgShadowTechnique.h:107
bool myMulticastIsSupported
Definition: DtOsgShadowTechnique.h:487
Definition: DtOsgShadowTechnique.h:445
std::vector< osg::ref_ptr< DtPerChannelData > > PerChannelDataVector
Definition: DtOsgShadowTechnique.h:466
virtual osg::Object * cloneType() const
Creates a new object of Type DtOsgShadowTechnique.
Definition: DtOsgShadowTechnique.h:98
Definition: DtCurrentPassData.h:29
osg::Matrix myViewMatrix
Definition: DtOsgShadowTechnique.h:356
DtShadowTweakables * myShadowUI
Definition: DtOsgShadowTechnique.h:475
Definition: DtShadowTweakables.h:21
std::vector< osg::ref_ptr< osg::Camera > > myDeferredDeleteCamera
Definition: DtOsgShadowTechnique.h:482
std::vector< CascadeEntry > myCascades
Definition: DtOsgShadowTechnique.h:455
float myAnisotropy
Definition: DtOsgShadowTechnique.h:503
PerChannelDataVector myPerChannelDataDeleteList
Definition: DtOsgShadowTechnique.h:469
Implements cascaded shadow mapping (CSM) for the VRV rendering pipeline.
Definition: DtOsgShadowTechnique.h:87
DtSkyObjectManager & mySkyObjectManager
Definition: DtOsgShadowTechnique.h:490
unsigned int GLenum
Definition: DtGlTextureBufferObject.h:19
osg::Vec2f myScaleFactor
Definition: DtOsgShadowTechnique.h:449
virtual bool isSameKindAs(const osg::Object *obj) const
Returns true if object is of the DtOsgShadowTechnique class. Otherwise, returns false.
Definition: DtOsgShadowTechnique.h:104
osg::Vec2f myFrustumSegmentSizeRatio
Definition: DtOsgShadowTechnique.h:451
osg::Vec2f myPixelOffsetTopLeft
Definition: DtOsgShadowTechnique.h:453
std::map< const osg::Camera *, osg::ref_ptr< DtPerChannelData > > PerChannelDataMap
Definition: DtOsgShadowTechnique.h:465
Contains DLL export macros.
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:76
Stores debug information for multicast rendering, which can be visualized in the shadow overlay GUI...
Definition: DtOsgShadowTechnique.h:438
osg::Matrix myTextureViewProjectionMatrix
Definition: DtOsgShadowTechnique.h:358
osg::Vec3d myFrustumMin
Definition: DtOsgShadowTechnique.h:441
osg::Vec2f myOffsetSegmentSizeRatio
Definition: DtOsgShadowTechnique.h:450
DtOsgShaderFilesCache & myShaderFilesCache
Definition: DtOsgShadowTechnique.h:495
bool myShadingRateIsSupported
Definition: DtOsgShadowTechnique.h:488
osg::ref_ptr< osg::LightSource > myGlobalLight
Definition: DtOsgShadowTechnique.h:471
osg::ref_ptr< osg::Uniform > myLightDirectionUniform
Definition: DtOsgShadowTechnique.h:472
tbb::mutex myDeferredCameraDeletionMutex
Definition: DtOsgShadowTechnique.h:485
boost::signalslib::connection myTerrainPatchDeletedConnection
Definition: DtOsgShadowTechnique.h:493
virtual osg::Object * clone(const osg::CopyOp ©op) const
Creates a new copy of DtOsgShadowTechnique object.
Definition: DtOsgShadowTechnique.h:101
osg::Vec3d myFrustumMidpoint
Definition: DtOsgShadowTechnique.h:440
virtual const char * className() const
Returns the class name string.
Definition: DtOsgShadowTechnique.h:110