PlanetEditor/grk/cw 6/shaders/shader_sun.frag
Natalia Nowakowska d94b5cd398 merge bloom
2024-02-07 20:16:03 +01:00

55 lines
1.3 KiB
GLSL

#version 430 core
layout (location = 0) out vec4 outColor;
layout (location = 1) out vec4 BrightColor;
uniform vec3 lightPos;
uniform vec3 lightColor;
uniform vec3 cameraPos;
uniform bool atmosphereCheck;
in vec3 vecNormal;
in vec3 worldPos;
in vec2 vtc;
//out vec4 outColor;
uniform sampler2D colorTexture;
vec3 toneMapping(vec3 color)
{
float exposure = 0.06;
vec3 mapped = 1 - exp(-color * exposure);
return mapped;
}
void main()
{
vec3 normal = normalize(vecNormal);
vec3 viewDir = normalize(cameraPos - worldPos);
vec3 textureColor = texture2D(colorTexture, vtc).rgb;
if (atmosphereCheck)
{
float atmosphereDot = dot(normal, viewDir);
vec3 atmosphereColor = vec3(1.0, 0.08, 0.02);
textureColor = mix(textureColor, atmosphereColor, pow(1 - atmosphereDot, 3));
}
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 25;
vec3 toneMappedColor = toneMapping(textureColor * distance);
//gamma correction
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
vec3 finalColor = toneMappedColor * lightColor * 0.2f;
float brightness = dot(finalColor, vec3(0.2126, 0.7152, 0.0722));
if(brightness > 0.2)
BrightColor = vec4(finalColor, 1.0);
else
BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
outColor = vec4(finalColor, 1.0);
}