forked from Mirrorlandia_minetest/minetest
Change normal bias for entities to avoid shadow acne
This commit is contained in:
parent
12896b22d8
commit
25c1974e0d
@ -56,12 +56,6 @@ vec4 getPerspectiveFactor(in vec4 shadowPosition)
|
|||||||
return shadowPosition;
|
return shadowPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
// assuming near is always 1.0
|
|
||||||
float getLinearDepth()
|
|
||||||
{
|
|
||||||
return 2.0 * f_shadowfar / (f_shadowfar + 1.0 - (2.0 * gl_FragCoord.z - 1.0) * (f_shadowfar - 1.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 getLightSpacePosition()
|
vec3 getLightSpacePosition()
|
||||||
{
|
{
|
||||||
vec4 pLightSpace;
|
vec4 pLightSpace;
|
||||||
@ -69,8 +63,7 @@ vec3 getLightSpacePosition()
|
|||||||
#if DRAW_TYPE == NDT_PLANTLIKE
|
#if DRAW_TYPE == NDT_PLANTLIKE
|
||||||
pLightSpace = m_ShadowViewProj * vec4(worldPosition, 1.0);
|
pLightSpace = m_ShadowViewProj * vec4(worldPosition, 1.0);
|
||||||
#else
|
#else
|
||||||
float offsetScale = (0.0057 * getLinearDepth() + normalOffsetScale);
|
pLightSpace = m_ShadowViewProj * vec4(worldPosition + normalOffsetScale * normalize(vNormal), 1.0);
|
||||||
pLightSpace = m_ShadowViewProj * vec4(worldPosition + offsetScale * normalize(vNormal), 1.0);
|
|
||||||
#endif
|
#endif
|
||||||
pLightSpace = getPerspectiveFactor(pLightSpace);
|
pLightSpace = getPerspectiveFactor(pLightSpace);
|
||||||
return pLightSpace.xyz * 0.5 + 0.5;
|
return pLightSpace.xyz * 0.5 + 0.5;
|
||||||
@ -544,6 +537,5 @@ void main(void)
|
|||||||
float clarity = clamp(fogShadingParameter
|
float clarity = clamp(fogShadingParameter
|
||||||
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
|
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
|
||||||
col = mix(skyBgColor, col, clarity);
|
col = mix(skyBgColor, col, clarity);
|
||||||
|
|
||||||
gl_FragColor = vec4(col.rgb, base.a);
|
gl_FragColor = vec4(col.rgb, base.a);
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,8 @@ const vec3 artificialLight = vec3(1.04, 1.04, 1.04);
|
|||||||
varying float vIDiff;
|
varying float vIDiff;
|
||||||
const float e = 2.718281828459;
|
const float e = 2.718281828459;
|
||||||
const float BS = 10.0;
|
const float BS = 10.0;
|
||||||
|
const float bias0 = 0.9;
|
||||||
|
const float bias1 = 1.0 - bias0;
|
||||||
|
|
||||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||||
// custom smoothstep implementation because it's not defined in glsl1.2
|
// custom smoothstep implementation because it's not defined in glsl1.2
|
||||||
@ -104,8 +106,15 @@ void main(void)
|
|||||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||||
vec3 nNormal = normalize(vNormal);
|
vec3 nNormal = normalize(vNormal);
|
||||||
cosLight = dot(nNormal, -v_LightDirection);
|
cosLight = dot(nNormal, -v_LightDirection);
|
||||||
float texelSize = 767.0 / f_textureresolution;
|
|
||||||
float slopeScale = clamp(1.0 - abs(cosLight), 0.0, 1.0);
|
// Calculate normal offset scale based on the texel size adjusted for
|
||||||
|
// curvature of the SM texture. This code must be change together with
|
||||||
|
// getPerspectiveFactor or any light-space transformation.
|
||||||
|
float distanceToPlayer = length((eyePosition - worldPosition).xyz) / f_shadowfar;
|
||||||
|
float perspectiveFactor = distanceToPlayer * bias0 + bias1;
|
||||||
|
float texelSize = 1.0 / f_textureresolution;
|
||||||
|
texelSize *= f_shadowfar * perspectiveFactor / (bias1 / perspectiveFactor - texelSize * bias0) * 0.15;
|
||||||
|
float slopeScale = clamp(pow(1.0 - cosLight*cosLight, 0.5), 0.0, 1.0);
|
||||||
normalOffsetScale = texelSize * slopeScale;
|
normalOffsetScale = texelSize * slopeScale;
|
||||||
|
|
||||||
if (f_timeofday < 0.2) {
|
if (f_timeofday < 0.2) {
|
||||||
|
Loading…
Reference in New Issue
Block a user