diff --git a/assets/shaders/cloud.frag b/assets/shaders/cloud.frag index 3a0b416..9efd7ad 100644 --- a/assets/shaders/cloud.frag +++ b/assets/shaders/cloud.frag @@ -24,6 +24,10 @@ void main() { 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); } diff --git a/src/graphics/renderer.cpp b/src/graphics/renderer.cpp index 08d861e..0091a1f 100644 --- a/src/graphics/renderer.cpp +++ b/src/graphics/renderer.cpp @@ -226,7 +226,18 @@ unsigned int Renderer::_generate_cloud_texture(void) { for(int y = 0; y < height; y++) { 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; } }