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);
}
The code here isn’t complete, please add the entire shader.
For example: shader_type, Albedo, BumpMap, RimDist are missing declarations.