1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 06:35:30 +00:00

Always write opaque fragments instead of relying on blending being off for translucent RTT

This commit is contained in:
AnyOldName3 2021-01-20 01:17:16 +00:00
parent 6265081d08
commit 8af8ad3840
3 changed files with 29 additions and 2 deletions

View File

@ -5,6 +5,7 @@
#include <osg/Material>
#include <osg/Fog>
#include <osg/BlendFunc>
#include <osg/TexEnvCombine>
#include <osg/Texture2D>
#include <osg/Camera>
#include <osg/PositionAttitudeTransform>
@ -85,7 +86,7 @@ namespace MWRender
class SetUpBlendVisitor : public osg::NodeVisitor
{
public:
SetUpBlendVisitor(): osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
SetUpBlendVisitor(): osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), mNoAlphaUniform(new osg::Uniform("noAlpha", false))
{
}
@ -102,10 +103,17 @@ namespace MWRender
newStateSet->setAttribute(newBlendFunc, osg::StateAttribute::ON);
node.setStateSet(newStateSet);
}
if (stateset->getMode(GL_BLEND) & osg::StateAttribute::ON)
{
// Disable noBlendAlphaEnv
stateset->setTextureMode(7, GL_TEXTURE_2D, osg::StateAttribute::OFF);
stateset->addUniform(mNoAlphaUniform);
}
}
traverse(node);
}
private:
osg::ref_ptr<osg::Uniform> mNoAlphaUniform;
};
CharacterPreview::CharacterPreview(osg::Group* parent, Resource::ResourceSystem* resourceSystem,
@ -164,6 +172,20 @@ namespace MWRender
fog->setEnd(10000000);
stateset->setAttributeAndModes(fog, osg::StateAttribute::OFF|osg::StateAttribute::OVERRIDE);
// Opaque stuff must have 1 as its fragment alpha as the FBO is translucent, so having blending off isn't enough
osg::ref_ptr<osg::TexEnvCombine> noBlendAlphaEnv = new osg::TexEnvCombine();
noBlendAlphaEnv->setCombine_Alpha(osg::TexEnvCombine::REPLACE);
noBlendAlphaEnv->setSource0_Alpha(osg::TexEnvCombine::CONSTANT);
noBlendAlphaEnv->setConstantColor(osg::Vec4(0.0, 0.0, 0.0, 1.0));
noBlendAlphaEnv->setCombine_RGB(osg::TexEnvCombine::REPLACE);
noBlendAlphaEnv->setSource0_RGB(osg::TexEnvCombine::PREVIOUS);
osg::ref_ptr<osg::Texture2D> dummyTexture = new osg::Texture2D();
dummyTexture->setInternalFormat(GL_RED);
dummyTexture->setTextureSize(1, 1);
stateset->setTextureAttributeAndModes(7, dummyTexture, osg::StateAttribute::ON);
stateset->setTextureAttribute(7, noBlendAlphaEnv, osg::StateAttribute::ON);
stateset->addUniform(new osg::Uniform("noAlpha", true));
osg::ref_ptr<osg::LightModel> lightmodel = new osg::LightModel;
lightmodel->setAmbientIntensity(osg::Vec4(0.0, 0.0, 0.0, 1.0));
stateset->setAttributeAndModes(lightmodel, osg::StateAttribute::ON);

View File

@ -370,6 +370,7 @@ namespace MWRender
mRootNode->getOrCreateStateSet()->addUniform(new osg::Uniform("near", mNearClip));
mRootNode->getOrCreateStateSet()->addUniform(new osg::Uniform("far", mViewDistance));
mRootNode->getOrCreateStateSet()->addUniform(new osg::Uniform("simpleWater", false));
mRootNode->getOrCreateStateSet()->addUniform(new osg::Uniform("noAlpha", false));
mUniformNear = mRootNode->getOrCreateStateSet()->getUniform("near");
mUniformFar = mRootNode->getOrCreateStateSet()->getUniform("far");

View File

@ -50,6 +50,7 @@ uniform mat2 bumpMapMatrix;
#endif
uniform bool simpleWater;
uniform bool noAlpha;
varying float euclideanDepth;
varying float linearDepth;
@ -208,5 +209,8 @@ void main()
#endif
gl_FragData[0].xyz = mix(gl_FragData[0].xyz, gl_Fog.color.xyz, fogValue);
if (noAlpha)
gl_FragData[0].a = 1.0;
applyShadowDebugOverlay();
}