GRK-Projekt-Scena-Podwodna/Grk-Projekt/shaders/particle_2D.frag
2022-02-11 15:37:18 +01:00

37 lines
834 B
GLSL

#version 330 core
out vec4 FragColor;
in vec2 TexCords;
in vec4 ParticleColor;
uniform sampler2D theTexture;
uniform bool showFog;
uniform vec3 fogColor;
float linearizeDepth(float depth, float nearPlane, float farPlane)
{
return (2.0 * nearPlane * farPlane) / (farPlane + nearPlane - (depth * 2.0 - 1.0) * (farPlane - nearPlane));
}
float logisticDepth(float depth, float nearPlane, float farPlane, float steppness, float offeset)
{
float zVal = linearizeDepth(depth, nearPlane, farPlane);
return (1 / (1 + exp(-steppness * (zVal - offeset))));
}
void main()
{
if (showFog)
{
float d = logisticDepth(gl_FragCoord.z, 0.1, 100,0.05f,5.0f);
FragColor = texture(theTexture, TexCords) * (ParticleColor * (1.0 - d) + vec4(d * fogColor, 1.0));
}
else
{
FragColor = texture(theTexture, TexCords) * ParticleColor;
}
}