forked from Mirrorlandia_minetest/minetest
Node vertex shader: Properly use the waved world position (#12665)
This commit is contained in:
parent
bcc56803d7
commit
df1d215f48
@ -165,41 +165,34 @@ void main(void)
|
|||||||
smoothTriangleWave(animationTimer * 13.0 + tOffset)) * 0.5;
|
smoothTriangleWave(animationTimer * 13.0 + tOffset)) * 0.5;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
worldPosition = (mWorld * inVertexPosition).xyz;
|
vec4 pos = inVertexPosition;
|
||||||
|
|
||||||
// OpenGL < 4.3 does not support continued preprocessor lines
|
// OpenGL < 4.3 does not support continued preprocessor lines
|
||||||
#if (MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_OPAQUE || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_BASIC) && ENABLE_WAVING_WATER
|
#if (MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_OPAQUE || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_BASIC) && ENABLE_WAVING_WATER
|
||||||
// Generate waves with Perlin-type noise.
|
// Generate waves with Perlin-type noise.
|
||||||
// The constants are calibrated such that they roughly
|
// The constants are calibrated such that they roughly
|
||||||
// correspond to the old sine waves.
|
// correspond to the old sine waves.
|
||||||
vec4 pos = inVertexPosition;
|
vec3 wavePos = (mWorld * pos).xyz + cameraOffset;
|
||||||
vec3 wavePos = worldPosition + cameraOffset;
|
|
||||||
// The waves are slightly compressed along the z-axis to get
|
// The waves are slightly compressed along the z-axis to get
|
||||||
// wave-fronts along the x-axis.
|
// wave-fronts along the x-axis.
|
||||||
wavePos.x /= WATER_WAVE_LENGTH * 3.0;
|
wavePos.x /= WATER_WAVE_LENGTH * 3.0;
|
||||||
wavePos.z /= WATER_WAVE_LENGTH * 2.0;
|
wavePos.z /= WATER_WAVE_LENGTH * 2.0;
|
||||||
wavePos.z += animationTimer * WATER_WAVE_SPEED * 10.0;
|
wavePos.z += animationTimer * WATER_WAVE_SPEED * 10.0;
|
||||||
pos.y += (snoise(wavePos) - 1.0) * WATER_WAVE_HEIGHT * 5.0;
|
pos.y += (snoise(wavePos) - 1.0) * WATER_WAVE_HEIGHT * 5.0;
|
||||||
gl_Position = mWorldViewProj * pos;
|
|
||||||
#elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES && ENABLE_WAVING_LEAVES
|
#elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES && ENABLE_WAVING_LEAVES
|
||||||
vec4 pos = inVertexPosition;
|
|
||||||
pos.x += disp_x;
|
pos.x += disp_x;
|
||||||
pos.y += disp_z * 0.1;
|
pos.y += disp_z * 0.1;
|
||||||
pos.z += disp_z;
|
pos.z += disp_z;
|
||||||
gl_Position = mWorldViewProj * pos;
|
|
||||||
#elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_PLANTS && ENABLE_WAVING_PLANTS
|
#elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_PLANTS && ENABLE_WAVING_PLANTS
|
||||||
vec4 pos = inVertexPosition;
|
|
||||||
if (varTexCoord.y < 0.05) {
|
if (varTexCoord.y < 0.05) {
|
||||||
pos.x += disp_x;
|
pos.x += disp_x;
|
||||||
pos.z += disp_z;
|
pos.z += disp_z;
|
||||||
}
|
}
|
||||||
gl_Position = mWorldViewProj * pos;
|
|
||||||
#else
|
|
||||||
gl_Position = mWorldViewProj * inVertexPosition;
|
|
||||||
#endif
|
#endif
|
||||||
|
worldPosition = (mWorld * pos).xyz;
|
||||||
|
gl_Position = mWorldViewProj * pos;
|
||||||
|
|
||||||
vPosition = gl_Position.xyz;
|
vPosition = gl_Position.xyz;
|
||||||
eyeVec = -(mWorldView * inVertexPosition).xyz;
|
eyeVec = -(mWorldView * pos).xyz;
|
||||||
vNormal = inVertexNormal;
|
vNormal = inVertexNormal;
|
||||||
|
|
||||||
// Calculate color.
|
// Calculate color.
|
||||||
@ -228,13 +221,20 @@ void main(void)
|
|||||||
|
|
||||||
#ifdef ENABLE_DYNAMIC_SHADOWS
|
#ifdef ENABLE_DYNAMIC_SHADOWS
|
||||||
if (f_shadow_strength > 0.0) {
|
if (f_shadow_strength > 0.0) {
|
||||||
|
#if MATERIAL_TYPE == TILE_MATERIAL_WAVING_PLANTS && ENABLE_WAVING_PLANTS
|
||||||
|
// The shadow shaders don't apply waving when creating the shadow-map.
|
||||||
|
// We are using the not waved inVertexPosition to avoid ugly self-shadowing.
|
||||||
|
vec4 shadow_pos = inVertexPosition;
|
||||||
|
#else
|
||||||
|
vec4 shadow_pos = pos;
|
||||||
|
#endif
|
||||||
vec3 nNormal;
|
vec3 nNormal;
|
||||||
f_normal_length = length(vNormal);
|
f_normal_length = length(vNormal);
|
||||||
|
|
||||||
/* normalOffsetScale is in world coordinates (1/10th of a meter)
|
/* normalOffsetScale is in world coordinates (1/10th of a meter)
|
||||||
z_bias is in light space coordinates */
|
z_bias is in light space coordinates */
|
||||||
float normalOffsetScale, z_bias;
|
float normalOffsetScale, z_bias;
|
||||||
float pFactor = getPerspectiveFactor(getRelativePosition(m_ShadowViewProj * mWorld * inVertexPosition));
|
float pFactor = getPerspectiveFactor(getRelativePosition(m_ShadowViewProj * mWorld * shadow_pos));
|
||||||
if (f_normal_length > 0.0) {
|
if (f_normal_length > 0.0) {
|
||||||
nNormal = normalize(vNormal);
|
nNormal = normalize(vNormal);
|
||||||
cosLight = dot(nNormal, -v_LightDirection);
|
cosLight = dot(nNormal, -v_LightDirection);
|
||||||
@ -252,7 +252,7 @@ void main(void)
|
|||||||
}
|
}
|
||||||
z_bias *= pFactor * pFactor / f_textureresolution / f_shadowfar;
|
z_bias *= pFactor * pFactor / f_textureresolution / f_shadowfar;
|
||||||
|
|
||||||
shadow_position = applyPerspectiveDistortion(m_ShadowViewProj * mWorld * (inVertexPosition + vec4(normalOffsetScale * nNormal, 0.0))).xyz;
|
shadow_position = applyPerspectiveDistortion(m_ShadowViewProj * mWorld * (shadow_pos + vec4(normalOffsetScale * nNormal, 0.0))).xyz;
|
||||||
shadow_position.z -= z_bias;
|
shadow_position.z -= z_bias;
|
||||||
perspective_factor = pFactor;
|
perspective_factor = pFactor;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user