2023-12-18 16:15:08 +01:00
|
|
|
#version 430 core
|
|
|
|
|
2024-02-03 23:21:33 +01:00
|
|
|
float AMBIENT = 0.05;
|
|
|
|
|
|
|
|
uniform sampler2D colorTexture;
|
2023-12-18 16:15:08 +01:00
|
|
|
|
2024-01-15 16:36:57 +01:00
|
|
|
uniform vec3 color;
|
2023-12-18 16:15:08 +01:00
|
|
|
uniform vec3 lightPos;
|
2024-01-15 16:36:57 +01:00
|
|
|
uniform vec3 lightColor;
|
2023-12-18 16:15:08 +01:00
|
|
|
|
2024-02-03 23:21:33 +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;
|
2023-12-18 16:15:08 +01:00
|
|
|
|
2024-02-03 23:21:33 +01:00
|
|
|
out vec4 outColor;
|
2023-12-18 16:15:08 +01:00
|
|
|
|
2024-01-26 22:40:06 +01:00
|
|
|
vec3 toneMapping(vec3 color)
|
|
|
|
{
|
2024-01-15 16:36:57 +01:00
|
|
|
float exposure = 0.06;
|
2024-01-26 22:40:06 +01:00
|
|
|
vec3 mapped = 1 - exp(-color * exposure);
|
2024-01-15 16:36:57 +01:00
|
|
|
return mapped;
|
|
|
|
}
|
|
|
|
|
2023-12-18 16:15:08 +01:00
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec3 normal = normalize(vecNormal);
|
2024-02-03 23:21:33 +01:00
|
|
|
vec3 viewDir = normalize(cameraPos - worldPos);
|
|
|
|
vec3 lightDir = normalize(lightPos - worldPos);
|
|
|
|
|
2024-01-14 19:42:19 +01:00
|
|
|
float diffuse = max(0, dot(normal, lightDir));
|
2024-01-26 22:40:06 +01:00
|
|
|
|
2024-02-03 23:21:33 +01:00
|
|
|
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);
|
2024-01-18 16:50:20 +01:00
|
|
|
|
2024-02-03 23:21:33 +01:00
|
|
|
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));
|
2023-12-18 16:15:08 +01:00
|
|
|
|
2024-02-03 23:21:33 +01:00
|
|
|
outColor = vec4(toneMappedColor, 1);
|
2024-01-15 16:36:57 +01:00
|
|
|
}
|