mirror of
https://github.com/minetest/minetest.git
synced 2024-08-19 04:54:18 +02:00
Reuse normal offset calculation for nodes
This commit is contained in:
parent
4801bdf45a
commit
b651bbf446
@ -74,8 +74,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;
|
||||||
|
@ -45,6 +45,8 @@ varying float nightRatio;
|
|||||||
const vec3 artificialLight = vec3(1.04, 1.04, 1.04);
|
const vec3 artificialLight = vec3(1.04, 1.04, 1.04);
|
||||||
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
|
||||||
@ -195,10 +197,20 @@ 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);
|
|
||||||
normalOffsetScale = texelSize * slopeScale;
|
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
vec3 eyeToVertex = worldPosition - eyePosition + cameraOffset;
|
||||||
|
// 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 texelSize = f_shadowfar * perspectiveFactor * perspectiveFactor /
|
||||||
|
(f_textureresolution * bias1 - perspectiveFactor * bias0);
|
||||||
|
float slopeScale = clamp(pow(1.0 - cosLight*cosLight, 0.5), 0.0, 1.0);
|
||||||
|
normalOffsetScale = texelSize * slopeScale;
|
||||||
|
|
||||||
if (f_timeofday < 0.2) {
|
if (f_timeofday < 0.2) {
|
||||||
adj_shadow_strength = f_shadow_strength * 0.5 *
|
adj_shadow_strength = f_shadow_strength * 0.5 *
|
||||||
(1.0 - mtsmoothstep(0.18, 0.2, f_timeofday));
|
(1.0 - mtsmoothstep(0.18, 0.2, f_timeofday));
|
||||||
|
Loading…
Reference in New Issue
Block a user