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.

Shader code
shader_type spatial;
render_mode specular_disabled;

uniform float Roughness : hint_range(0f,1f) = 0.5f;
uniform sampler2D Albedo : hint_white;
uniform sampler2D BumpMap : hint_normal;
uniform float RimDist : hint_range(0f, 1f);
uniform float RimPower : hint_range(0f, 5f);
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))-(1f-ATTENUATION.xy));
	float spec = max(pow(dot(NORMAL, normalize(LIGHT + VIEW)), (1f-ROUGHNESS)*128f),0f)*((rampTex.r+rampTex.g+rampTex.b)/3f);
	float rim = max(RimDist - dot(VIEW, NORMAL), 0f)*RimPower;
	vec3 lit =  min(rampTex.rgb * LIGHT_COLOR, 1f);
	DIFFUSE_LIGHT = ALBEDO * lit+((spec*(1f-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

Inline Feedbacks
View all comments