1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-01 03:21:41 +00:00

Scale mipmap alpha to preserve coverage

This commit is contained in:
AnyOldName3 2021-01-05 22:21:54 +00:00
parent d061ae8096
commit d13459ecf9
3 changed files with 28 additions and 0 deletions

View File

@ -12,6 +12,29 @@
uniform float alphaRef;
#endif
float mipmapLevel(vec2 scaleduv)
{
vec2 dUVdx = dFdx(scaleduv);
vec2 dUVdy = dFdy(scaleduv);
float maxDUVSquared = max(dot(dUVdx, dUVdx), dot(dUVdy, dUVdy));
return max(0.0, 0.5 * log2(maxDUVSquared));
}
float coveragePreservingAlphaScale(sampler2D diffuseMap, vec2 uv)
{
#if @alphaFunc != FUNC_ALWAYS && @alphaFunc != FUNC_NEVER
vec2 textureSize;
#ifdef GL_EXT_gpu_shader4
textureSize = textureSize2D(diffuseMap, 0);
#else
textureSize = 256.0;
#endif
return 1.0 + mipmapLevel(uv * textureSize) * 0.25;
#else
return 1.0;
#endif
}
void alphaTest()
{
#if @alphaToCoverage

View File

@ -1,5 +1,7 @@
#version 120
#extension EXT_gpu_shader4: enable
#if @diffuseMap
uniform sampler2D diffuseMap;
varying vec2 diffuseMapUV;
@ -109,6 +111,7 @@ void main()
#if @diffuseMap
gl_FragData[0] = texture2D(diffuseMap, adjustedDiffuseUV);
gl_FragData[0].a *= coveragePreservingAlphaScale(diffuseMap, adjustedDiffuseUV);
#else
gl_FragData[0] = vec4(1.0);
#endif

View File

@ -1,5 +1,7 @@
#version 120
#extension EXT_gpu_shader4: enable
uniform sampler2D diffuseMap;
varying vec2 diffuseMapUV;