Hello Michael,

On 12/12/2011 09:59 AM, Michael Raab wrote:
currently I'm playing around with shadows in OpenSG. At the moment I have 2 
questions:

1.) We're using a sky sphere to simulate environment information. That sky 
shouldn't neither produce nor receive any shadow when being rendered using a 
ShadowViewport. The questions is, how can I completely exclude a node/sub tree 
from the shadow calculations. At the moment I push the root node of the 
environment into the excludenodes list of the shadowviewport. The result looks 
better than without doing this, but the shading of sky sphere has changed 
(received some dark artefacts) a litte bit...

exclude nodes are meant to exclude objects from casting or receiving shadows. What shadow mode are you using? What artefacts are you getting? Alternatively, you could use a regular viewport to render the non-shadow part first, then the shadow viewport with a PassiveBackground on top of that.

2.) Looking at the code for excluding nodes from shadow calculations, this 
seems to be achieved by temporarily setting these nodes inactive. After the 
calculation all exclude node are set to active, independent of their activation 
state before shadow calc. I would propose saving the node activation state 
before disabling and restoring the saved state afterwards.

not quite, the previous state of the exclude nodes is stored, but it would be better to store the complete trav mask. Attached patch fixes that, committed.

        Cheers,
                Carsten
Index: Source/Experimental/ShadowViewport/OSGDitherShadowMap.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/Experimental/ShadowViewport/OSGDitherShadowMap.cpp,v
retrieving revision 1.43
diff -u -p -r1.43 OSGDitherShadowMap.cpp
--- Source/Experimental/ShadowViewport/OSGDitherShadowMap.cpp	19 Nov 2009 01:28:33 -0000	1.43
+++ Source/Experimental/ShadowViewport/OSGDitherShadowMap.cpp	12 Dec 2011 23:48:51 -0000
@@ -1145,7 +1145,7 @@ void DitherShadowMap::createShadowMaps(R
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            exnode->setActive(false);
+            exnode->setTravMask(0);
     }
 
     for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
@@ -1361,8 +1361,7 @@ void DitherShadowMap::createShadowMaps(R
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            if(_shadowVP->_excludeNodeActive[i])
-                exnode->setActive(true);
+            exnode->setTravMask(_shadowVP->_excludeNodeTravMask[i]);
     }
 
     // enable all lights.
@@ -1416,7 +1415,7 @@ void DitherShadowMap::createShadowMapsFB
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            exnode->setActive(false);
+            exnode->setTravMask(0);
     }
 
     for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
@@ -1567,8 +1566,7 @@ void DitherShadowMap::createShadowMapsFB
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            if(_shadowVP->_excludeNodeActive[i])
-                exnode->setActive(true);
+            exnode->setTravMask(_shadowVP->_excludeNodeTravMask[i]);
     }
 
     // enable all lights.
Index: Source/Experimental/ShadowViewport/OSGPCFShadowMap.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/Experimental/ShadowViewport/OSGPCFShadowMap.cpp,v
retrieving revision 1.58
diff -u -p -r1.58 OSGPCFShadowMap.cpp
--- Source/Experimental/ShadowViewport/OSGPCFShadowMap.cpp	19 Nov 2009 01:28:33 -0000	1.58
+++ Source/Experimental/ShadowViewport/OSGPCFShadowMap.cpp	12 Dec 2011 23:48:51 -0000
@@ -3173,7 +3173,7 @@ void PCFShadowMap::createShadowMaps(Rend
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            exnode->setActive(false);
+            exnode->setTravMask(0);
     }
 
     for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
@@ -3392,8 +3392,7 @@ void PCFShadowMap::createShadowMaps(Rend
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            if(_shadowVP->_excludeNodeActive[i])
-                exnode->setActive(true);
+            exnode->setTravMask(_shadowVP->_excludeNodeTravMask[i]);
     }
 
     // enable all lights.
@@ -3446,7 +3445,7 @@ void PCFShadowMap::createShadowMapsFBO(R
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            exnode->setActive(false);
+            exnode->setTravMask(0);
     }
 
     for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
@@ -3597,8 +3596,7 @@ void PCFShadowMap::createShadowMapsFBO(R
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            if(_shadowVP->_excludeNodeActive[i])
-                exnode->setActive(true);
+            exnode->setTravMask(_shadowVP->_excludeNodeTravMask[i]);
     }
 
     // enable all lights.
Index: Source/Experimental/ShadowViewport/OSGPCSSShadowMap.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/Experimental/ShadowViewport/OSGPCSSShadowMap.cpp,v
retrieving revision 1.37
diff -u -p -r1.37 OSGPCSSShadowMap.cpp
--- Source/Experimental/ShadowViewport/OSGPCSSShadowMap.cpp	19 Nov 2009 01:28:33 -0000	1.37
+++ Source/Experimental/ShadowViewport/OSGPCSSShadowMap.cpp	12 Dec 2011 23:48:51 -0000
@@ -693,7 +693,7 @@ void PCSSShadowMap::createShadowMaps(Ren
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            exnode->setActive(false);
+            exnode->setTravMask(0);
     }
 
     for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
@@ -786,8 +786,7 @@ void PCSSShadowMap::createShadowMaps(Ren
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            if(_shadowVP->_excludeNodeActive[i])
-                exnode->setActive(true);
+            exnode->setTravMask(_shadowVP->_excludeNodeTravMask[i]);
     }
     //-------Restoring old states of Window and Viewport----------
 
@@ -838,7 +837,7 @@ void PCSSShadowMap::createShadowMapsFBO(
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            exnode->setActive(false);
+            exnode->setTravMask(0);
     }
 
     for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
@@ -898,8 +897,7 @@ void PCSSShadowMap::createShadowMapsFBO(
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            if(_shadowVP->_excludeNodeActive[i])
-                exnode->setActive(true);
+            exnode->setTravMask(_shadowVP->_excludeNodeTravMask[i]);
     }
 
     _shadowVP->setVPSize(0, 0, oldWidth - 1, oldHeight - 1);
Index: Source/Experimental/ShadowViewport/OSGPerspectiveShadowMap.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/Experimental/ShadowViewport/OSGPerspectiveShadowMap.cpp,v
retrieving revision 1.46
diff -u -p -r1.46 OSGPerspectiveShadowMap.cpp
--- Source/Experimental/ShadowViewport/OSGPerspectiveShadowMap.cpp	19 Nov 2009 01:28:33 -0000	1.46
+++ Source/Experimental/ShadowViewport/OSGPerspectiveShadowMap.cpp	12 Dec 2011 23:48:51 -0000
@@ -1955,7 +1955,7 @@ void PerspectiveShadowMap::createShadowM
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            exnode->setActive(false);
+            exnode->setTravMask(0);
     }
 
     for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
@@ -2049,8 +2049,7 @@ void PerspectiveShadowMap::createShadowM
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            if(_shadowVP->_excludeNodeActive[i])
-                exnode->setActive(true);
+            exnode->setTravMask(_shadowVP->_excludeNodeTravMask[i]);
     }
 
     //-------Restoring old states of Window and Viewport----------
@@ -2109,7 +2108,7 @@ void PerspectiveShadowMap::createShadowM
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            exnode->setActive(false);
+            exnode->setTravMask(0);
     }
 
     for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
@@ -2338,8 +2337,7 @@ void PerspectiveShadowMap::createShadowM
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            if(_shadowVP->_excludeNodeActive[i])
-                exnode->setActive(true);
+            exnode->setTravMask(_shadowVP->_excludeNodeTravMask[i]);
     }
 
     //-------Restoring old states of Window and Viewport----------
@@ -2383,7 +2381,7 @@ void PerspectiveShadowMap::createShadowM
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            exnode->setActive(false);
+            exnode->setTravMask(0);
     }
 
     for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
@@ -2543,8 +2541,7 @@ void PerspectiveShadowMap::createShadowM
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            if(_shadowVP->_excludeNodeActive[i])
-                exnode->setActive(true);
+            exnode->setTravMask(_shadowVP->_excludeNodeTravMask[i]);
     }
 
     //-------Restoring old states of Window and Viewport----------
Index: Source/Experimental/ShadowViewport/OSGShadowViewport.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/Experimental/ShadowViewport/OSGShadowViewport.cpp,v
retrieving revision 1.42
diff -u -p -r1.42 OSGShadowViewport.cpp
--- Source/Experimental/ShadowViewport/OSGShadowViewport.cpp	2 Sep 2011 16:15:41 -0000	1.42
+++ Source/Experimental/ShadowViewport/OSGShadowViewport.cpp	12 Dec 2011 23:48:51 -0000
@@ -152,7 +152,7 @@ ShadowViewport::ShadowViewport(void) :
     _lightStates(),
     _shadowImages(),
     _texChunks(),
-    _excludeNodeActive(),
+    _excludeNodeTravMask(),
     _realPointLight(),
     _renderSide(),
     _trigger_update(false),
@@ -250,7 +250,7 @@ ShadowViewport::ShadowViewport(const Sha
     _lightStates(source._lightStates),
     _shadowImages(source._shadowImages),
     _texChunks(source._texChunks),
-    _excludeNodeActive(source._excludeNodeActive),
+    _excludeNodeTravMask(source._excludeNodeTravMask),
     _realPointLight(source._realPointLight),
     _renderSide(source._renderSide),
     _trigger_update(source._trigger_update),
@@ -585,16 +585,16 @@ void ShadowViewport::render(RenderAction
         //endEditCP(getPtr(), SceneRootFieldMask);
     }
 
-    _excludeNodeActive.clear();
+    _excludeNodeTravMask.clear();
     _realPointLight.clear();
     //get excludeNode states
     for(UInt32 i = 0;i < getMFExcludeNodes()->getSize();i++)
     {
         NodePtr exnode = getExcludeNodes(i);
         if(exnode != NullFC)
-            _excludeNodeActive.push_back(exnode->getActive());
+            _excludeNodeTravMask.push_back(exnode->getTravMask());
         else
-            _excludeNodeActive.push_back(false);
+            _excludeNodeTravMask.push_back(0);
     }
 
 
@@ -642,7 +642,7 @@ void ShadowViewport::render(RenderAction
         for(UInt32 i = 0;i < getMFExcludeNodes()->getSize();++i)
         {
             NodePtr exnode = getExcludeNodes(i);
-            _excludeNodeActive[i] = exnode->getActive();
+            _excludeNodeTravMask[i] = exnode->getTravMask();
         }
 
         //check if all sides of a pointlight are needed
Index: Source/Experimental/ShadowViewport/OSGShadowViewport.h
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/Experimental/ShadowViewport/OSGShadowViewport.h,v
retrieving revision 1.14
diff -u -p -r1.14 OSGShadowViewport.h
--- Source/Experimental/ShadowViewport/OSGShadowViewport.h	3 Apr 2007 03:16:54 -0000	1.14
+++ Source/Experimental/ShadowViewport/OSGShadowViewport.h	12 Dec 2011 23:48:51 -0000
@@ -129,7 +129,7 @@ class OSG_SYSTEMLIB_DLLMAPPING ShadowVie
     std::vector<UInt32>                         _lightStates;
     std::vector<ImagePtr>                       _shadowImages;
     std::vector<TextureChunkPtr>                _texChunks;
-    std::vector<bool>                           _excludeNodeActive;
+    std::vector<UInt32>                         _excludeNodeTravMask;
     std::vector<bool>                           _realPointLight;
     std::vector<bool*>                          _renderSide;
 
Index: Source/Experimental/ShadowViewport/OSGStdShadowMap.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/Experimental/ShadowViewport/OSGStdShadowMap.cpp,v
retrieving revision 1.44
diff -u -p -r1.44 OSGStdShadowMap.cpp
--- Source/Experimental/ShadowViewport/OSGStdShadowMap.cpp	19 Nov 2009 01:28:34 -0000	1.44
+++ Source/Experimental/ShadowViewport/OSGStdShadowMap.cpp	12 Dec 2011 23:48:51 -0000
@@ -1373,7 +1373,7 @@ void StdShadowMap::createShadowMapsNOGLS
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            exnode->setActive(false);
+            exnode->setTravMask(0);
     }
 
     for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
@@ -1461,8 +1461,7 @@ void StdShadowMap::createShadowMapsNOGLS
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            if(_shadowVP->_excludeNodeActive[i])
-                exnode->setActive(true);
+            exnode->setTravMask(_shadowVP->_excludeNodeTravMask[i]);
     }
 
     //-------Restoring old states of Window and Viewport----------
@@ -1524,7 +1523,7 @@ void StdShadowMap::createShadowMaps(Rend
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            exnode->setActive(false);
+            exnode->setTravMask(0);
     }
 
     for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
@@ -1748,8 +1747,7 @@ void StdShadowMap::createShadowMaps(Rend
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            if(_shadowVP->_excludeNodeActive[i])
-                exnode->setActive(true);
+            exnode->setTravMask(_shadowVP->_excludeNodeTravMask[i]);
     }
     //-------Restoring old states of Window and Viewport----------
 
@@ -1792,7 +1790,7 @@ void StdShadowMap::createShadowMapsFBO(R
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            exnode->setActive(false);
+            exnode->setTravMask(0);
     }
 
     for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
@@ -1949,8 +1947,7 @@ void StdShadowMap::createShadowMapsFBO(R
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            if(_shadowVP->_excludeNodeActive[i])
-                exnode->setActive(true);
+            exnode->setTravMask(_shadowVP->_excludeNodeTravMask[i]);
     }
 
     //-------Restoring old states of Window and Viewport----------
Index: Source/Experimental/ShadowViewport/OSGVarianceShadowMap.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/Experimental/ShadowViewport/OSGVarianceShadowMap.cpp,v
retrieving revision 1.28
diff -u -p -r1.28 OSGVarianceShadowMap.cpp
--- Source/Experimental/ShadowViewport/OSGVarianceShadowMap.cpp	19 Nov 2009 01:28:34 -0000	1.28
+++ Source/Experimental/ShadowViewport/OSGVarianceShadowMap.cpp	12 Dec 2011 23:48:51 -0000
@@ -741,8 +741,7 @@ void VarianceShadowMap::createShadowMaps
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            if(_shadowVP->_excludeNodeActive[i])
-                exnode->setActive(true);
+            exnode->setTravMask(0);
     }
 
     for(UInt32 i = 0;i < _shadowVP->_lights.size();++i)
@@ -885,8 +884,7 @@ void VarianceShadowMap::createShadowMaps
     {
         NodePtr exnode = _shadowVP->getExcludeNodes(i);
         if(exnode != NullFC)
-            if(_shadowVP->_excludeNodeActive[i])
-                exnode->setActive(true);
+            exnode->setTravMask(_shadowVP->_excludeNodeTravMask[i]);
     }
 
     _shadowVP->setVPSize(0, 0, oldWidth - 1, oldHeight - 1);
------------------------------------------------------------------------------
Learn Windows Azure Live!  Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for 
developers. It will provide a great way to learn Windows Azure and what it 
provides. You can attend the event by watching it streamed LIVE online.  
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to