PlanetEditor/grk/cw 6/shaders/shader_sun.frag

44 lines
1004 B
GLSL
Raw Normal View History

2023-12-18 16:15:08 +01:00
#version 430 core
uniform vec3 lightPos;
2024-01-21 13:34:33 +01:00
uniform vec3 lightColor;
2023-12-18 16:15:08 +01:00
uniform vec3 cameraPos;
uniform bool atmosphereCheck;
2023-12-18 16:15:08 +01:00
in vec3 vecNormal;
in vec3 worldPos;
2024-01-14 19:42:19 +01:00
in vec2 vtc;
2024-01-17 22:01:14 +01:00
2023-12-18 16:15:08 +01:00
out vec4 outColor;
uniform sampler2D colorTexture;
vec3 toneMapping(vec3 color)
{
float exposure = 0.06;
vec3 mapped = 1 - exp(-color * exposure);
return mapped;
}
2023-12-18 16:15:08 +01:00
void main()
{
vec3 normal = normalize(vecNormal);
vec3 viewDir = normalize(cameraPos - worldPos);
2024-01-14 19:42:19 +01:00
vec4 textureColor = texture2D(colorTexture, vtc);
float atmosphereDot = dot(normal, viewDir);
vec3 atmosphereColor = vec3(1.0, 0.04, 0.01);
if (atmosphereCheck)
textureColor = mix(textureColor, vec4(atmosphereColor / atmosphereDot, 1.0), 0.25);
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 25;
vec3 toneMappedColor = toneMapping(vec3(textureColor) * distance);
//gamma correction
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
outColor = vec4(toneMappedColor * lightColor * 0.2f, 1.0);
2024-01-17 22:01:14 +01:00
}