ps_2_0
// fetch coordinates from texture 0
dcl t0
dcl t1   //ray orig
dcl t2   //ray dir
dcl t3   //ray 2 orig
dcl t4   //ray 2 dir
dcl_2d s0
texld r0,t0,s0
mul r0,r0,c2         // *256
sub r6,r0,c3         // -(128,128,128,0)
// ray 1
sub r2,r6,t1         // e' = p - q
nrm r1,r2            // e = norm(e');
dp3 r2,r2,r2         // a = e' dot e'
dp3 r3,r1,t2         // b = e dot dir
mul r3.w,r3.w,r3.w   // b = b*b
add r3.x,r2.w,r6.w   // c = a + r*r
rcp r3.x,r3.x        // c = 1/c
mul r2.x,r2.w,r3.x   // a = a * c
sub r0.y,r2.x,r3.w   // out = a - b   - this is negative if sphere is intersect
mul r5,r0,c3         // *128
// ray 2
sub r2,r6,t3         // e' = p - q
nrm r1,r2            // e = norm(e');
dp3 r2,r2,r2         // a = e' dot e'
dp3 r3,r1,t4         // b = e dot dir
mul r3.w,r3.w,r3.w   // b = b*b
add r3.x,r2.w,r6.w   // c = a + r*r
rcp r3.x,r3.x        // c = 1/c
mul r2.x,r2.w,r3.x   // a = a * c
sub r0.x,r2.x,r3.w   // out = a - b   - this is negative if sphere is intersect
mul r5.x,r0.x,c3.x
// result
mov oC0,r5
