Hello Christian,
On 04/01/2013 11:31 AM, Carsten Neumann wrote:
On 03/29/2013 05:31 AM, Christian Bar wrote:
Carsten, is it possible to modify the HDRStage with a
setCombineBlend(true) as you did with the ShadowStage?
probably, I'll have a look.
could you give the attached patch a try please?
Cheers,
Carsten
diff --git a/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStage.cpp b/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStage.cpp
index ac101b0..4fef6eb 100644
--- a/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStage.cpp
+++ b/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStage.cpp
@@ -59,6 +59,7 @@
#include "OSGTextureBuffer.h"
#include "OSGChunkMaterial.h"
+#include "OSGBlendChunk.h"
#include "OSGMaterialChunk.h"
#include "OSGTextureObjChunk.h"
#include "OSGDrawEnv.h"
@@ -483,10 +484,12 @@ HDRStageDataTransitPtr HDRStage::setupStageData(Int32 iPixelWidth,
MaterialChunkUnrecPtr pMatChunk = MaterialChunk::createLocal();
-
pMatChunk->setLit(false);
-
+ BlendChunkUnrecPtr pBlendChunk = BlendChunk ::createLocal();
+ pBlendChunk->setSrcFactor (GL_SRC_ALPHA);
+ pBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
+ pBlendChunk->setIgnore (!getCombineBlend());
// tone map material
@@ -494,6 +497,7 @@ HDRStageDataTransitPtr HDRStage::setupStageData(Int32 iPixelWidth,
ChunkMaterialUnrecPtr pTonemapMat = ChunkMaterial ::createLocal();
pTonemapMat->addChunk(pMatChunk );
+ pTonemapMat->addChunk(pBlendChunk );
pTonemapMat->addChunk(pSceneTex, 0);
pTonemapMat->addChunk(pSceneTexEnv, 0);
pTonemapMat->addChunk(pBlurTex1, 1);
@@ -885,6 +889,8 @@ void HDRStage::updateData(RenderAction *pAction,
if(pData == NULL)
{
initData(pAction, iVPWidth, iVPHeight);
+
+ pData = pAction->getData<HDRStageData *>(_iDataSlotId);
}
else if((pData->getWidth () != iVPWidth ) ||
(pData->getHeight() != iVPHeight) )
@@ -896,6 +902,13 @@ void HDRStage::updateData(RenderAction *pAction,
pData->setWidth (iVPWidth );
pData->setHeight(iVPHeight);
}
+
+ ChunkMaterial* pTonemapMat = pData->getToneMappingMaterial();
+ BlendChunk* pBlendChunk = static_cast<BlendChunk*>(
+ pTonemapMat->find(BlendChunk::getClassType()));
+
+ if(pBlendChunk != NULL)
+ pBlendChunk->setIgnore(!getCombineBlend());
}
#define OSGHDRL << std::endl
@@ -957,10 +970,10 @@ SimpleSHLChunkTransitPtr HDRStage::generateHDRFragmentProgram(void)
<< " c += effect * effectAmount;" OSGHDRL
<< "" OSGHDRL
<< " // exposure" OSGHDRL
- << " c = c * exposure;" OSGHDRL
+ << " c.rgb = c.rgb * exposure;" OSGHDRL
<< "" OSGHDRL
<< " // vignette effect" OSGHDRL
- << " c *= vignette(gl_TexCoord[0].xy * 2.0 - 1.0, 0.7, 1.5);" OSGHDRL
+ << " c.rgb *= vignette(gl_TexCoord[0].xy * 2.0 - 1.0, 0.7, 1.5);" OSGHDRL
<< "" OSGHDRL
<< " // gamma correction" OSGHDRL
<< " c.rgb = pow(c.rgb, vec3(gamma));" OSGHDRL
diff --git a/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStage.fcd b/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStage.fcd
index 15b71aa..8bf5285 100644
--- a/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStage.fcd
+++ b/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStage.fcd
@@ -69,4 +69,15 @@
access="public"
>
</Field>
+ <Field
+ name="combineBlend"
+ type="bool"
+ cardinality="single"
+ visibility="external"
+ defaultValue="false"
+ access="public"
+ >
+ Use blending when writing the combined scene and "effect" images
+ to the target framebuffer.
+ </Field>
</FieldContainer>
diff --git a/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStageBase.cpp b/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStageBase.cpp
index 94da2f8..ceaf15e 100644
--- a/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStageBase.cpp
+++ b/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStageBase.cpp
@@ -106,6 +106,11 @@ OSG_BEGIN_NAMESPACE
*/
+/*! \var bool HDRStageBase::_sfCombineBlend
+ Use blending when writing the combined scene and "effect"images
+ to the target framebuffer.
+*/
+
/***************************************************************************\
* FieldType/FieldTrait Instantiation *
@@ -201,6 +206,19 @@ void HDRStageBase::classDescInserter(TypeObject &oType)
static_cast<FieldGetMethodSig >(&HDRStage::getHandleBufferFormat));
oType.addInitialDesc(pDesc);
+
+ pDesc = new SFBool::Description(
+ SFBool::getClassType(),
+ "combineBlend",
+ "Use blending when writing the combined scene and \"effect\"images\n"
+ "to the target framebuffer.\n",
+ CombineBlendFieldId, CombineBlendFieldMask,
+ false,
+ (Field::SFDefaultFlags | Field::FStdAccess),
+ static_cast<FieldEditMethodSig>(&HDRStage::editHandleCombineBlend),
+ static_cast<FieldGetMethodSig >(&HDRStage::getHandleCombineBlend));
+
+ oType.addInitialDesc(pDesc);
}
@@ -286,6 +304,17 @@ HDRStageBase::TypeObject HDRStageBase::_type(
"\t access=\"public\"\n"
" >\n"
" </Field>\n"
+ " <Field\n"
+ " name=\"combineBlend\"\n"
+ " type=\"bool\"\n"
+ " cardinality=\"single\"\n"
+ " visibility=\"external\"\n"
+ " defaultValue=\"false\"\n"
+ " access=\"public\"\n"
+ " >\n"
+ " Use blending when writing the combined scene and "effect" images\n"
+ " to the target framebuffer.\n"
+ " </Field>\n"
"</FieldContainer>\n",
""
);
@@ -388,6 +417,19 @@ const SFGLenum *HDRStageBase::getSFBufferFormat(void) const
}
+SFBool *HDRStageBase::editSFCombineBlend(void)
+{
+ editSField(CombineBlendFieldMask);
+
+ return &_sfCombineBlend;
+}
+
+const SFBool *HDRStageBase::getSFCombineBlend(void) const
+{
+ return &_sfCombineBlend;
+}
+
+
@@ -422,6 +464,10 @@ SizeT HDRStageBase::getBinSize(ConstFieldMaskArg whichField)
{
returnValue += _sfBufferFormat.getBinSize();
}
+ if(FieldBits::NoField != (CombineBlendFieldMask & whichField))
+ {
+ returnValue += _sfCombineBlend.getBinSize();
+ }
return returnValue;
}
@@ -455,6 +501,10 @@ void HDRStageBase::copyToBin(BinaryDataHandler &pMem,
{
_sfBufferFormat.copyToBin(pMem);
}
+ if(FieldBits::NoField != (CombineBlendFieldMask & whichField))
+ {
+ _sfCombineBlend.copyToBin(pMem);
+ }
}
void HDRStageBase::copyFromBin(BinaryDataHandler &pMem,
@@ -492,6 +542,11 @@ void HDRStageBase::copyFromBin(BinaryDataHandler &pMem,
editSField(BufferFormatFieldMask);
_sfBufferFormat.copyFromBin(pMem);
}
+ if(FieldBits::NoField != (CombineBlendFieldMask & whichField))
+ {
+ editSField(CombineBlendFieldMask);
+ _sfCombineBlend.copyFromBin(pMem);
+ }
}
//! create a new instance of the class
@@ -622,7 +677,8 @@ HDRStageBase::HDRStageBase(void) :
_sfBlurAmount (Real32(0.5f)),
_sfEffectAmount (Real32(0.2f)),
_sfGamma (Real32(0.5f)),
- _sfBufferFormat (GLenum(GL_RGBA16F_ARB))
+ _sfBufferFormat (GLenum(GL_RGBA16F_ARB)),
+ _sfCombineBlend (bool(false))
{
}
@@ -633,7 +689,8 @@ HDRStageBase::HDRStageBase(const HDRStageBase &source) :
_sfBlurAmount (source._sfBlurAmount ),
_sfEffectAmount (source._sfEffectAmount ),
_sfGamma (source._sfGamma ),
- _sfBufferFormat (source._sfBufferFormat )
+ _sfBufferFormat (source._sfBufferFormat ),
+ _sfCombineBlend (source._sfCombineBlend )
{
}
@@ -795,6 +852,31 @@ EditFieldHandlePtr HDRStageBase::editHandleBufferFormat (void)
return returnValue;
}
+GetFieldHandlePtr HDRStageBase::getHandleCombineBlend (void) const
+{
+ SFBool::GetHandlePtr returnValue(
+ new SFBool::GetHandle(
+ &_sfCombineBlend,
+ this->getType().getFieldDesc(CombineBlendFieldId),
+ const_cast<HDRStageBase *>(this)));
+
+ return returnValue;
+}
+
+EditFieldHandlePtr HDRStageBase::editHandleCombineBlend (void)
+{
+ SFBool::EditHandlePtr returnValue(
+ new SFBool::EditHandle(
+ &_sfCombineBlend,
+ this->getType().getFieldDesc(CombineBlendFieldId),
+ this));
+
+
+ editSField(CombineBlendFieldMask);
+
+ return returnValue;
+}
+
#ifdef OSG_MT_CPTR_ASPECT
void HDRStageBase::execSyncV( FieldContainer &oFrom,
diff --git a/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStageBase.h b/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStageBase.h
index 73fb686..274118c 100644
--- a/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStageBase.h
+++ b/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStageBase.h
@@ -101,7 +101,8 @@ class OSG_EFFECTGROUPS_DLLMAPPING HDRStageBase : public Stage
EffectAmountFieldId = BlurAmountFieldId + 1,
GammaFieldId = EffectAmountFieldId + 1,
BufferFormatFieldId = GammaFieldId + 1,
- NextFieldId = BufferFormatFieldId + 1
+ CombineBlendFieldId = BufferFormatFieldId + 1,
+ NextFieldId = CombineBlendFieldId + 1
};
static const OSG::BitVector ExposureFieldMask =
@@ -116,6 +117,8 @@ class OSG_EFFECTGROUPS_DLLMAPPING HDRStageBase : public Stage
(TypeTraits<BitVector>::One << GammaFieldId);
static const OSG::BitVector BufferFormatFieldMask =
(TypeTraits<BitVector>::One << BufferFormatFieldId);
+ static const OSG::BitVector CombineBlendFieldMask =
+ (TypeTraits<BitVector>::One << CombineBlendFieldId);
static const OSG::BitVector NextFieldMask =
(TypeTraits<BitVector>::One << NextFieldId);
@@ -125,6 +128,7 @@ class OSG_EFFECTGROUPS_DLLMAPPING HDRStageBase : public Stage
typedef SFReal32 SFEffectAmountType;
typedef SFReal32 SFGammaType;
typedef SFGLenum SFBufferFormatType;
+ typedef SFBool SFCombineBlendType;
/*---------------------------------------------------------------------*/
/*! \name Class Get */
@@ -168,6 +172,9 @@ class OSG_EFFECTGROUPS_DLLMAPPING HDRStageBase : public Stage
SFGLenum *editSFBufferFormat (void);
const SFGLenum *getSFBufferFormat (void) const;
+ SFBool *editSFCombineBlend (void);
+ const SFBool *getSFCombineBlend (void) const;
+
Real32 &editExposure (void);
Real32 getExposure (void) const;
@@ -187,6 +194,9 @@ class OSG_EFFECTGROUPS_DLLMAPPING HDRStageBase : public Stage
GLenum &editBufferFormat (void);
const GLenum &getBufferFormat (void) const;
+ bool &editCombineBlend (void);
+ bool getCombineBlend (void) const;
+
/*! \} */
/*---------------------------------------------------------------------*/
/*! \name Field Set */
@@ -198,6 +208,7 @@ class OSG_EFFECTGROUPS_DLLMAPPING HDRStageBase : public Stage
void setEffectAmount (const Real32 value);
void setGamma (const Real32 value);
void setBufferFormat (const GLenum &value);
+ void setCombineBlend (const bool value);
/*! \} */
/*---------------------------------------------------------------------*/
@@ -263,6 +274,7 @@ class OSG_EFFECTGROUPS_DLLMAPPING HDRStageBase : public Stage
SFReal32 _sfEffectAmount;
SFReal32 _sfGamma;
SFGLenum _sfBufferFormat;
+ SFBool _sfCombineBlend;
/*! \} */
/*---------------------------------------------------------------------*/
@@ -302,6 +314,8 @@ class OSG_EFFECTGROUPS_DLLMAPPING HDRStageBase : public Stage
EditFieldHandlePtr editHandleGamma (void);
GetFieldHandlePtr getHandleBufferFormat (void) const;
EditFieldHandlePtr editHandleBufferFormat (void);
+ GetFieldHandlePtr getHandleCombineBlend (void) const;
+ EditFieldHandlePtr editHandleCombineBlend (void);
/*! \} */
/*---------------------------------------------------------------------*/
diff --git a/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStageBase.inl b/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStageBase.inl
index 30ac39f..98c03e5 100644
--- a/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStageBase.inl
+++ b/Source/System/NodeCores/Groups/Effects/HDR/OSGHDRStageBase.inl
@@ -224,6 +224,31 @@ void HDRStageBase::setBufferFormat(const GLenum &value)
_sfBufferFormat.setValue(value);
}
+//! Get the value of the HDRStage::_sfCombineBlend field.
+
+inline
+bool &HDRStageBase::editCombineBlend(void)
+{
+ editSField(CombineBlendFieldMask);
+
+ return _sfCombineBlend.getValue();
+}
+
+//! Get the value of the HDRStage::_sfCombineBlend field.
+inline
+ bool HDRStageBase::getCombineBlend(void) const
+{
+ return _sfCombineBlend.getValue();
+}
+
+//! Set the value of the HDRStage::_sfCombineBlend field.
+inline
+void HDRStageBase::setCombineBlend(const bool value)
+{
+ editSField(CombineBlendFieldMask);
+
+ _sfCombineBlend.setValue(value);
+}
#ifdef OSG_MT_CPTR_ASPECT
@@ -253,6 +278,9 @@ void HDRStageBase::execSync ( HDRStageBase *pFrom,
if(FieldBits::NoField != (BufferFormatFieldMask & whichField))
_sfBufferFormat.syncWith(pFrom->_sfBufferFormat);
+
+ if(FieldBits::NoField != (CombineBlendFieldMask & whichField))
+ _sfCombineBlend.syncWith(pFrom->_sfCombineBlend);
}
#endif
------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire
the most talented Cisco Certified professionals. Visit the
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users