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

50 lines
1.1 KiB
GLSL

#version 430 core
float AMBIENT = 0.05;
uniform sampler2D colorTexture;
uniform vec3 color;
uniform vec3 lightPos;
uniform vec3 lightColor;
uniform vec3 cameraPos;
uniform bool atmosphereCheck;
in vec3 vecNormal;
in vec3 worldPos;
in vec2 vtc;
out vec4 outColor;
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 lightDir = normalize(lightPos - worldPos);
float diffuse = max(0, dot(normal, lightDir));
vec4 textureColor = texture2D(colorTexture, vtc);
float atmosphereDot = dot(normal, viewDir);
vec3 atmosphereColor = vec3(0.04, 0.2, 1.0);
if (atmosphereCheck)
textureColor = mix(textureColor, vec4(atmosphereColor / atmosphereDot, 1.0), 0.05);
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 10000;
vec3 toneMappedColor = toneMapping(vec3(textureColor) * min(1, AMBIENT + diffuse) * distance);
//gamma correction
//toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
outColor = vec4(toneMappedColor, 1);
}