Pixel shader logic for mixing colors

From wowdev
Jump to: navigation, search

WoW combines colors of textures in shader. The actual formula used depends on shader used.

Symbols

vec4 tex1 - color from first texture
vec4 tex2 - color from second texture
vec4 submeshColor - value for current animation and animation time from M2Color (M2Color.color lands into submeshColor.rgb, M2Color.alpha goes into submeshColor.a). If M2Color is not present in M2 file, this values is vec4(1.0, 1.0, 1.0, 1.0)
float transparency - value for current animation and animation time from M2TextureWeight. If M2TextureWeight doesnt exists in M2 file, this value is 1.0
vec4 diffuseColor - value:

  • for M2 spawned from MDDF chunk of Adt: vec4(1.0, 1.0, 1.0, 1.0);
  • for M2 spawned from MODD chunk of WMO:

bool uUseDiffuseColor:

mix(a,b,c) - function that calculates result value as a*(1.0-c) + b*c. Same formula in different notation with less multiplications: (b - a) * c + a
vec4 meshResColor - the combined color of several variables:

if (uUseDiffuseColor) {
    meshResColor = vec4(submeshColor.rgb * diffuseColor.bgr, submeshColor.a * transparency);
} else {
    meshResColor = vec4(submeshColor.rgb, submeshColor.a * transparency);
}

vec4 finalColor - the result of combining

M2 shaders

Combiners_Opaque

finalColor.rgb = tex1.rgb * meshResColor.rgb;
finalColor.a = meshResColor.a;

Combiners_Decal

finalColor.rgb = (meshResColor.rgb - tex1.rgb) * meshResColor.a + tex1.rgb;
finalColor.a = meshResColor.a;

Combiners_Add

finalColor.rgba = tex1.rgba + meshResColor.rgba;

Combiners_Mod2x

finalColor.rgb = tex1.rgb * meshResColor.rgb * 2.0;
finalColor.a = tex1.a * meshResColor.a * 2.0;

Combiners_Fade

finalColor.rgb = (tex1.rgb - meshResColor.rgb) * meshResColor.a + meshResColor.rgb;
finalColor.a = meshResColor.a;

Combiners_Mod

finalColor.rgba = tex1.rgba * meshResColor.rgba;

Combiners_Opaque_Opaque

finalColor.rgb = tex1.rgb * tex2.rgb * meshResColor.rgb;
finalColor.a = meshResColor.a;

Combiners_Opaque_Add

finalColor.rgb = tex2.rgb + tex1.rgb * meshResColor.rgb;
finalColor.a = meshResColor.a + tex1.a;

Combiners_Opaque_Mod2x

finalColor.rgb = tex1.rgb * meshResColor.rgb * tex2.rgb * 2.0;
finalColor.a  = tex2.a * meshResColor.a * 2.0;

Combiners_Opaque_Mod2xNA

finalColor.rgb = tex1.rgb * meshResColor.rgb * tex2.rgb * 2.0;
finalColor.a  = meshResColor.a;

Combiners_Opaque_AddNA

finalColor.rgb = tex2.rgb + tex1.rgb * meshResColor.rgb;<br>
finalColor.a = meshResColor.a;

Combiners_Opaque_Mod

finalColor.rgb = tex1rgb * tex2.rgb * meshResColor.rgb;<br>
finalColor.a = tex2.a * meshResColor.a;

Combiners_Mod_Opaque

finalColor.rgb = tex1.rgb * tex2.rgb * meshResColor.rgb;
finalColor.a = tex1.a;

Combiners_Mod_Add

finalColor.rgba = tex2.rgba + tex1.rgba * meshResColor.rgba;

Combiners_Mod_Mod2x

finalColor.rgba = tex1.rgba * tex2.rgba * meshResColor.rgba * 2.0;

Combiners_Mod_Mod2xNA

finalColor.rgb = tex1.rgb * tex2.rgb * meshResColor.rgb * 2.0;
finalColor.a = tex1.a * meshResColor.a;

Combiners_Mod_AddNA

finalColor.rgb = tex2.rgb + tex1.rgb * meshResColor.rgb;
finalColor.a = tex1.a * meshResColor.a;

Combiners_Mod_Mod

finalColor.rgba = tex1.rgba * tex2.rgba * meshResColor.rgba;

Combiners_Add_Mod

finalColor.rgb = (tex1.rgb + meshResColor.rgb) * tex2.a;
finalColor.a = (tex1.a + meshResColor.a) * tex2.a;

Combiners_Mod2x_Mod2x

finalColor.rgba = tex1.rgba * tex2.rgba * meshResColor.rgba * 4.0

Combiners_Opaque_Mod2xNA_Alpha

finalColor.rgb = meshResColor.rgb * ( (tex1.rgb - tex1.rgb * tex2.rgb) * tex1.a + tex1.rgb * tex2.rgb);
finalColor.a = meshResColor.a;

Combiners_Opaque_AddAlpha

finalColor.rgb = meshResColor.rgb * tex1.rgb + tex2.rgb * tex2.a;
finalColor.a = meshResColor.a;

Combiners_Opaque_AddAlpha_Alpha

finalColor.rgb = meshResColor.rgb * tex1.rgb + (tex2.rgb * tex2.a * (1.0 - tex1.a));
finalColor.a = meshResColor.a;

Combiners_Opaque_Mod2xNA_Alpha_Add

Combiners_Mod_AddAlpha

finalColor.rgb = meshResColor.rgb * tex1.rgb + tex2.rgb * tex2.a
finalColor.a = meshResColor.a * tex1.a;

Combiners_Mod_AddAlpha_Alpha

float addMapBrightness = (((0.300000012 * tex2.r) + (0.589999974 * tex2.g)) + (0.109999999 * tex2.b));

finalColor.rgb = meshResColor.rgb * tex1.rgb + (tex2.rgb * tex2.a * (1.0 - tex1.a) + ((tex2.xyz * tex2.a) * (1.0 - tex1.a));
finalColor.a = meshResColor.a * (tex1.a + (tex2.a * addMapBrightness));

Combiners_Opaque_Alpha_Alpha

finalColor.rgb = meshResColor.rgb * mix(mix(tex1.rgb, tex2.rgb, tex2.a), tex1.rgb, tex1.a);
finalColor.a = meshResColor.a;

Combiners_Opaque_Mod2xNA_Alpha_3s

Combiners_Opaque_AddAlpha_Wgt

Combiners_Mod_Add_Alpha

Combiners_Opaque_ModNA_Alpha

Combiners_Mod_AddAlpha_Wgt

Combiners_Opaque_Mod_Add_Wgt

Combiners_Opaque_Mod2xNA_Alpha_UnshAlpha

Combiners_Mod_Dual_Crossfade

Combiners_Opaque_Mod2xNA_Alpha_Alpha

Combiners_Mod_Masked_Dual_Crossfade

Combiners_Opaque_Alpha

Guild

Guild_NoBorder

Guild_Opaque

Combiners_Mod_Depth

Illum

WMO shaders