mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Tune shadow perspective distortion (#12146)
* Pass perspective distortion parameters as uniforms * Set all perspective bias parameters via ShadowRenderer * Recalibrate perspective distortion and shadow range to render less shadow geometry with the same quality and observed shadow distance
This commit is contained in:
parent
06d197cdd0
commit
31578303a4
12 changed files with 117 additions and 59 deletions
|
@ -47,17 +47,17 @@ const float fogShadingParameter = 1.0 / ( 1.0 - fogStart);
|
|||
|
||||
|
||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||
const float bias0 = 0.9;
|
||||
const float zPersFactor = 0.5;
|
||||
const float bias1 = 1.0 - bias0 + 1e-6;
|
||||
uniform float xyPerspectiveBias0;
|
||||
uniform float xyPerspectiveBias1;
|
||||
uniform float zPerspectiveBias;
|
||||
|
||||
vec4 getPerspectiveFactor(in vec4 shadowPosition)
|
||||
{
|
||||
|
||||
float pDistance = length(shadowPosition.xy);
|
||||
float pFactor = pDistance * bias0 + bias1;
|
||||
float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1;
|
||||
|
||||
shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPersFactor);
|
||||
shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias);
|
||||
|
||||
return shadowPosition;
|
||||
}
|
||||
|
@ -172,12 +172,12 @@ float getHardShadowDepth(sampler2D shadowsampler, vec2 smTexCoord, float realDis
|
|||
float getBaseLength(vec2 smTexCoord)
|
||||
{
|
||||
float l = length(2.0 * smTexCoord.xy - 1.0); // length in texture coords
|
||||
return bias1 / (1.0 / l - bias0); // return to undistorted coords
|
||||
return xyPerspectiveBias1 / (1.0 / l - xyPerspectiveBias0); // return to undistorted coords
|
||||
}
|
||||
|
||||
float getDeltaPerspectiveFactor(float l)
|
||||
{
|
||||
return 0.1 / (bias0 * l + bias1); // original distortion factor, divided by 10
|
||||
return 0.1 / (xyPerspectiveBias0 * l + xyPerspectiveBias1); // original distortion factor, divided by 10
|
||||
}
|
||||
|
||||
float getPenumbraRadius(sampler2D shadowsampler, vec2 smTexCoord, float realDistance, float multiplier)
|
||||
|
@ -489,8 +489,8 @@ void main(void)
|
|||
vec3 shadow_color = vec3(0.0, 0.0, 0.0);
|
||||
vec3 posLightSpace = getLightSpacePosition();
|
||||
|
||||
float distance_rate = (1 - pow(clamp(2.0 * length(posLightSpace.xy - 0.5),0.0,1.0), 20.0));
|
||||
float f_adj_shadow_strength = max(adj_shadow_strength-mtsmoothstep(0.9,1.1, posLightSpace.z ),0.0);
|
||||
float distance_rate = (1 - pow(clamp(2.0 * length(posLightSpace.xy - 0.5),0.0,1.0), 50.0));
|
||||
float f_adj_shadow_strength = max(adj_shadow_strength-mtsmoothstep(0.9,1.1, posLightSpace.z),0.0);
|
||||
|
||||
if (distance_rate > 1e-7) {
|
||||
|
||||
|
|
|
@ -45,8 +45,8 @@ varying float nightRatio;
|
|||
const vec3 artificialLight = vec3(1.04, 1.04, 1.04);
|
||||
const float e = 2.718281828459;
|
||||
const float BS = 10.0;
|
||||
const float bias0 = 0.9;
|
||||
const float bias1 = 1.0 - bias0;
|
||||
uniform float xyPerspectiveBias0;
|
||||
uniform float xyPerspectiveBias1;
|
||||
|
||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||
// custom smoothstep implementation because it's not defined in glsl1.2
|
||||
|
@ -206,9 +206,9 @@ void main(void)
|
|||
// Distance from the vertex to the player
|
||||
float distanceToPlayer = length(eyeToVertex - v_LightDirection * dot(eyeToVertex, v_LightDirection)) / f_shadowfar;
|
||||
// perspective factor estimation according to the
|
||||
float perspectiveFactor = distanceToPlayer * bias0 + bias1;
|
||||
float perspectiveFactor = distanceToPlayer * xyPerspectiveBias0 + xyPerspectiveBias1;
|
||||
float texelSize = f_shadowfar * perspectiveFactor * perspectiveFactor /
|
||||
(f_textureresolution * bias1 - perspectiveFactor * bias0);
|
||||
(f_textureresolution * xyPerspectiveBias1 - perspectiveFactor * xyPerspectiveBias0);
|
||||
float slopeScale = clamp(pow(1.0 - cosLight*cosLight, 0.5), 0.0, 1.0);
|
||||
normalOffsetScale = texelSize * slopeScale;
|
||||
|
||||
|
|
|
@ -43,17 +43,17 @@ const float fogShadingParameter = 1.0 / (1.0 - fogStart);
|
|||
#endif
|
||||
|
||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||
const float bias0 = 0.9;
|
||||
const float zPersFactor = 0.5;
|
||||
const float bias1 = 1.0 - bias0 + 1e-6;
|
||||
uniform float xyPerspectiveBias0;
|
||||
uniform float xyPerspectiveBias1;
|
||||
uniform float zPerspectiveBias;
|
||||
|
||||
vec4 getPerspectiveFactor(in vec4 shadowPosition)
|
||||
{
|
||||
|
||||
float pDistance = length(shadowPosition.xy);
|
||||
float pFactor = pDistance * bias0 + bias1;
|
||||
float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1;
|
||||
|
||||
shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPersFactor);
|
||||
shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias);
|
||||
|
||||
return shadowPosition;
|
||||
}
|
||||
|
@ -162,12 +162,12 @@ float getHardShadowDepth(sampler2D shadowsampler, vec2 smTexCoord, float realDis
|
|||
float getBaseLength(vec2 smTexCoord)
|
||||
{
|
||||
float l = length(2.0 * smTexCoord.xy - 1.0); // length in texture coords
|
||||
return bias1 / (1.0 / l - bias0); // return to undistorted coords
|
||||
return xyPerspectiveBias1 / (1.0 / l - xyPerspectiveBias0); // return to undistorted coords
|
||||
}
|
||||
|
||||
float getDeltaPerspectiveFactor(float l)
|
||||
{
|
||||
return 0.1 / (bias0 * l + bias1); // original distortion factor, divided by 10
|
||||
return 0.1 / (xyPerspectiveBias0 * l + xyPerspectiveBias1); // original distortion factor, divided by 10
|
||||
}
|
||||
|
||||
float getPenumbraRadius(sampler2D shadowsampler, vec2 smTexCoord, float realDistance, float multiplier)
|
||||
|
@ -477,8 +477,8 @@ void main(void)
|
|||
vec3 shadow_color = vec3(0.0, 0.0, 0.0);
|
||||
vec3 posLightSpace = getLightSpacePosition();
|
||||
|
||||
float distance_rate = (1 - pow(clamp(2.0 * length(posLightSpace.xy - 0.5),0.0,1.0), 20.0));
|
||||
float f_adj_shadow_strength = max(adj_shadow_strength-mtsmoothstep(0.9,1.1, posLightSpace.z ),0.0);
|
||||
float distance_rate = (1 - pow(clamp(2.0 * length(posLightSpace.xy - 0.5),0.0,1.0), 50.0));
|
||||
float f_adj_shadow_strength = max(adj_shadow_strength-mtsmoothstep(0.9,1.1, posLightSpace.z),0.0);
|
||||
|
||||
if (distance_rate > 1e-7) {
|
||||
|
||||
|
|
|
@ -37,8 +37,8 @@ const vec3 artificialLight = vec3(1.04, 1.04, 1.04);
|
|||
varying float vIDiff;
|
||||
const float e = 2.718281828459;
|
||||
const float BS = 10.0;
|
||||
const float bias0 = 0.9;
|
||||
const float bias1 = 1.0 - bias0;
|
||||
uniform float xyPerspectiveBias0;
|
||||
uniform float xyPerspectiveBias1;
|
||||
|
||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||
// custom smoothstep implementation because it's not defined in glsl1.2
|
||||
|
@ -116,9 +116,9 @@ void main(void)
|
|||
// Distance from the vertex to the player
|
||||
float distanceToPlayer = length(eyeToVertex - v_LightDirection * dot(eyeToVertex, v_LightDirection)) / f_shadowfar;
|
||||
// perspective factor estimation according to the
|
||||
float perspectiveFactor = distanceToPlayer * bias0 + bias1;
|
||||
float perspectiveFactor = distanceToPlayer * xyPerspectiveBias0 + xyPerspectiveBias1;
|
||||
float texelSize = f_shadowfar * perspectiveFactor * perspectiveFactor /
|
||||
(f_textureresolution * bias1 - perspectiveFactor * bias0);
|
||||
(f_textureresolution * xyPerspectiveBias1 - perspectiveFactor * xyPerspectiveBias0);
|
||||
float slopeScale = clamp(pow(1.0 - cosLight*cosLight, 0.5), 0.0, 1.0);
|
||||
normalOffsetScale = texelSize * slopeScale;
|
||||
|
||||
|
|
|
@ -4,15 +4,15 @@ varying vec4 tPos;
|
|||
varying vec3 varColor;
|
||||
#endif
|
||||
|
||||
const float bias0 = 0.9;
|
||||
const float zPersFactor = 0.5;
|
||||
const float bias1 = 1.0 - bias0 + 1e-6;
|
||||
uniform float xyPerspectiveBias0;
|
||||
uniform float xyPerspectiveBias1;
|
||||
uniform float zPerspectiveBias;
|
||||
|
||||
vec4 getPerspectiveFactor(in vec4 shadowPosition)
|
||||
{
|
||||
float pDistance = length(shadowPosition.xy);
|
||||
float pFactor = pDistance * bias0 + bias1;
|
||||
shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPersFactor);
|
||||
float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1;
|
||||
shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias);
|
||||
|
||||
return shadowPosition;
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
uniform mat4 LightMVP; // world matrix
|
||||
varying vec4 tPos;
|
||||
|
||||
const float bias0 = 0.9;
|
||||
const float zPersFactor = 0.5;
|
||||
const float bias1 = 1.0 - bias0 + 1e-6;
|
||||
uniform float xyPerspectiveBias0;
|
||||
uniform float xyPerspectiveBias1;
|
||||
uniform float zPerspectiveBias;
|
||||
|
||||
vec4 getPerspectiveFactor(in vec4 shadowPosition)
|
||||
{
|
||||
float pDistance = length(shadowPosition.xy);
|
||||
float pFactor = pDistance * bias0 + bias1;
|
||||
shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPersFactor);
|
||||
float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1;
|
||||
shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias);
|
||||
|
||||
return shadowPosition;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue