Hello Pablo,
Pablo Carneiro Elias wrote:
I'm drawing a cloud of transparent object and I use a shader to perform
some calculations over this cloud. I discovered that OpenSG turns off Z
Write for transparent objects by default. This is ok since they will be
ordered in Z, but sub elements within the same object geometry are
drawed in a wrong way.. Plus, I need Z valus to perform many
calculations within my shader code... I 've tried to enable Z Write
using RenderOptions like below:
OSG::RenderOptionsUnrecPtr options =
OSG::RenderOptions::create();
options->setZWriteTrans( true );
options->activate( _renderAction );
where _renderAction is a pointer to RenderAction.
hm, RenderOptions is lacking a lot of option setting code in activate(),
it might have been forgotten to finish.
Gerrit: Is this just an overlooked piece from the RenderAction rework or
was there another plan for RenderOptions? If it was just forgotten I'll
put the option setting code back in, ok?
Also there is currently no way to set the _bZWriteTrans value of the
RenderPartition, that looks like a simple omission as well (fixed by the
attached patch)?
It doesn't work at all. I've tried also to place a ChunkOverrideNode
with a DepthChunk, but it didn't yield results...
This should have worked, but there is bug hiding [1]. The attached patch
(fix.state.tracking.diff) should fix it, but it is untested.
How can I turn on Z Write for transparent objects?
With the attached patch (add.zwritetrans.option.diff) you can enable it
with RenderAction::setZWriteTrans(true).
Cheers,
Carsten
[1] When going from opaque to transparent objects the last opaque state
is kept active, but then a call to glDepthMask(false) is being made to
disable depth writes for transparent objects. The state tracking does
not know about this happening and therefore has no reason to re-apply
the override.
I guess we can just call _oDrawEnv.deactivateState() before starting to
render transparent objects?
diff --git a/Source/System/Action/Base/OSGRenderActionBase.cpp b/Source/System/Action/Base/OSGRenderActionBase.cpp
index 26a7909..c0e1896 100644
--- a/Source/System/Action/Base/OSGRenderActionBase.cpp
+++ b/Source/System/Action/Base/OSGRenderActionBase.cpp
@@ -90,8 +90,9 @@ RenderActionBase::RenderActionBase(void) :
_bFrustumCulling (true ),
_bVolumeDrawing (false ),
+ _bZWriteTrans (false ),
_bAutoFrustum (true ),
- _bCorrectTwoSidedLighting(false ),
+ _bCorrectTwoSidedLighting (false ),
_oFrustum ( ),
_uiFrameTravCount (0 ),
_iDrawerId (-1 ),
@@ -117,6 +118,7 @@ RenderActionBase::RenderActionBase(const RenderActionBase &source) :
_bFrustumCulling (source._bFrustumCulling ),
_bVolumeDrawing (source._bVolumeDrawing ),
+ _bZWriteTrans (source._bZWriteTrans ),
_bAutoFrustum (source._bAutoFrustum ),
_bCorrectTwoSidedLighting(source._bCorrectTwoSidedLighting),
_oFrustum (source._oFrustum ),
@@ -242,14 +244,6 @@ void RenderActionBase::setCorrectTwoSidedLighting(bool val)
_bCorrectTwoSidedLighting = val;
}
-// automatically calc the frustum at the beginning of the traversal
-// default true
-
-void RenderActionBase::setAutoFrustum(bool val)
-{
- _bAutoFrustum = val;
-}
-
// draw the tested volumes
// default false
@@ -258,50 +252,25 @@ void RenderActionBase::setVolumeDrawing(bool val)
_bVolumeDrawing = val;
}
-// explicitly set the frustum
-
-void RenderActionBase::setFrustum(FrustumVolume &oFrustum)
+void RenderActionBase::setZWriteTrans(bool val)
{
- _oFrustum = oFrustum;
+ _bZWriteTrans = val;
}
+// automatically calc the frustum at the beginning of the traversal
+// default true
-#if 0
-// select all visible nodes
-UInt32 RenderActionBase::selectVisibles(void)
+void RenderActionBase::setAutoFrustum(bool val)
{
- if(getFrustumCulling() == false)
- return getNNodes();
-
- useNodeList();
-
- Color3f col;
-
- UInt32 count = 0;
-
- for(UInt32 i = 0; i < getNNodes(); i++)
- {
- if(isVisible(getCPtr(getNode(i))))
- {
- col.setValuesRGB(0,1,0);
-
- addNode(getNode(i));
-
- ++count;
- }
- else
- {
- col.setValuesRGB(1,0,0);
- }
+ _bAutoFrustum = val;
+}
- if(getVolumeDrawing())
- {
- dropVolume(this, getNode(i), col);
- }
- }
+// explicitly set the frustum
- return count;
+void RenderActionBase::setFrustum(FrustumVolume &oFrustum)
+{
+ _oFrustum = oFrustum;
}
-#endif
+
OSG_END_NAMESPACE
diff --git a/Source/System/Action/Base/OSGRenderActionBase.h b/Source/System/Action/Base/OSGRenderActionBase.h
index 8b76af5..14e49e8 100644
--- a/Source/System/Action/Base/OSGRenderActionBase.h
+++ b/Source/System/Action/Base/OSGRenderActionBase.h
@@ -154,6 +154,9 @@ class OSG_SYSTEM_DLLMAPPING RenderActionBase : public RenderActionBaseParent
// control drawing of checked volumes
virtual bool getVolumeDrawing (void ) const;
virtual void setVolumeDrawing (bool val = false);
+
+ virtual bool getZWriteTrans (void ) const;
+ virtual void setZWriteTrans (bool val = false);
// control automatic frustum calculation
bool getAutoFrustum (void ) const;
@@ -163,17 +166,6 @@ class OSG_SYSTEM_DLLMAPPING RenderActionBase : public RenderActionBaseParent
virtual const FrustumVolume &getFrustum (void ) const;
virtual void setFrustum (FrustumVolume &frust);
- /*! \} */
- /*---------------------------------------------------------------------*/
- /*! \name Lights */
- /*! \{ */
-
-#if 0
- // select all visible nodes
- UInt32 selectVisibles(void );
-
- virtual bool isVisible (Node *node) = 0;
-#endif
/*----------- multi-frame buffering / split cull/draw -------------------*/
@@ -280,6 +272,7 @@ class OSG_SYSTEM_DLLMAPPING RenderActionBase : public RenderActionBaseParent
bool _bFrustumCulling;
bool _bVolumeDrawing;
+ bool _bZWriteTrans;
bool _bAutoFrustum;
bool _bCorrectTwoSidedLighting;
diff --git a/Source/System/Action/Base/OSGRenderActionBase.inl b/Source/System/Action/Base/OSGRenderActionBase.inl
index 83c3d86..b37f32a 100644
--- a/Source/System/Action/Base/OSGRenderActionBase.inl
+++ b/Source/System/Action/Base/OSGRenderActionBase.inl
@@ -114,6 +114,12 @@ bool RenderActionBase::getVolumeDrawing(void) const
{
return _bVolumeDrawing;
}
+
+inline
+bool RenderActionBase::getZWriteTrans(void) const
+{
+ return _bZWriteTrans;
+}
inline
bool RenderActionBase::getAutoFrustum(void) const
diff --git a/Source/System/Action/Base/OSGRenderPartitionBase.h b/Source/System/Action/Base/OSGRenderPartitionBase.h
index 03ad6d9..c80a138 100644
--- a/Source/System/Action/Base/OSGRenderPartitionBase.h
+++ b/Source/System/Action/Base/OSGRenderPartitionBase.h
@@ -158,9 +158,12 @@ class OSG_SYSTEM_DLLMAPPING RenderPartitionBase : public DrawTask
/*------------------------- assignment ----------------------------------*/
- bool getCorrectNegScale(void );
+ bool getCorrectNegScale(void ) const;
void setCorrectNegScale(bool bVal);
+ bool getZWriteTrans (void ) const;
+ void setZWriteTrans (bool bVal);
+
/*------------------------- comparison ----------------------------------*/
/*------------------------- comparison ----------------------------------*/
diff --git a/Source/System/Action/Base/OSGRenderPartitionBase.inl b/Source/System/Action/Base/OSGRenderPartitionBase.inl
index 28ac817..87861ba 100644
--- a/Source/System/Action/Base/OSGRenderPartitionBase.inl
+++ b/Source/System/Action/Base/OSGRenderPartitionBase.inl
@@ -90,7 +90,7 @@ void RenderPartitionBase::setTaskType(UInt32 uiTaskType)
/*------------------------------ access -----------------------------------*/
inline
-bool RenderPartitionBase::getCorrectNegScale(void)
+bool RenderPartitionBase::getCorrectNegScale(void) const
{
return _bCorrectNegScale;
}
@@ -101,6 +101,18 @@ void RenderPartitionBase::setCorrectNegScale(bool bVal)
_bCorrectNegScale = bVal;
}
+inline
+bool RenderPartitionBase::getZWriteTrans(void) const
+{
+ return _bZWriteTrans;
+}
+
+inline
+void RenderPartitionBase::setZWriteTrans(bool bVal)
+{
+ _bZWriteTrans = bVal;
+}
+
/*---------------------------- properties ---------------------------------*/
/*-------------------------- assignment -----------------------------------*/
diff --git a/Source/System/Action/RenderAction/OSGRenderAction.cpp b/Source/System/Action/RenderAction/OSGRenderAction.cpp
index ceb08ad..f550085 100644
--- a/Source/System/Action/RenderAction/OSGRenderAction.cpp
+++ b/Source/System/Action/RenderAction/OSGRenderAction.cpp
@@ -516,6 +516,7 @@ Action::ResultE RenderAction::start(void)
_pActivePartition->setFrustumCulling (_bFrustumCulling );
_pActivePartition->setVolumeDrawing (_bVolumeDrawing );
+ _pActivePartition->setZWriteTrans (_bZWriteTrans );
_pActivePartition->setCorrectNegScale(_bCorrectTwoSidedLighting);
_pActivePartition->init();
@@ -882,6 +883,7 @@ void RenderAction::pushPartition(UInt32 uiCopyOnPush,
_pActivePartition->setStatCollector (_pStatistics );
_pActivePartition->setFrustumCulling (_bFrustumCulling );
_pActivePartition->setVolumeDrawing (_bVolumeDrawing );
+ _pActivePartition->setZWriteTrans (_bZWriteTrans );
_pActivePartition->setCorrectNegScale(_bCorrectTwoSidedLighting );
diff --git a/Source/System/Action/RenderAction/OSGRenderPartition.cpp b/Source/System/Action/RenderAction/OSGRenderPartition.cpp
index ce7f3bc..80346a6 100644
--- a/Source/System/Action/RenderAction/OSGRenderPartition.cpp
+++ b/Source/System/Action/RenderAction/OSGRenderPartition.cpp
@@ -485,6 +485,8 @@ void RenderPartition::doExecution (void)
mapIt = _mTransMatTrees.begin();
mapEnd = _mTransMatTrees.end ();
+ _oDrawEnv.deactivateState();
+
if(!_bZWriteTrans)
glDepthMask(false);
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users