Godot Version
4.7
Question
I’ve been trying to make a cloud shader for my game. The way it works is by sampling a noise texture in fragment() and thresholding it to ALPHA. This shader is applied to a quad floating above the player, and I control the cloud scrolling through sampling it’s world position in vertex().
shader_type spatial;
group_uniforms cloud_cover;
global uniform float cloud_cover_scale;
global uniform float cloud_cover_intensity;
global uniform vec2 cloud_scroll_speed;
global uniform sampler2D cloud_noise_texture;
global uniform float cloud_cover_threshold;
uniform float pixelation : hint_range(16.0, 512.0, 1.0) = 512;
varying vec3 v_world_pos;
void vertex() {
v_world_pos = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
}
void fragment() {
vec2 cloud_uv = (v_world_pos.xz + (cloud_scroll_speed * TIME)) * cloud_cover_scale;
cloud_uv = floor(cloud_uv * pixelation) / pixelation;
float cloud_cover = texture(cloud_noise_texture, cloud_uv).r;
cloud_cover = (cloud_cover >= cloud_cover_threshold) ? 1.0 : 0.0;
ALPHA_SCISSOR_THRESHOLD = 1.0;
ALPHA = cloud_cover;
}
In order to compensate the fact that this is not an endless plane and the sun rotates (which would make the clouds stop casting shadows at certain angles) I rotate the whole mesh around a pivot centered on the player to always face the sun. However, this distorts the cloud shapes due to how I sample the noise texture in the shader.
Is there any way to change how the noise is sampled to stop this stretching? Like always sampling it as if the mesh is parallel to the ground so the shapes are consistent even when rotating?
I’m very new to shaders and most of what I know is from reverse engineering others I find around and smashing together pieces of YouTube tutorials.

