Rely on existing alpha test for non-blended shadow casting

pull/2828/head
AnyOldName3 5 years ago
parent 12044a607b
commit 53b9b41159

@ -25,7 +25,6 @@ namespace Shader
: mShaderRequired(false)
, mColorMode(0)
, mMaterialOverridden(false)
, mAlphaFuncOverridden(false)
, mBlendFuncOverridden(false)
, mNormalHeight(false)
, mTexStageRequiringTangents(-1)
@ -279,19 +278,6 @@ namespace Shader
mRequirements.back().mColorMode = colorMode;
}
}
else if (it->first.first == osg::StateAttribute::ALPHAFUNC)
{
if (!mRequirements.back().mAlphaFuncOverridden || it->second.second & osg::StateAttribute::PROTECTED)
{
if (it->second.second & osg::StateAttribute::OVERRIDE)
mRequirements.back().mAlphaFuncOverridden = true;
const osg::AlphaFunc* test = static_cast<const osg::AlphaFunc*>(it->second.first.get());
if (test->getFunction() == osg::AlphaFunc::GREATER || test->getFunction() == osg::AlphaFunc::GEQUAL)
alphaTestShadows = true;
alphaSettingsChanged = true;
}
}
else if (it->first.first == osg::StateAttribute::BLENDFUNC)
{
if (!mRequirements.back().mBlendFuncOverridden || it->second.second & osg::StateAttribute::PROTECTED)
@ -305,8 +291,9 @@ namespace Shader
alphaSettingsChanged = true;
}
}
// Eventually, move alpha testing to discard in shader adn remove deprecated state here
}
// we don't need to check for glEnable/glDisable of blending and testing as we always set it at the same time
// we don't need to check for glEnable/glDisable of blending as we always set it at the same time
if (alphaSettingsChanged)
{
if (!writableStateSet)

@ -75,7 +75,6 @@ namespace Shader
int mColorMode;
bool mMaterialOverridden;
bool mAlphaFuncOverridden;
bool mBlendFuncOverridden;
bool mNormalHeight; // true if normal map has height info in alpha channel

@ -11,18 +11,12 @@ uniform bool alphaTestShadows;
void main()
{
gl_FragData[0].rgb = vec3(1.0);
if (!alphaTestShadows)
{
gl_FragData[0].a = 1.0;
return;
}
if (useDiffuseMapForShadowAlpha)
gl_FragData[0].a = texture2D(diffuseMap, diffuseMapUV).a * alphaPassthrough;
else
gl_FragData[0].a = alphaPassthrough;
// Prevent translucent things casting shadow (including the player using an invisibility effect)
if (gl_FragData[0].a <= 0.5)
// Prevent translucent things casting shadow (including the player using an invisibility effect). For now, rely on the deprecated FF test for non-blended stuff.
if (alphaTestShadows && gl_FragData[0].a <= 0.5)
discard;
}

@ -5,8 +5,8 @@ varying vec2 diffuseMapUV;
varying float alphaPassthrough;
uniform int colorMode;
uniform bool useDiffuseMapForShadowAlpha;
uniform bool alphaTestShadows;
uniform bool useDiffuseMapForShadowAlpha = true;
uniform bool alphaTestShadows = true;
void main(void)
{
@ -15,13 +15,11 @@ void main(void)
vec4 viewPos = (gl_ModelViewMatrix * gl_Vertex);
gl_ClipVertex = viewPos;
if (alphaTestShadows && useDiffuseMapForShadowAlpha)
if (useDiffuseMapForShadowAlpha)
diffuseMapUV = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
else
diffuseMapUV = vec2(0.0); // Avoid undefined behaviour if running on hardware predating the concept of dynamically uniform expressions
if (!alphaTestShadows)
alphaPassthrough = 1.0;
else if (colorMode == 2)
if (colorMode == 2)
alphaPassthrough = gl_Color.a;
else
// This is uniform, so if it's too low, we might be able to put the position/clip vertex outside the view frustum and skip the fragment shader and rasteriser

Loading…
Cancel
Save