Created
March 26, 2025 22:35
-
-
Save partybusiness/519083d02124d6c2f173fca76ac963da to your computer and use it in GitHub Desktop.
Godot sky shader that displays the moon based on light direction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shader_type sky; | |
uniform sampler2D moon_texture:source_color, repeat_disable; | |
// updirection of moon texture will try to align with this | |
uniform vec3 north = vec3(0, 0, -1); | |
void sky() { | |
vec3 light_dir = normalize(-LIGHT0_DIRECTION); | |
vec3 side_dir = normalize(cross(light_dir, north)); | |
vec3 up_dir = normalize(cross(light_dir, side_dir)); | |
vec3 diff = normalize(EYEDIR) + light_dir; //difference between view dir and moon dir | |
vec2 moon_uv = (vec2(dot(side_dir, diff), dot(up_dir, diff)) * 5.0) + 0.5; | |
vec4 moon = texture(moon_texture, moon_uv); | |
moon.rgb = moon.rgb * clamp(dot(normalize(EYEDIR), light_dir) * -2.0, 0.0, 1.0); // make sure only one moon | |
COLOR = vec3(0, 0, 0) + moon.rgb; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment