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

Albedo Terrain Mix Shader

Depth Edge Highlights Shader

Voronoi Guard Effect Shader

Subscribe
Notify of
guest

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

love it <3

lvar999
lvar999
3 months ago

nice