Banded Lighting Shader (godot 3.x)

ported from Jordan Stevens

https://www.jordanstevenstechart.com/lighting-models

Shader code
shader_type spatial;
render_mode ambient_light_disabled;

uniform sampler2D _albedo:hint_albedo;
varying vec4 vector_ws;
varying vec4 vector_os;
uniform float _lightSteps:hint_range(0.0, 256.0, 2.0)=1.0;

void vertex()
{
	vector_os.xyz = VERTEX;
	vector_ws= WORLD_MATRIX* vec4(vector_os.xyz,1.0);

}

void light()

{
vec3 i = ATTENUATION;
vec3 l = LIGHT;
vec3 n = NORMAL;

vec3 viewDirection= normalize(CAMERA_MATRIX[3]-vector_ws).xyz;

float roughness=ROUGHNESS;




vec3 nDotL = max(0.0, dot(n, l)) * i;
vec3 vDotL = max(0.0, dot(viewDirection, l)) * i;

float lightBandsMultiplier = _lightSteps/256.0;
float lightBandAdditive = _lightSteps/2.0;

vec3 bandedNDotL=(floor((nDotL*256.0+lightBandAdditive)/_lightSteps))*lightBandsMultiplier;
vec3 lightingModel = bandedNDotL *ALBEDO;
vec3 attenuation = ATTENUATION;
vec3 attenColor = i * LIGHT_COLOR;
vec4 finalDiffuse = vec4(lightingModel*attenColor,1);


DIFFUSE_LIGHT += finalDiffuse.xyz;
SPECULAR_LIGHT +=finalDiffuse.xyz;
}
Live Preview
Tags
banded, banded-lighting, jordan stevens, lighting, 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.

More from FP2

Related shaders

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments