Smooth Radial Gradient

Henlo! This is a shader I made to create a smooth stepped radial gradient in godot. I’m using it to create a planet atmosphere, but you might use it/ adapt it to create shader based lights, circular auras, scene vignettes, Halos, you name it. 

How to use it:

Just create a new shader material into a colorRect Node and you’re good to go.

Variables:

Colors: You can change them in the inspector. They will be the colors of your gradient from center to end.

Steps: They control where the radial colores are. Step 1 controls the position of color 1, step 2 the position of color 2 and so on. if you make the steps really close to each other, the gradient will be small. I used it to create the atmosphere border, for example.

Size: Contols the overall size of your gradient.

Squishness: This variable constrols the size of one axis of your gradient, so you can make oval shapes as well.

 

Enjoy!

Shader code
shader_type canvas_item;
render_mode blend_add; //Comment this if you want another render mode.
uniform vec2 center = vec2(0.5);
uniform float size: hint_range(0.0,5.0) = 1.0; //change size to well, change the size of your gradient
uniform vec2 squishness = vec2(1.0); // how squashed your gradient is

//choose colors in the inspector
uniform vec4 color1 : hint_color;
uniform vec4 color2 : hint_color;
uniform vec4 color3 : hint_color;
uniform vec4 color4 : hint_color;
uniform vec4 color5 : hint_color;
uniform vec4 color6 : hint_color;

//choose how far the colors are from each other in the inspector
uniform float step1 : hint_range(0.0,1.0) = 0.159;
uniform float step2 : hint_range(0.0,1.0) = 0.182;
uniform float step3 : hint_range(0.0,1.0) = 0.233;
uniform float step4 : hint_range(0.0,1.0) = 0.264;
uniform float step5 : hint_range(0.0,1.0) = 0.265;
uniform float step6 : hint_range(0.0,1.0) = 0.266;

void fragment() {
	float dist = distance(center*squishness,UV*squishness);
	vec4 color = mix(color1, color2, smoothstep(step1*size, step2*size, dist));
	color = mix(color, color3, smoothstep(step2*size, step3*size, dist));
	color = mix(color, color4, smoothstep(step3*size, step4*size, dist));
	color = mix(color, color5, smoothstep(step4*size, step5*size, dist));
	color = mix(color, color6, smoothstep(step5*size, step6*size, dist));
	COLOR = color;
}
Tags
atmosphere, gradient, radial
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

Smooth Color Gradient

Smooth outline 2D

Smooth outline 2D with enable disable system

Subscribe
Notify of
guest

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
FDM
FDM
3 years ago

Could you make a square/rectangular variant, or as border around a sprite?

Last edited 3 years ago by FDM
morningking
morningking
3 years ago

thanks this is so helpfull for me. thank you for sharing bro.

kelsylol
kelsylol
5 months ago

Hi can you provide the paramaters to generate that last image? I want to try to create a lightmask