ps_2_0
// counts spheres colors for one point light
// tex0 is spheres result texture (32F)
// tex1 is spheres desc texture (32F)
// tex2 is spheres colors texture (argb)
// tex3 is texture mapped pixels
// tex5 is shadow cast render results
// tex6 is sphere normals
// tex7 is sphere origins
// c0 is light source
// c1.x is number of spheres = width of spheres desc and colors textures
// c2 - ambient light
// output is argb
def c5,0,0,0,0
def c6,99.9,256,100,256
def c7,-128,-128,-128,0
def c8,0.9,0,0,0
dcl t0
dcl_2d s0
dcl_2d s1
dcl_2d s2
dcl_2d s3
dcl_2d s5
dcl_2d s6
dcl_2d s7
texld r0,t0,s0
mul r0.g,r0.g,c6.z
mov r2.y,c5.x
mov r2.x,r0.b      // sphere index from blue component
sub r3,c8.x,r0.b
texkill r3
rcp r3.x,c1.x
mul r2.x,r2.x,c6.w
frc r2.z,r2.x
sub r2.x,r2.x,r2.z
mul r2.x,r2.x,r3.x
texld r1,r2,s2       // get indexed sphere color
texld r2,t0,s3       // get texture mapped sphere pixels
mul r1,r1,r2
texld r5,t0,s6     // get sphere normal
texld r7,t0,s7     // get sphere intersect pos
sub r6,c0,r7
nrm r4,r6
dp3 r2.x,r4,r5
mov r3,r2.x
texld r2,t0,s5
mul r2.g,r2.g,c6.z
sub r2.g,r2.g,c6.r
cmp r3,r2.g,r3,c5 // apply shadow cast render result
abs r3,r3
add r2,r3,c2
mul r1,r1,r2        // apply cosine shade
sub r0.g,r0.g,c6.r
//mov r1,r5
cmp r1,r0.g,c5,r1  // black pixel on great distance
mov oC0,r1
