Fix problem of the post processing shader sampling the fog values at the wrong resolution, leading to stripes at low resolution scales.

fixes #1065
This commit is contained in:
IntegratedQuantum 2025-02-19 19:11:20 +01:00
parent 980588f6ed
commit 1bcd5095da
2 changed files with 14 additions and 5 deletions

View File

@ -1,7 +1,7 @@
#version 430
out vec4 fragColor;
in vec2 texCoords;
in vec3 direction;
flat in vec3[4] directions;
uniform sampler2D color;
@ -78,7 +78,13 @@ vec3 applyFrontfaceFog(float fogDistance, vec3 fogColor, vec3 inColor) {
void main() {
fragColor = texture(color, texCoords);
fragColor += texture(bloomColor, texCoords);
float densityAdjustment = sqrt(dot(tanXY*(texCoords*2 - 1), tanXY*(texCoords*2 - 1)) + 1);
vec2 clampedTexCoords = (floor(texCoords*vec2(textureSize(color, 0))) + 0.5)/vec2(textureSize(color, 0));
vec3 direction = clampedTexCoords.x*(
clampedTexCoords.y*directions[0] + (1 - clampedTexCoords.y)*directions[1]
) + (1 - clampedTexCoords.x)*(
clampedTexCoords.y*directions[2] + (1 - clampedTexCoords.y)*directions[3]
);
float densityAdjustment = sqrt(dot(tanXY*(clampedTexCoords*2 - 1), tanXY*(clampedTexCoords*2 - 1)) + 1);
float dist = zFromDepth(texture(depthTexture, texCoords).r);
float fogDistance = calculateFogDistance(dist, densityAdjustment, playerPositionInteger.z + playerPositionFraction.z, normalize(direction).z, fog.density, fog.fogLower, fog.fogHigher);
fragColor.rgb = applyFrontfaceFog(fogDistance, fog.color, fragColor.rgb);

View File

@ -3,14 +3,17 @@
layout (location=0) in vec2 inTexCoords;
out vec2 texCoords;
out vec3 direction;
flat out vec3[4] directions;
uniform mat4 invViewMatrix;
uniform vec2 tanXY;
void main() {
vec2 position = inTexCoords*2 - vec2(1, 1);
direction = (invViewMatrix * vec4(position.x*tanXY.x, 1, position.y*tanXY.y, 0)).xyz;
directions[0] = (invViewMatrix * vec4(1*tanXY.x, 1, 1*tanXY.y, 0)).xyz;
directions[1] = (invViewMatrix * vec4(1*tanXY.x, 1, -1*tanXY.y, 0)).xyz;
directions[2] = (invViewMatrix * vec4(-1*tanXY.x, 1, 1*tanXY.y, 0)).xyz;
directions[3] = (invViewMatrix * vec4(-1*tanXY.x, 1, -1*tanXY.y, 0)).xyz;
texCoords = inTexCoords;
vec2 position = inTexCoords*2 - vec2(1, 1);
gl_Position = vec4(position, 0, 1);
}