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

Thick 3D Screen Space – Depth – & Normal – Based Outline Shader.

Glass shader

Decal shader 4.0 port

Subscribe
Notify of
guest

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
ilies
ilies
9 months ago

love it <3

lvar999
lvar999
8 months ago

nice

clid
clid
2 months ago

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

render_mode ambient_light_disabled;

TheYellowArchitect
26 days ago

What type is the color ramp variable? Anything I add (e.g. GradientTexture2D) does no difference to the scene.
I even added the tag render_mode ambient_light_disabled;