diff --git a/Fwk/AppFwk/CommonCode/cafEffectGenerator.cpp b/Fwk/AppFwk/CommonCode/cafEffectGenerator.cpp index fcfe86f08a..f0cac87129 100644 --- a/Fwk/AppFwk/CommonCode/cafEffectGenerator.cpp +++ b/Fwk/AppFwk/CommonCode/cafEffectGenerator.cpp @@ -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 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 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; } diff --git a/Fwk/AppFwk/CommonCode/cafEffectGenerator.h b/Fwk/AppFwk/CommonCode/cafEffectGenerator.h index fc5a2ec63f..19ae19c0f2 100644 --- a/Fwk/AppFwk/CommonCode/cafEffectGenerator.h +++ b/Fwk/AppFwk/CommonCode/cafEffectGenerator.h @@ -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 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; };