mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-04-13 11:06:47 +00:00
Rely on existing alpha test for non-blended shadow casting
This commit is contained in:
parent
12044a607b
commit
53b9b41159
4 changed files with 8 additions and 30 deletions
|
@ -25,7 +25,6 @@ namespace Shader
|
||||||
: mShaderRequired(false)
|
: mShaderRequired(false)
|
||||||
, mColorMode(0)
|
, mColorMode(0)
|
||||||
, mMaterialOverridden(false)
|
, mMaterialOverridden(false)
|
||||||
, mAlphaFuncOverridden(false)
|
|
||||||
, mBlendFuncOverridden(false)
|
, mBlendFuncOverridden(false)
|
||||||
, mNormalHeight(false)
|
, mNormalHeight(false)
|
||||||
, mTexStageRequiringTangents(-1)
|
, mTexStageRequiringTangents(-1)
|
||||||
|
@ -279,19 +278,6 @@ namespace Shader
|
||||||
mRequirements.back().mColorMode = colorMode;
|
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)
|
else if (it->first.first == osg::StateAttribute::BLENDFUNC)
|
||||||
{
|
{
|
||||||
if (!mRequirements.back().mBlendFuncOverridden || it->second.second & osg::StateAttribute::PROTECTED)
|
if (!mRequirements.back().mBlendFuncOverridden || it->second.second & osg::StateAttribute::PROTECTED)
|
||||||
|
@ -305,8 +291,9 @@ namespace Shader
|
||||||
alphaSettingsChanged = true;
|
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 (alphaSettingsChanged)
|
||||||
{
|
{
|
||||||
if (!writableStateSet)
|
if (!writableStateSet)
|
||||||
|
|
|
@ -75,7 +75,6 @@ namespace Shader
|
||||||
int mColorMode;
|
int mColorMode;
|
||||||
|
|
||||||
bool mMaterialOverridden;
|
bool mMaterialOverridden;
|
||||||
bool mAlphaFuncOverridden;
|
|
||||||
bool mBlendFuncOverridden;
|
bool mBlendFuncOverridden;
|
||||||
|
|
||||||
bool mNormalHeight; // true if normal map has height info in alpha channel
|
bool mNormalHeight; // true if normal map has height info in alpha channel
|
||||||
|
|
|
@ -11,18 +11,12 @@ uniform bool alphaTestShadows;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_FragData[0].rgb = vec3(1.0);
|
gl_FragData[0].rgb = vec3(1.0);
|
||||||
if (!alphaTestShadows)
|
|
||||||
{
|
|
||||||
gl_FragData[0].a = 1.0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (useDiffuseMapForShadowAlpha)
|
if (useDiffuseMapForShadowAlpha)
|
||||||
gl_FragData[0].a = texture2D(diffuseMap, diffuseMapUV).a * alphaPassthrough;
|
gl_FragData[0].a = texture2D(diffuseMap, diffuseMapUV).a * alphaPassthrough;
|
||||||
else
|
else
|
||||||
gl_FragData[0].a = alphaPassthrough;
|
gl_FragData[0].a = alphaPassthrough;
|
||||||
|
|
||||||
// Prevent translucent things casting shadow (including the player using an invisibility effect)
|
// 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 (gl_FragData[0].a <= 0.5)
|
if (alphaTestShadows && gl_FragData[0].a <= 0.5)
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ varying vec2 diffuseMapUV;
|
||||||
varying float alphaPassthrough;
|
varying float alphaPassthrough;
|
||||||
|
|
||||||
uniform int colorMode;
|
uniform int colorMode;
|
||||||
uniform bool useDiffuseMapForShadowAlpha;
|
uniform bool useDiffuseMapForShadowAlpha = true;
|
||||||
uniform bool alphaTestShadows;
|
uniform bool alphaTestShadows = true;
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
|
@ -15,13 +15,11 @@ void main(void)
|
||||||
vec4 viewPos = (gl_ModelViewMatrix * gl_Vertex);
|
vec4 viewPos = (gl_ModelViewMatrix * gl_Vertex);
|
||||||
gl_ClipVertex = viewPos;
|
gl_ClipVertex = viewPos;
|
||||||
|
|
||||||
if (alphaTestShadows && useDiffuseMapForShadowAlpha)
|
if (useDiffuseMapForShadowAlpha)
|
||||||
diffuseMapUV = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
|
diffuseMapUV = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
|
||||||
else
|
else
|
||||||
diffuseMapUV = vec2(0.0); // Avoid undefined behaviour if running on hardware predating the concept of dynamically uniform expressions
|
diffuseMapUV = vec2(0.0); // Avoid undefined behaviour if running on hardware predating the concept of dynamically uniform expressions
|
||||||
if (!alphaTestShadows)
|
if (colorMode == 2)
|
||||||
alphaPassthrough = 1.0;
|
|
||||||
else if (colorMode == 2)
|
|
||||||
alphaPassthrough = gl_Color.a;
|
alphaPassthrough = gl_Color.a;
|
||||||
else
|
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
|
// 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…
Reference in a new issue