From 4ef49086a519d6c450f242ccb7126ff8f08eaece Mon Sep 17 00:00:00 2001 From: Kraton99 Date: Thu, 27 Jan 2022 17:33:40 +0100 Subject: [PATCH] add fog on skybox --- cw 6/shaders/shader_cube.frag | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cw 6/shaders/shader_cube.frag b/cw 6/shaders/shader_cube.frag index 3c50f5a..f7571f5 100644 --- a/cw 6/shaders/shader_cube.frag +++ b/cw 6/shaders/shader_cube.frag @@ -4,7 +4,26 @@ out vec4 FragColor; in vec3 TexCoords; uniform samplerCube skybox; + + +float near = 0.1f; +float far = 70.0f; + +float linearizeDepth(float depth) +{ + return (2.0 * near * far) / (far + near - (depth * 2.0 - 1.0) * (far - near)); +} + + +float logisticDepth(float depth, float steepness, float offset) +{ + float zVal = linearizeDepth(depth); + return (1 / (1 + exp(-steepness * (zVal - offset)))); +} + void main() { + float depth = logisticDepth(gl_FragCoord.z, 0.5f, 5.0f); + //FragColor = texture(skybox,TexCoords) * (1.0f - depth) + vec4(depth * vec3(5.0f/255.0f, 35.0f/255.0f, 95.0f/255.0f), 1.0f); FragColor = texture(skybox,TexCoords); }