bettola/assets/shaders/cloud.frag
Ritchie Cunningham a1c214caec [Add] Procedural cloud rendering.
Adds a skydome with two scrolling layers of procedurally generated
clouds to create an interestingish environment.
2025-09-18 20:18:02 +01:00

30 lines
867 B
GLSL

#version 330 core
out vec4 FragColor;
in vec3 TexCoords;
uniform sampler2D u_CloudTexture;
uniform vec3 u_LightDir;
const float PI = 3.14159265359;
void main() {
/* Convert 3D texture coords to 2D using spherical mapping. */
float u = atan(TexCoords.z, TexCoords.x) / (2.0 * PI) + 0.5;
float v = asin(TexCoords.y) / PI + 0.5;
/* Sample noise value from cloud texture. */
float noise = texture(u_CloudTexture, vec2(u, v)).r;
/* Create soft-edged clouds from the noise. */
float cloudAlpha = smoothstep(0.5, 0.8, noise);
/* Some simple lighting. */
vec3 normal = normalize(TexCoords);
float diffuse = max(dot(normal, -u_LightDir), 0.0);
vec3 cloudColor = vec3(1.0) * (diffuse * 0.5 + 0.5); /* Add some ambient light. */
/* Cloud colour is white. it's transparency is determined by alpha. */
FragColor = vec4(cloudColor, cloudAlpha);
}