Projekt-Grafika-Komputerowa/cw 6/shaders/shader_color.frag

34 lines
823 B
GLSL
Raw Normal View History

2022-01-23 19:43:27 +01:00
#version 410 core
uniform vec3 objectColor;
2022-02-10 16:21:08 +01:00
uniform vec4 objectColorTransparent;
2022-01-23 19:43:27 +01:00
uniform vec3 lightDir;
in vec3 interpNormal;
2022-02-10 16:21:08 +01:00
out vec4 Color;
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))));
}
2022-01-23 19:43:27 +01:00
void main()
{
vec3 normal = normalize(interpNormal);
float diffuse = max(dot(normal, -lightDir), 0.0);
2022-02-10 16:21:08 +01:00
//gl_FragColor = vec4(objectColor * diffuse, 1.0);
float depth = logisticDepth(gl_FragCoord.z, 0.5f, 4.0f);
Color = objectColorTransparent * diffuse * (1.0f - depth) + vec4(depth * vec3(5.0f/255.0f, 35.0f/255.0f, 95.0f/255.0f), 1.0f);
2022-01-23 19:43:27 +01:00
}