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

55 lines
1.3 KiB
GLSL
Raw Normal View History

2023-12-18 16:15:08 +01:00
#version 430 core
2024-02-07 20:16:03 +01:00
layout (location = 0) out vec4 outColor;
layout (location = 1) out vec4 BrightColor;
2023-12-18 16:15:08 +01:00
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
2024-02-07 20:16:03 +01:00
//out vec4 outColor;
2023-12-18 16:15:08 +01:00
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);
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));
2024-02-07 20:16:03 +01:00
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);
2024-01-17 22:01:14 +01:00
}