Shading Technique - Palette Coloring

From Horde3D Wiki
Jump to: navigation, search

Explanation of the Technique

By definition palette recoloration is the use of defined colors that replace or modify any other colors within their specified domain. The best example in use is team colors in real-time strategy titles or the color variations of enemies in role-playing games.

Example Fragment Shader

GLSL Code
uniform vec4 Rkey;
uniform vec4 Bkey;
uniform vec4 Gkey;
uniform vec4 Akey;
uniform sampler2D tex0;
uniform sampler2D tex1;
varying vec3 tsbNormal;
varying vec4 pos, vsPos;
varying vec2 texCoords;

void main( void )
{
	vec3 albedo = texture2D( tex0, texCoords ).rgb;
	vec3 outAl;
	float luminous;
	vec4 blender = texture2D( tex1, texCoords ).rgba;
	outAl = (Rkey.rgb * blender.r) + 
		(Bkey.rgb * blender.b) + 
		(Gkey.rgb * blender.g) + 
		(Akey.rgb * blender.a);
	luminous = (Rkey.a * blender.r) +
		(Bkey.a * blender.b) +
		(Gkey.a * blender.g) +
		(Akey.a * blender.a);
	vec3 final = albedo-luminous + outAl-luminous;
	gl_FragColor.rgb =
		calcPhongSpotLight( pos.xyz, normalize( tsbNormal ), final, 0.5, -vsPos.z );
}

Explanation of the Fragment Shader

This technique uses an RGBA blend map to define the regions and intensities at which the uniforms are used for color replacement. The uniforms can be thought as being RGBL (Red, Green, Blue, Luminance/Brightness).

The principle concept is that the base texture is colored based solely by value (in reference to the "art" definition of value as being the variance of light and dark in a composition) or color that will be unaltered. The uniform is adapted to the value and then adjusted by its luminosity in order to enable proper adjustment of the value of the RGB color.

To Do List for This Article

- Cut down on esoteric terms or explain those that are esoteric
- Explain the not so obvious reasons behind the choice of math operations
- Add pictures!!