Moon Phase

Show a pseudo-moon and progress it through its phases. You need to use material.set_shader_parameter("cval", cval) in your Godot code with something like process’s delta.

Shader code
shader_type canvas_item;

uniform float cval = 0.0;
uniform vec4 shade = vec4(0, 0, 0, 255);
uniform float shade_radius = 0.5;

void fragment() {
	vec2 center = vec2(cval, 0.5);
	
	COLOR.a = 0.0;

	float dist = distance(UV, vec2(0.5, 0.5));
	if(dist < shade_radius) {
		COLOR = vec4(255, 255, 255, 255);
	}

	dist = distance(UV, center);
	if(dist < shade_radius) {
		COLOR = shade * COLOR.a;
	}
}
Tags
moon
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

Sea and Moon

Moon Shader 2D All Phases and Roughened Shadow

Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
LambBrainz
1 year ago

Yessss, finally. Thank you so much