#include "Common.xpsh"
tex t0 // colormap
tex t1 // dirtmap
tex t2 // envmap
tex t3 // lightmap
// scale sun light intensity with sun lightmap and add to diffuse
mad v0.rgb, v0.a, t3.rgb, v0.rgb
// create metallic specular
// create specular highlight
+ xmma_x2 r1.a, discard.a, t2.a, t2.a, 1-zero, -HALF, 1-zero
// create dirt color
lrp t1.rgb, 1-t1.rgb, DIRT_MIN_COLOR, DIRT_MAX_COLOR
// scale metallic specular with sun lightmap
+ mul r1.a, r1.a, t3.a
// apply lighting to colormap
// apply lighting to dirtmap
xmma_x2 r0.rgb, t1.rgb, discard.rgb, t0.rgb, v0.rgb, t1.rgb, v0.rgb
// scale highlight with sun lightmap
// scale metallic specular with specular scale
+ xmma t2.a, r1.a, discard.a, t2_sat.a, t3.a, r1.a, SPECULAR_SCALE
// create specular
// scale highlight with highlight color
// scale metallic specular with colormap
xmma discard.rgb, discard.rgb, r1.rgb, t2.a, HIGHLIGHT_COLOR, r1.a, t0.rgb
// scale envmap with fresnel and add to specular
mad r1.rgb, t2.rgb, v1.a, r1.rgb
// scale damage intensity with damagemap
+ mul t0.a, 1-t0.a, v1.b
// add colormap and specular
// scale colormap with damage
// scale specular with damage
xmma discard.rgb, discard.rgb, r0.rgb, r0.rgb, 1-t0.a, r1.rgb, 1-t0.a
// scale dirt intensity with dirtmap
+ mul t1.a, DIRT_INTENSITY, t1.a
// lerp between colormap+specular and dirtmap with dirt intensity
lrp r0.rgb, 1-t1.a, r0.rgb, t1.rgb
xfc fog.a, r0.rgb, fog.rgb, zero, zero, zero, 1-zero