OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Ogre::CompositorShadowNode Class Reference

Shadow Nodes are special nodes (not to be confused with. More...

#include <OgreCompositorShadowNode.h>

+ Inheritance diagram for Ogre::CompositorShadowNode:
+ Collaboration diagram for Ogre::CompositorShadowNode:

Classes

struct  ShadowMapCamera
 

Public Member Functions

 CompositorShadowNode (IdType id, const CompositorShadowNodeDef *definition, CompositorWorkspace *workspace, RenderSystem *renderSys, const RenderTarget *finalTarget)
 
 ~CompositorShadowNode ()
 
const CompositorPassVec_getPasses () const
 
void _notifyCleared (void)
 Internal Use. More...
 
void _update (Camera *camera, const Camera *lodCamera, SceneManager *sceneManager)
 Renders into the shadow map, executes passes. More...
 
void _update (const Camera *lodCamera, SceneManager *sceneManager)
 Calling this function every frame will cause us to execute all our passes (ie. More...
 
bool areAllInputsConnected () const
 
void connectFinalRT (RenderTarget *rt, CompositorChannel::TextureVec &textures, size_t inChannelA)
 Connects (injects) an external RT into the given channel. More...
 
void connectTo (size_t outChannelA, CompositorNode *nodeB, size_t inChannelB)
 Connects this node (let's call it node 'A') to node 'B', mapping the output channel from A into the input channel from B. More...
 
void createPasses (void)
 Creates all passes based on our definition. More...
 
virtual void finalTargetResized (const RenderTarget *finalTarget)
 Called by CompositorManager2 when (i.e.) the RenderWindow was resized, thus our RTs that depend on their resolution need to be recreated. More...
 
const AxisAlignedBoxgetCastersBox (void) const
 mCastersBox More...
 
TexturePtr getDefinedTexture (IdString textureName, size_t mrtIndex) const
 Returns the texture pointer of a texture based on it's name & mrt index. More...
 
const CompositorNodeDefgetDefinition () const
 
bool getEnabled (void) const
 Returns if this instance is enabled. setEnabled. More...
 
IdType getId () const
 Get the unique id of this object. More...
 
const CompositorChannelVecgetInputChannel () const
 
const CompositorChannelVecgetLocalTextures () const
 
void getMinMaxDepthRange (const Frustum *shadowMapCamera, Real &outMin, Real &outMax) const
 Outputs the min & max depth range for the given camera. More...
 
IdString getName (void) const
 
size_t getNumShadowCastingLights (void) const
 The return value may change in the future, which happens when the number of lights changes to or from a value lower than the supported shadow casting lights by the definition. More...
 
const vector< Real >::type * getPssmSplits (size_t shadowMapIdx) const
 Returns a list of points with the limits of each PSSM split in projection space for the given shadow map index. More...
 
const LightClosestArraygetShadowCastingLights (void) const
 
CompositorWorkspacegetWorkspace (void)
 Returns our parent workspace. More...
 
const CompositorWorkspacegetWorkspace (void) const
 Returns our parent workspace. More...
 
void notifyDestroyed (const CompositorChannel &channel)
 Call this function when caller has destroyed a RenderTarget in which the callee may have a reference to that pointer, so that we can clean it up. More...
 
void notifyRecreated (const CompositorChannel &oldChannel, const CompositorChannel &newChannel)
 Call this function when you're replacing the textures from oldChannel with the ones in newChannel. More...
 
void operator delete (void *ptr)
 
void operator delete (void *ptr, void *)
 
void operator delete (void *ptr, const char *, int, const char *)
 
void operator delete[] (void *ptr)
 
void operator delete[] (void *ptr, const char *, int, const char *)
 
void * operator new (size_t sz, const char *file, int line, const char *func)
 operator new, with debug line info More...
 
void * operator new (size_t sz)
 
void * operator new (size_t sz, void *ptr)
 placement operator new More...
 
void * operator new[] (size_t sz, const char *file, int line, const char *func)
 array operator new, with debug line info More...
 
void * operator new[] (size_t sz)
 
bool operator() (const IdObject *left, const IdObject *right)
 
bool operator() (const IdObject &left, const IdObject &right)
 
virtual void postInitializePassScene (CompositorPassScene *pass)
 We derive so we can override the camera with ours. More...
 
void setEnabled (bool bEnabled)
 Enables or disables all instances of this node. More...
 
const LightListsetShadowMapsToPass (Renderable *rend, const Pass *pass, AutoParamDataSource *autoParamDataSource, size_t startLight)
 

Protected Member Functions

void _setId (IdType newId)
 In the rare case our derived class wants to override our Id (normally we don't want that, that's why it's private). More...
 
void disconnectOutput ()
 Disconnects this node's output from all nodes we send our textures to. More...
 
void routeOutputs ()
 Used to create/destroy MRTs. More...
 

Protected Attributes

CompositorNodeVec mConnectedNodes
 Nodes we're connected to. If we destroy our local textures, we need to inform them. More...
 
bool mEnabled
 
CompositorChannelVec mInTextures
 
CompositorChannelVec mLocalTextures
 
IdString mName
 Unique name across the same workspace. More...
 
size_t mNumConnectedInputs
 Must be <= mInTextures.size(). Tracks how many pointers are not null in mInTextures. More...
 
CompositorChannelVec mOutTextures
 Contains pointers that are ither in mInTextures or mLocalTextures. More...
 
CompositorPassVec mPasses
 
RenderSystemmRenderSystem
 
CompositorWorkspacemWorkspace
 

Private Types

typedef vector< bool >::type LightsBitSet
 
typedef vector
< ShadowMapCamera >::type 
ShadowMapCameraVec
 

Private Member Functions

void buildClosestLightList (Camera *newCamera, const Camera *lodCamera)
 Called by update to find out which lights are the ones closest to the given camera. More...
 
CompositorChannel createShadowTexture (const ShadowTextureDefinition &textureDef, const RenderTarget *finalTarget)
 

Private Attributes

LightsBitSet mAffectedLights
 
AxisAlignedBox mCastersBox
 Cached value. More...
 
LightList mCurrentLightList
 Changes with each call to setShadowMapsToPass. More...
 
CompositorShadowNodeDef const * mDefinition
 
Camera const * mLastCamera
 
size_t mLastFrame
 
ShadowMapCameraVec mShadowMapCameras
 One per shadow map (whether texture or atlas) More...
 
LightClosestArray mShadowMapCastingLights
 

Detailed Description

Shadow Nodes are special nodes (not to be confused with.

See also
CompositorNode) that are only used for rendering shadow maps. Normal Compositor Nodes can share or own a ShadowNode. The ShadowNode will render the scene enough times to fill all shadow maps so the main scene pass can use them.
ShadowNode are very flexible compared to Ogre 1.x; as they allow mixing multiple shadow camera setups for different lights.
Shadow Nodes derive from nodes so that they can be used as regular nodes
During a render with shadow mapping enabled, in theory we should render first the Shadow Node's pass, then render the regular scene. However in practice we need information that is calculated during the reulgar scene render, namely: An AABB enclosing all visible objects (calculated in cullFrusum) An AABB enclosing all visible objects that receive shadows (also in cullFrusum) Unfortunately calculating them twice (first for shadow map, then for the regular pass) is very expensive so the smart thing to do is to reuse such data.

As a result, Ogre divides the rendering into two stages: The culling phase (01), and the rendering phase (02). Ogre first calls the culling phase 01 of the regular pass, and the resulting output is: An array(s) containing all visible/culled objects ( SceneManager::mVisibleObjects) The 2 aabbs we need. ( SceneManager::mVisibleObjsPerRenderQueue) The next step, before entering rendering phase 02, is to update the shadow node (which implies entering both its cull & render phases); only then, enter rendering phase 02.

There is a caveat: When entering shadow node's cull phase 01, the array of visible objects is overwritten, but we'll still need it for phase 02. As a result, we save the content of the array before updating the shadow node, and restore it afterwards.

To summarize: a normal rendering flow with shadow map looks like this: normal->_cullPhase01(); saveCulledObjects( normal->getSceneManager() ); shadowNode->setupShadowCamera( normal->getVisibleBoundsInfo() ); shadowNode->_cullPhase01(); shadowNode->_renderPhase02(); restoreCulledObjects( normal->getSceneManager() ); normal->_renderPhase02();

Another issues that has to take care is that if shadow map will render render queues 0 to 4 and the normal pass only renders RQs from 0 to 2, then unfortunately we'll need to calculate the bounds information of RQs 3 & 4.

It may sound complicated, but it's just the old rendering sequence divided into stages. It's much more elegant than Ogre 1.x, which just interrupted the normal rendering sequence with lots of branches and called itself recursively to render the shadow maps. This separation also provides a way to isolate & encapsulate systems (SceneManager now has no idea of how to take care of shadow map rendering)

On forward lighting passes, shadow mapping is handled in the following way: 1) Build a list of all lights visible by all cameras (SceneManager does this) 2) Traverse the list to get the closest lights to the current camera. These lights will cast shadows. 3) Build a list of the closest lights for each object (SceneManager does this) 4) Traverse this list and find those that are actually casting a shadow 5) Send to the GPU & engine the list in step 4, but shadow casting lights are put first, then sorted by proximity. See the comments inside the function setShadowMapsToPass for more information.
Author
Matias N. Goldberg
Version
1.0

Definition at line 112 of file OgreCompositorShadowNode.h.

Member Typedef Documentation

typedef vector<bool>::type Ogre::CompositorShadowNode::LightsBitSet
private

Definition at line 140 of file OgreCompositorShadowNode.h.

Constructor & Destructor Documentation

Ogre::CompositorShadowNode::CompositorShadowNode ( IdType  id,
const CompositorShadowNodeDef definition,
CompositorWorkspace workspace,
RenderSystem renderSys,
const RenderTarget finalTarget 
)
Ogre::CompositorShadowNode::~CompositorShadowNode ( )

Member Function Documentation

const CompositorPassVec& Ogre::CompositorNode::_getPasses ( ) const
inlineinherited

Definition at line 214 of file OgreCompositorNode.h.

void Ogre::CompositorNode::_notifyCleared ( void  )
inherited

Internal Use.

Called when connections are all being zero'ed. We rely our caller is doing this to all nodes, hence we do not notify our nodes. Failing to clear them too may leave dangling pointers or graphical glitches

Remarks
Destroys all of our passes.
void Ogre::IdObject::_setId ( IdType  newId)
inlineprotectedinherited

In the rare case our derived class wants to override our Id (normally we don't want that, that's why it's private).

Definition at line 63 of file OgreId.h.

void Ogre::CompositorShadowNode::_update ( Camera camera,
const Camera lodCamera,
SceneManager sceneManager 
)

Renders into the shadow map, executes passes.

Parameters
cameraCamera used to calculate our shadow camera (in case of directional lights).
void Ogre::CompositorNode::_update ( const Camera lodCamera,
SceneManager sceneManager 
)
inherited

Calling this function every frame will cause us to execute all our passes (ie.

render)

Parameters
lodCameraLOD Camera to be used by our passes. Pointer can be null, and note however passes can ignore this hint and use their own camera pointer for LOD (this parameter is mostly used for syncing shadow mapping).
bool Ogre::CompositorNode::areAllInputsConnected ( ) const
inlineinherited

Definition at line 185 of file OgreCompositorNode.h.

void Ogre::CompositorShadowNode::buildClosestLightList ( Camera newCamera,
const Camera lodCamera 
)
private

Called by update to find out which lights are the ones closest to the given camera.

Early outs if we've already calculated our stuff for that camera in a previous call. Also updates internals lists for easy look up of lights <-> shadow maps

Parameters
newCameraUser camera to base our shadow map cameras from.
void Ogre::CompositorNode::connectFinalRT ( RenderTarget rt,
CompositorChannel::TextureVec textures,
size_t  inChannelA 
)
inherited

Connects (injects) an external RT into the given channel.

Usually used for the "connect_output" directive for the RenderWindow.

Parameters
rtThe RenderTarget.
texturesThe Textures associated with the RT. Can be empty (eg. RenderWindow) but could cause crashes/exceptions if tried to use in PASS_QUAD passes.
inChannelAIn which channel number to inject to.
void Ogre::CompositorNode::connectTo ( size_t  outChannelA,
CompositorNode nodeB,
size_t  inChannelB 
)
inherited

Connects this node (let's call it node 'A') to node 'B', mapping the output channel from A into the input channel from B.

Parameters
outChannelAOutput to use from node A.
inChannelBInput to connect the output from A.
void Ogre::CompositorNode::createPasses ( void  )
inherited

Creates all passes based on our definition.

Remarks
Call this function after connecting all channels (at least our input) otherwise we may bind null pointer RTs to the passes (and then crash) connectTo and
See also
connectFinalRT
CompositorChannel Ogre::CompositorShadowNode::createShadowTexture ( const ShadowTextureDefinition textureDef,
const RenderTarget finalTarget 
)
private
void Ogre::CompositorNode::disconnectOutput ( )
protectedinherited

Disconnects this node's output from all nodes we send our textures to.

We only disconnect local textures.

Remarks
Textures that we got from our input channel and then pass it to the output channel are left untouched. This allows for some node to be plugged back & forth without making much mess and leaving everything else working.
virtual void Ogre::CompositorShadowNode::finalTargetResized ( const RenderTarget finalTarget)
virtual

Called by CompositorManager2 when (i.e.) the RenderWindow was resized, thus our RTs that depend on their resolution need to be recreated.

Remarks
We inform all connected nodes and passes related to us of RenderTargets/Textures that may have been recreated (pointers could become danlging otherwise).
Parameters
finalTargetThe Final Target (i.e. RenderWindow) from which we'll base our local textures' resolution.

Reimplemented from Ogre::CompositorNode.

const AxisAlignedBox& Ogre::CompositorShadowNode::getCastersBox ( void  ) const
inline

mCastersBox

Definition at line 178 of file OgreCompositorShadowNode.h.

TexturePtr Ogre::CompositorNode::getDefinedTexture ( IdString  textureName,
size_t  mrtIndex 
) const
inherited

Returns the texture pointer of a texture based on it's name & mrt index.

Remarks
The texture name must have been registered with CompositorNodeDef::addTextureSourceName
Parameters
textureNameThe name of the texture. This name may only be valid at node scope. It can refer to an input texture, a local texture, or a global one. If the global texture wasn't registered with addTextureSourceName, it will fail.
mrtIndexThe MRT (Multiple Render Target) index. If the texture isn't MRT or has less RTs than the index, it returns the highest valid index found.
Returns
Null if not found (or global texture not registered). The texture otherwise
const CompositorNodeDef* Ogre::CompositorNode::getDefinition ( ) const
inlineinherited

Definition at line 146 of file OgreCompositorNode.h.

bool Ogre::CompositorNode::getEnabled ( void  ) const
inlineinherited

Returns if this instance is enabled. setEnabled.

Definition at line 161 of file OgreCompositorNode.h.

IdType Ogre::IdObject::getId ( ) const
inlineinherited

Get the unique id of this object.

Definition at line 74 of file OgreId.h.

const CompositorChannelVec& Ogre::CompositorNode::getInputChannel ( ) const
inlineinherited

Definition at line 186 of file OgreCompositorNode.h.

const CompositorChannelVec& Ogre::CompositorNode::getLocalTextures ( ) const
inlineinherited

Definition at line 187 of file OgreCompositorNode.h.

void Ogre::CompositorShadowNode::getMinMaxDepthRange ( const Frustum shadowMapCamera,
Real outMin,
Real outMax 
) const

Outputs the min & max depth range for the given camera.

0 & 100000 if camera not found

Remarks
Performs linear search O(N)
IdString Ogre::CompositorNode::getName ( void  ) const
inlineinherited

Definition at line 145 of file OgreCompositorNode.h.

size_t Ogre::CompositorShadowNode::getNumShadowCastingLights ( void  ) const
inline

The return value may change in the future, which happens when the number of lights changes to or from a value lower than the supported shadow casting lights by the definition.

Definition at line 202 of file OgreCompositorShadowNode.h.

const vector<Real>::type* Ogre::CompositorShadowNode::getPssmSplits ( size_t  shadowMapIdx) const

Returns a list of points with the limits of each PSSM split in projection space for the given shadow map index.

Remarks
If shadow map 0, 1 & 2 use light 0 with different splits, the return value should be the same for all of them.
Returns
An array with the split points. The number of elements is N+1 where N is the number of splits for that shadow map. Returns null if shadowMapIdx is out of bounds, or is not a PSSM technique.
const LightClosestArray& Ogre::CompositorShadowNode::getShadowCastingLights ( void  ) const
inline

Definition at line 203 of file OgreCompositorShadowNode.h.

CompositorWorkspace* Ogre::CompositorNode::getWorkspace ( void  )
inlineinherited

Returns our parent workspace.

Definition at line 260 of file OgreCompositorNode.h.

const CompositorWorkspace* Ogre::CompositorNode::getWorkspace ( void  ) const
inlineinherited

Returns our parent workspace.

Definition at line 263 of file OgreCompositorNode.h.

void Ogre::CompositorNode::notifyDestroyed ( const CompositorChannel channel)
inherited

Call this function when caller has destroyed a RenderTarget in which the callee may have a reference to that pointer, so that we can clean it up.

Parameters
channelChannel containing the pointer about to be destroyed (must still be valid)
void Ogre::CompositorNode::notifyRecreated ( const CompositorChannel oldChannel,
const CompositorChannel newChannel 
)
inherited

Call this function when you're replacing the textures from oldChannel with the ones in newChannel.

Useful when recreating textures (i.e. resolution changed)

Parameters
oldChannelThe old textures that are going to be removed. Pointers in it must be still valid
newChannelThe new replacement textures
template<class Alloc >
void Ogre::AllocatedObject< Alloc >::operator delete ( void *  ptr)
inlineinherited

Definition at line 96 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void Ogre::AllocatedObject< Alloc >::operator delete ( void *  ptr,
void *   
)
inlineinherited

Definition at line 102 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void Ogre::AllocatedObject< Alloc >::operator delete ( void *  ptr,
const char *  ,
int  ,
const char *   
)
inlineinherited

Definition at line 108 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void Ogre::AllocatedObject< Alloc >::operator delete[] ( void *  ptr)
inlineinherited

Definition at line 113 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void Ogre::AllocatedObject< Alloc >::operator delete[] ( void *  ptr,
const char *  ,
int  ,
const char *   
)
inlineinherited

Definition at line 119 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void* Ogre::AllocatedObject< Alloc >::operator new ( size_t  sz,
const char *  file,
int  line,
const char *  func 
)
inlineinherited

operator new, with debug line info

Definition at line 68 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void* Ogre::AllocatedObject< Alloc >::operator new ( size_t  sz)
inlineinherited

Definition at line 73 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void* Ogre::AllocatedObject< Alloc >::operator new ( size_t  sz,
void *  ptr 
)
inlineinherited

placement operator new

Definition at line 79 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void* Ogre::AllocatedObject< Alloc >::operator new[] ( size_t  sz,
const char *  file,
int  line,
const char *  func 
)
inlineinherited

array operator new, with debug line info

Definition at line 86 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void* Ogre::AllocatedObject< Alloc >::operator new[] ( size_t  sz)
inlineinherited

Definition at line 91 of file OgreMemoryAllocatedObject.h.

bool Ogre::IdObject::operator() ( const IdObject left,
const IdObject right 
)
inlineinherited

Definition at line 76 of file OgreId.h.

References Ogre::IdObject::mId.

bool Ogre::IdObject::operator() ( const IdObject left,
const IdObject right 
)
inlineinherited

Definition at line 81 of file OgreId.h.

References Ogre::IdObject::mId.

virtual void Ogre::CompositorShadowNode::postInitializePassScene ( CompositorPassScene pass)
virtual

We derive so we can override the camera with ours.

Reimplemented from Ogre::CompositorNode.

void Ogre::CompositorNode::routeOutputs ( )
protectedinherited

Used to create/destroy MRTs.

Fills mOutTextures with the pointers from mInTextures & mLocalTextures according to CompositorNodeDef::mOutChannelMapping. Call this immediately after modifying mInTextures or mLocalTextures

void Ogre::CompositorNode::setEnabled ( bool  bEnabled)
inlineinherited

Enables or disables all instances of this node.

Remarks
Note that we just won't execute our passes. It's your job to change the channel connections accordingly if you have to. A disabled node won't complain when its connections are incomplete in a workspace.
This function is useful frequently toggling a compositor effect without having to recreate any API resource (which often would involve stalls).

Definition at line 158 of file OgreCompositorNode.h.

const LightList* Ogre::CompositorShadowNode::setShadowMapsToPass ( Renderable rend,
const Pass pass,
AutoParamDataSource autoParamDataSource,
size_t  startLight 
)

Member Data Documentation

LightsBitSet Ogre::CompositorShadowNode::mAffectedLights
private

Definition at line 141 of file OgreCompositorShadowNode.h.

AxisAlignedBox Ogre::CompositorShadowNode::mCastersBox
private

Cached value.

Contains the aabb of all caster-only objects (filtered by camera's visibility flags) from the minimum RQ used by our shadow render passes, to the maximum RQ used. The tighter the box, the higher the shadow quality.

Definition at line 138 of file OgreCompositorShadowNode.h.

CompositorNodeVec Ogre::CompositorNode::mConnectedNodes
protectedinherited

Nodes we're connected to. If we destroy our local textures, we need to inform them.

Definition at line 108 of file OgreCompositorNode.h.

LightList Ogre::CompositorShadowNode::mCurrentLightList
private

Changes with each call to setShadowMapsToPass.

Definition at line 144 of file OgreCompositorShadowNode.h.

CompositorShadowNodeDef const* Ogre::CompositorShadowNode::mDefinition
private

Definition at line 114 of file OgreCompositorShadowNode.h.

bool Ogre::CompositorNode::mEnabled
protectedinherited

Definition at line 95 of file OgreCompositorNode.h.

CompositorChannelVec Ogre::CompositorNode::mInTextures
protectedinherited

Definition at line 99 of file OgreCompositorNode.h.

Camera const* Ogre::CompositorShadowNode::mLastCamera
private

Definition at line 129 of file OgreCompositorShadowNode.h.

size_t Ogre::CompositorShadowNode::mLastFrame
private

Definition at line 130 of file OgreCompositorShadowNode.h.

CompositorChannelVec Ogre::CompositorNode::mLocalTextures
protectedinherited

Definition at line 100 of file OgreCompositorNode.h.

IdString Ogre::CompositorNode::mName
protectedinherited

Unique name across the same workspace.

Definition at line 94 of file OgreCompositorNode.h.

size_t Ogre::CompositorNode::mNumConnectedInputs
protectedinherited

Must be <= mInTextures.size(). Tracks how many pointers are not null in mInTextures.

Definition at line 98 of file OgreCompositorNode.h.

CompositorChannelVec Ogre::CompositorNode::mOutTextures
protectedinherited

Contains pointers that are ither in mInTextures or mLocalTextures.

Definition at line 103 of file OgreCompositorNode.h.

CompositorPassVec Ogre::CompositorNode::mPasses
protectedinherited

Definition at line 105 of file OgreCompositorNode.h.

RenderSystem* Ogre::CompositorNode::mRenderSystem
protectedinherited

Definition at line 112 of file OgreCompositorNode.h.

ShadowMapCameraVec Ogre::CompositorShadowNode::mShadowMapCameras
private

One per shadow map (whether texture or atlas)

Definition at line 127 of file OgreCompositorShadowNode.h.

LightClosestArray Ogre::CompositorShadowNode::mShadowMapCastingLights
private

Definition at line 131 of file OgreCompositorShadowNode.h.

CompositorWorkspace* Ogre::CompositorNode::mWorkspace
protectedinherited

Definition at line 110 of file OgreCompositorNode.h.


The documentation for this class was generated from the following file: