ps_2_0
// intersects a triangle
// inputs:
//   tex0 - ray origins
//   tex1 - ray directions
//   index of triangle in v0.b (color value) - max 255 !!
// outputs index of sphere in blue component
// outputs distance in green component
// outputs coordinates (u,v) in red (u) and alpha (v) components
// output buffer format should be A32R32G32B32F
// equation is: v1*u + v2*v - t*dir = A - rayorig
def c7,-128,-128,-128,0
def c8,256,256,256,256
def c9,1,-1,0.01,10
dcl v0
dcl t0
dcl t1
dcl t2
dcl t3
dcl_2d s0
dcl_2d s1
texld r0,t0,s0
mov r7,c7
mad r0,r0,c8,r7
texld r1,t0,s1
mad r1,r1,c8,r7       // ray parameters loaded
mov r7,t1
sub r0,r0,r7          // ro -= A
sub r2,t2,r7          // b = B-A
sub r3,t3,r7          // c = C-A
//mov r2,c1
//mov r3,c2
crs r4.xyz,r2,r3          // d = b cross c
dp3 r5.w,r4,r1            // main det
mul r5.w,r5.w,c9.y
crs r6.xyz,r1,r0
dp3 r5.x,r6,r3            // det for u ( (dir x ro)*v2 )
mul r5.x,r5.x,c9.y
dp3 r5.y,r6,r2            // det for v ( (dir x ro)*v1 )
dp3 r5.z,r4,r0            // det for t ( (v1 x v2)*ro )
mul r5.z,r5.z,c9.y
rcp r6.w,r5.w
mul r5,r5,r6.w    // /det
mov r7,r5
add r7.z,r7.x,r7.y
mad r7.z,r7.z,c9.y,c9.x
texkill r7             // die if u or v is less than zero, or if their sum is greater than one.
mov r0.b,v0.b
abs r0.g,r5.z
mul r0.g,r0.g,c9.z
mov r0.r,r5.x
mov r0.a,r5.y
mov oDepth,r0.g
mov oC0,r0
