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

34 lines
823 B
GLSL

#version 410 core
uniform vec3 objectColor;
uniform vec4 objectColorTransparent;
uniform vec3 lightDir;
in vec3 interpNormal;
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))));
}
void main()
{
vec3 normal = normalize(interpNormal);
float diffuse = max(dot(normal, -lightDir), 0.0);
//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);
}