GradientTexture Shader

A simple shader that uses a GradientTexture1D to control the color of the mesh. Similar to Toon Shading or Cell Shading, but allows the developer to be flexible to make stylistic choices. If you desire to have outlines, you can add an outline shader in the “Next Pass” property.

Shader code
// Created by Ryan Remer
// https://godotshaders.com/shader/gradienttexture-shader/
shader_type spatial;

uniform sampler2D color_ramp;

void light() {
	float dotnl = dot(NORMAL, LIGHT);
	float sample_position = max((dotnl + 1.0) / 2.01, 0.01);
	vec4 ramp_light = texture(color_ramp, vec2(sample_position, 0.0));
	vec3 diffuse_light = ramp_light.rgb * clamp(LIGHT_COLOR * ATTENUATION, vec3(0,0,0), vec3(1,1,1));
	DIFFUSE_LIGHT = max(diffuse_light, DIFFUSE_LIGHT);
}
Tags
cell shading, gradient, toon
The shader code and all code snippets in this post are under MIT license and can be used freely. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

2.5d sprite shader

Useful Gradient Effects All-in-one Shader

Water Shader

Subscribe
Notify of
guest

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
ilies
ilies
7 months ago

love it <3

lvar999
lvar999
7 months ago

nice

clid
clid
1 month ago

tested on 4.3, if your shader don´t work in world scene, add this tag ->

render_mode ambient_light_disabled;