#1242 AppFwk : Effect Generator : Discard transparent fragments

This commit is contained in:
Magne Sjaastad 2017-02-27 22:20:06 +01:00
parent 1b01e98c0e
commit 28b87a1700
2 changed files with 27 additions and 1 deletions

View File

@ -60,6 +60,21 @@
namespace caf {
//#############################################################################################################################
//#############################################################################################################################
static const char checkDiscard_Transparent_Fragments_inl[] =
" \n"
"#define CVF_CHECK_DISCARD_FRAGMENT_IMPL \n"
" \n"
"//-------------------------------------------------------------------------------------------------- \n"
"/// Check if fragment should be discarded based on alpha fragment value \n"
"//-------------------------------------------------------------------------------------------------- \n"
"void checkDiscardFragment() \n"
"{ \n"
" vec4 color = srcFragment(); \n"
" if (color.a < 1.0) discard; \n"
"} \n";
//=============================================================================================================================
//=============================================================================================================================
@ -417,6 +432,7 @@ ScalarMapperEffectGenerator::ScalarMapperEffectGenerator(const cvf::ScalarMapper
m_faceCulling = FC_NONE;
m_enableDepthWrite = true;
m_disableLighting = false;
m_discardTransparentFragments = false;
}
//--------------------------------------------------------------------------------------------------
@ -429,6 +445,11 @@ void ScalarMapperEffectGenerator::updateForShaderBasedRendering(cvf::Effect* eff
cvf::ShaderProgramGenerator gen("ScalarMapperEffectGenerator", cvf::ShaderSourceProvider::instance());
gen.addVertexCode(cvf::ShaderSourceRepository::vs_Standard);
gen.addFragmentCode(cvf::ShaderSourceRepository::src_Texture);
if (m_discardTransparentFragments)
{
gen.addFragmentCode(checkDiscard_Transparent_Fragments_inl);
}
if (m_disableLighting)
{
@ -440,6 +461,7 @@ void ScalarMapperEffectGenerator::updateForShaderBasedRendering(cvf::Effect* eff
gen.addFragmentCode(cvf::ShaderSourceRepository::fs_Standard);
}
cvf::ref<cvf::ShaderProgram> prog = gen.generate();
eff->setShaderProgram(prog.p());
@ -568,7 +590,8 @@ bool ScalarMapperEffectGenerator::isEqual(const EffectGenerator* other) const
&& m_undefinedColor == otherTextureResultEffect->m_undefinedColor
&& m_faceCulling == otherTextureResultEffect->m_faceCulling
&& m_enableDepthWrite == otherTextureResultEffect->m_enableDepthWrite
&& m_disableLighting == otherTextureResultEffect->m_disableLighting)
&& m_disableLighting == otherTextureResultEffect->m_disableLighting
&& m_discardTransparentFragments == otherTextureResultEffect->m_discardTransparentFragments)
{
cvf::ref<cvf::TextureImage> texImg2 = new cvf::TextureImage;
otherTextureResultEffect->m_scalarMapper->updateTexture(texImg2.p());
@ -592,6 +615,7 @@ EffectGenerator* ScalarMapperEffectGenerator::copy() const
scEffGen->m_faceCulling = m_faceCulling;
scEffGen->m_enableDepthWrite = m_enableDepthWrite;
scEffGen->m_disableLighting = m_disableLighting;
scEffGen->m_discardTransparentFragments = m_discardTransparentFragments;
return scEffGen;
}

View File

@ -171,6 +171,7 @@ public:
void setFaceCulling(FaceCulling faceCulling) { m_faceCulling = faceCulling; }
void enableDepthWrite(bool enableWrite) { m_enableDepthWrite = enableWrite; }
void disableLighting(bool disable) { m_disableLighting = disable; }
void discardTransparentFragments(bool discard) { m_discardTransparentFragments = discard; }
public:
static cvf::ref<cvf::TextureImage> addAlphaAndUndefStripes(const cvf::TextureImage* texImg, const cvf::Color3f& undefScalarColor, float opacityLevel);
@ -195,6 +196,7 @@ private:
FaceCulling m_faceCulling;
bool m_enableDepthWrite;
bool m_disableLighting;
bool m_discardTransparentFragments;
};