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

44 lines
1004 B
GLSL

#version 430 core
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);
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);
}