[Add] Implement tileable and pile-corrected clouds.

This commit is contained in:
Ritchie Cunningham 2025-09-18 20:44:25 +01:00
parent a1c214caec
commit 19a431ccc8
2 changed files with 16 additions and 1 deletions

View File

@ -24,6 +24,10 @@ void main() {
float diffuse = max(dot(normal, -u_LightDir), 0.0); float diffuse = max(dot(normal, -u_LightDir), 0.0);
vec3 cloudColor = vec3(1.0) * (diffuse * 0.5 + 0.5); /* Add some ambient light. */ 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. */ /* Cloud colour is white. it's transparency is determined by alpha. */
FragColor = vec4(cloudColor, cloudAlpha); FragColor = vec4(cloudColor, cloudAlpha);
} }

View File

@ -226,7 +226,18 @@ unsigned int Renderer::_generate_cloud_texture(void) {
for(int y = 0; y < height; y++) { for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) { for(int x = 0; x < width; x++) {
float noise_val = noise.GetNoise((float)x, (float)y); const float R = 1.0f; /* Major radius of the torus. */
const float r = 0.5f; /* Minor radius of the torus. */
float u = (float)x / width * 2.0f * M_PI;
float v = (float)y / height * 2.0f * M_PI;
float nx = (R + r * cos(v)) * cos(u);
float ny = (R + r * cos(v)) * sin(u);
float nz = r * sin(v);
const float noise_scale = 45.0f;
float noise_val = noise.GetNoise(nx * noise_scale, ny * noise_scale, nz * noise_scale);
buffer[y*width+x] = (noise_val + 1.0f) / 2.0f; buffer[y*width+x] = (noise_val + 1.0f) / 2.0f;
} }
} }