Added fog

This commit is contained in:
andreistr21 2022-02-10 19:59:26 +01:00
parent 1c2451b874
commit cf3965c485
2 changed files with 37 additions and 3 deletions

View File

@ -6,11 +6,28 @@ uniform vec3 lightDir;
in vec3 interpNormal; in vec3 interpNormal;
in vec2 interpTexCoord; in vec2 interpTexCoord;
float near = 00.01f;
float far = 100.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() void main()
{ {
vec2 modifiedTexCoord = vec2(interpTexCoord.x, 1.0 - interpTexCoord.y); // Poprawka dla tekstur Ziemi, ktore bez tego wyswietlaja sie 'do gory nogami' vec2 modifiedTexCoord = vec2(interpTexCoord.x, 1.0 - interpTexCoord.y); // Poprawka dla tekstur Ziemi, ktore bez tego wyswietlaja sie 'do gory nogami'
vec3 color = texture2D(textureSampler, modifiedTexCoord).rgb; vec3 color = texture2D(textureSampler, modifiedTexCoord).rgb;
vec3 normal = normalize(interpNormal); vec3 normal = normalize(interpNormal);
float diffuse = max(dot(normal, -lightDir), 0.0); float diffuse = max(dot(normal, -lightDir), 0.0);
gl_FragColor = vec4(color * diffuse, 1.0); float depth = logisticDepth(gl_FragCoord.z, 0.5f, 4.0f);
gl_FragColor = vec4(color * diffuse, 1.0) * (1.0f - depth) + vec4(depth * vec3(5.0f/255.0f, 35.0f/255.0f, 95.0f/255.0f), 1.0f);
} }

View File

@ -1,11 +1,28 @@
#version 410 core #version 410 core
out vec4 FragColor; out vec4 FragColor;
in vec3 TexCoords;
in vec3 texCoords;
uniform samplerCube skybox; uniform samplerCube skybox;
float near = 00.01f;
float far = 7f;
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() void main()
{ {
FragColor = texture(skybox, TexCoords); float depth = logisticDepth(gl_FragCoord.z, 0.5f, 4.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);
} }