Ramp Lighting

Based on http://wiki.unity3d.com/index.php/TeamFortress2Shader

Also includes specular highlighting and rim lighting.

Ramp textures must have “Repeat” import parameter set to “Disabled”, otherwise they will generate artifacts. Screenshots include example ramps.

For GLES3, change DIFFUSE_LIGHT to the following(Might need further adjustments but this seems to work well enough): DIFFUSE_LIGHT += ALBEDO * lit+((spec*(1.0f-ROUGHNESS))*lit)+((rim*ALBEDO)*lit);

Shader code
uniform sampler2D LightRamp;

void fragment() {
	ALBEDO = texture(Albedo, UV).rgb;
	ROUGHNESS = Roughness;
	NORMALMAP = texture(BumpMap, UV).rgb;

void light() {
	vec4 rampTex = texture(LightRamp, vec2(dot(LIGHT, NORMAL))-(1.0f-ATTENUATION.xy));
	float spec = max(pow(dot(NORMAL, normalize(LIGHT + VIEW)), (1.0f-ROUGHNESS)*128.0f),0.0f)*((rampTex.r+rampTex.g+rampTex.b)/3.0f);
	float rim = max(RimDist - dot(VIEW, NORMAL), 0.0f)*RimPower;
	vec3 lit =  min(rampTex.rgb * LIGHT_COLOR, 1.0f);
	DIFFUSE_LIGHT = ALBEDO * lit+((spec*(1.0f-ROUGHNESS))*lit)+((rim*ALBEDO)*lit);
lighting, ramp, ramp lighting
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.

More from Ed3800

3-point texture filtering

Related shaders

PSX Shader with Vertex Lighting

Drop-in PBR 2d lighting system with soft shadows and ambient occlusion

Notify of

1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
6 months ago

The code here isn’t complete, please add the entire shader.

For example: shader_type, Albedo, BumpMap, RimDist are missing declarations.