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
|
|
|
|
2024-02-03 23:21:33 +01:00
|
|
|
uniform vec3 cameraPos;
|
|
|
|
|
|
|
|
uniform bool atmosphereCheck;
|
|
|
|
|
2024-02-07 20:06:08 +01:00
|
|
|
uniform float time;
|
|
|
|
|
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;
|
|
|
|
|
2024-02-07 20:06:08 +01:00
|
|
|
vec4 noiseColor;
|
|
|
|
|
2024-02-03 23:21:33 +01:00
|
|
|
vec3 toneMapping(vec3 color)
|
|
|
|
{
|
|
|
|
float exposure = 0.06;
|
|
|
|
vec3 mapped = 1 - exp(-color * exposure);
|
|
|
|
return mapped;
|
|
|
|
}
|
|
|
|
|
2024-02-07 20:06:08 +01:00
|
|
|
float random (in vec2 _st) {
|
|
|
|
return fract(sin(dot(_st.xy,
|
|
|
|
vec2(-0.550,0.430)))*
|
|
|
|
43758.5453123);
|
|
|
|
}
|
|
|
|
|
|
|
|
float noise (in vec2 _st) {
|
|
|
|
vec2 i = floor(_st);
|
|
|
|
vec2 f = fract(_st);
|
|
|
|
|
|
|
|
float a = random(i);
|
|
|
|
float b = random(i + vec2(1.0, 0.0));
|
|
|
|
float c = random(i + vec2(0.0, 1.0));
|
|
|
|
float d = random(i + vec2(1.0, 1.0));
|
|
|
|
|
|
|
|
vec2 u = f * f * (3.0 - 2.0 * f);
|
|
|
|
|
|
|
|
return mix(a, b, u.x) +
|
|
|
|
(c - a)* u.y * (1.0 - u.x) +
|
|
|
|
(d - b) * u.x * u.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NUM_OCTAVES 5
|
|
|
|
|
|
|
|
float fbm ( in vec2 _st) {
|
|
|
|
float v = 0.0;
|
|
|
|
float a = 0.5;
|
|
|
|
vec2 shift = vec2(100.0);
|
|
|
|
|
|
|
|
mat2 rot = mat2(cos(0.5), sin(0.5),
|
|
|
|
-sin(0.5), cos(0.5));
|
|
|
|
for (int i = 0; i < NUM_OCTAVES; ++i) {
|
|
|
|
v += a * noise(_st);
|
|
|
|
_st = rot * _st * 2.0 + shift;
|
2024-02-07 20:19:25 +01:00
|
|
|
a *= 0.75;
|
2024-02-07 20:06:08 +01:00
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec4 noiseTexture(float time) {
|
|
|
|
vec2 st = vtc.xy * 9.;
|
|
|
|
vec3 color = vec3(0.0);
|
|
|
|
|
|
|
|
vec2 q = vec2(0.);
|
|
|
|
q.x = fbm(st + 0.0 * time);
|
|
|
|
q.y = fbm(st + vec2(1.0));
|
|
|
|
|
|
|
|
vec2 r = vec2(0.);
|
|
|
|
r.x = fbm(st + 1.0 * q + vec2(1.7, 9.2) + 0.15 * time);
|
|
|
|
r.y = fbm(st + 1.0 * q + vec2(8.3, 2.8) + 0.12 * time);
|
|
|
|
|
|
|
|
float f = fbm(st+r);
|
|
|
|
|
|
|
|
color = mix(vec3(0.667,0.640,0.088),
|
|
|
|
vec3(0.667,0.520,0.134),
|
|
|
|
clamp((f*f)*4.640,0.712,0.056));
|
|
|
|
|
|
|
|
color = mix(color,
|
2024-02-07 20:19:25 +01:00
|
|
|
vec3(0.165,0.111,0.036),
|
2024-02-07 20:06:08 +01:00
|
|
|
clamp(length(q),0.072,0.408));
|
|
|
|
|
|
|
|
color = mix(color,
|
2024-02-07 20:19:25 +01:00
|
|
|
vec3(1.000,0.306,0.143),
|
2024-02-07 20:06:08 +01:00
|
|
|
clamp(length(r.x),0.0,1.0));
|
|
|
|
|
|
|
|
noiseColor = vec4((f*f*f+1.384*f*f+1.044*f)*color,1.);
|
|
|
|
|
|
|
|
return noiseColor;
|
|
|
|
}
|
|
|
|
|
2023-12-18 16:15:08 +01:00
|
|
|
void main()
|
|
|
|
{
|
2024-02-03 23:21:33 +01:00
|
|
|
vec3 normal = normalize(vecNormal);
|
|
|
|
vec3 viewDir = normalize(cameraPos - worldPos);
|
|
|
|
|
2024-02-04 20:34:45 +01:00
|
|
|
vec3 textureColor = texture2D(colorTexture, vtc).rgb;
|
2024-02-03 23:21:33 +01:00
|
|
|
|
|
|
|
if (atmosphereCheck)
|
2024-02-04 20:34:45 +01:00
|
|
|
{
|
|
|
|
float atmosphereDot = dot(normal, viewDir);
|
|
|
|
vec3 atmosphereColor = vec3(1.0, 0.08, 0.02);
|
2024-02-07 20:19:25 +01:00
|
|
|
textureColor = mix(textureColor, atmosphereColor, pow(1 - atmosphereDot, 2));
|
2024-02-04 20:34:45 +01:00
|
|
|
}
|
2024-02-03 23:21:33 +01:00
|
|
|
|
2024-02-07 20:06:08 +01:00
|
|
|
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 15;
|
|
|
|
|
|
|
|
vec4 textureNoise = noiseTexture(time);
|
2024-02-07 20:19:25 +01:00
|
|
|
vec3 mixedTexture = mix(textureColor, textureNoise.rgb, 0.45f);
|
|
|
|
|
|
|
|
vec3 toneMappedColor = toneMapping(mixedTexture * distance);
|
2024-02-03 23:21:33 +01:00
|
|
|
//gamma correction
|
|
|
|
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
|
|
|
|
|
2024-02-07 20:06:08 +01:00
|
|
|
vec3 textureToned = toneMappedColor * lightColor * 0.2f;
|
|
|
|
|
|
|
|
outColor = vec4(textureToned, 1.0);
|
2024-01-17 22:01:14 +01:00
|
|
|
}
|