diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/resources/shaders/chunk.vert | 10 | ||||
-rw-r--r-- | src/main/resources/shaders/chunk_fog.frag | 18 |
2 files changed, 12 insertions, 16 deletions
diff --git a/src/main/resources/shaders/chunk.vert b/src/main/resources/shaders/chunk.vert index 9901ef3..75ee0ab 100644 --- a/src/main/resources/shaders/chunk.vert +++ b/src/main/resources/shaders/chunk.vert @@ -20,6 +20,7 @@ out vec4 Viewport; out mat4 ProjInv; out vec4 FogColor; out vec2 FogStartEnd; +out float FogFactor; void main() { @@ -30,5 +31,14 @@ void main() Viewport = viewport; ProjInv = projInv; FogColor = fogColor; + + float s = fogStartEnd.x; + float e = fogStartEnd.y; + vec4 eyePos = (modelView * (vec4(aPos - playerPos, 1.0) + vec4(0, 0.12, 0, 0))); + + float fogFactor = clamp((e - length(eyePos)) / (e - s), 0, 1); + + FogFactor = fogFactor; + FogStartEnd = fogStartEnd; }
\ No newline at end of file diff --git a/src/main/resources/shaders/chunk_fog.frag b/src/main/resources/shaders/chunk_fog.frag index 36c10af..160ae65 100644 --- a/src/main/resources/shaders/chunk_fog.frag +++ b/src/main/resources/shaders/chunk_fog.frag @@ -8,6 +8,7 @@ in vec4 Viewport; in mat4 ProjInv; in vec4 FogColor; in vec2 FogStartEnd; +in float FogFactor; uniform sampler2D atlas; uniform sampler2D lightTex; @@ -21,20 +22,5 @@ void main() vec4 rasterColor = ((texColor * colorMult) * lightyColor); - float s = FogStartEnd.x; - float e = FogStartEnd.y; - - vec4 ndcPos; - ndcPos.xy = ((2.0 * gl_FragCoord.xy) - (2.0 * Viewport.xy)) / (Viewport.zw) - 1; - ndcPos.z = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far) / - (gl_DepthRange.far - gl_DepthRange.near); - ndcPos.w = 1.0; - - vec4 clipPos = ndcPos / gl_FragCoord.w; - vec4 eyePos = ProjInv * clipPos; - - float z = length(eyePos); - float f = (e - z) / (e - s); - f = clamp(f, 0, 1); - FragColor = mix(FogColor, rasterColor, f); + FragColor = vec4(mix(FogColor.xyz, rasterColor.xyz, FogFactor), rasterColor.w); } |