diff --git a/assets/cubyz/shaders/deferred_render_pass.fs b/assets/cubyz/shaders/deferred_render_pass.fs index 3d000560..d987a6d1 100644 --- a/assets/cubyz/shaders/deferred_render_pass.fs +++ b/assets/cubyz/shaders/deferred_render_pass.fs @@ -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); diff --git a/assets/cubyz/shaders/deferred_render_pass.vs b/assets/cubyz/shaders/deferred_render_pass.vs index a8f83321..dcdbd304 100644 --- a/assets/cubyz/shaders/deferred_render_pass.vs +++ b/assets/cubyz/shaders/deferred_render_pass.vs @@ -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); }