// Pixel shader for shadows maps
// with 4 higher than 8-bit precision samples
// and percentage closer filtering


ps.1.4
// Intensity in shadow
def c0, 0, 0, 0, 0
// Intensity in the light
def c1, 1, 1, 1, 1
// Fudge factor for back face occlusion
def c2, 0.2, 0, 0, 0
// Sample weights (1/4)
def c3, 0.25, 0.25, 0.25, 0.25
// Ambient color
def c4, 0.25, 0.25, 0.25, 0.5
def c5, 1.0, 0.0, 0.0, 0.0
;def c5, 0.5, 1.0, 0.0, 0.0

// Fetch 4 shadow map samples
;tex t0
texld r0,t0
// Light space depth from vertex shader
;texcoord t1
texcrd r1.rgb,t1
mov r2,r0


// Unpack sample 0
dp3 r0.rgba,r0,c5
// Compare shadow map samples to surface depth
sub r0, r1.r, r0
cmp r0, -r0, c1, c0

;mov r0,t1
// Occlude back facing prims with respect to light
sub r5.r, v0.a, c2.r
cmp r0, r5.r, r0, c0
// Modulate with diffuse and add ambient
;mad r0, r0, v0, c4
;mov r0.rgb,r1