34 lines
1014 B
GLSL
34 lines
1014 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. */
|
|
|
|
/* Fade out clouds at the poles to hide pinching. */
|
|
float poleFade = 1.0 - abs(TexCoords.y);
|
|
cloudAlpha *= smoothstep(0.0, 0.2, poleFade);
|
|
|
|
/* Cloud colour is white. it's transparency is determined by alpha. */
|
|
FragColor = vec4(cloudColor, cloudAlpha);
|
|
}
|