ps_2_0
// intersects a bounded plane
// inputs:
//   tex0 - ray origins
//   tex1 - ray directions
//   tex2 - stencil map
//   index of object in c0.x
//   triangle points in c1,c2,c3
// 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
def c10,-1,1,0.5,0.01
dcl v0
dcl t0
dcl_2d s0
dcl_2d s1
dcl_2d s2
texld r0,t0,s0
texld r1,t0,s1
mov r7,c1
sub r0,r0,r7          // ro -= A
sub r2,c2,r7          // b = B-A
sub r3,c3,r7          // c = C-A
//mov r2,c2
//mov r3,c3
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.
    mul r7,r5,r5
    add r7.x,r7.x,r7.y
    sub r7,c9.x,r7.x
    texkill r7
    mul r6,r5,c10.x
    add r6,r6,c10.y
    mul r6,r6,c10.z
    texld r8,r6,s2
    sub r8,r8,c10.w
    texkill r8
mov r0.b,c0.x
abs r0.g,r5.z
mul r0.g,r0.g,c9.z
mov r0.r,r6.x
mov r0.a,r6.y
mov oDepth,r0.g
mov oC0,r0

