// PAY DAY THE HEIST - DOUBLE IMAGING AND LIGHTS IN ALL LEVELS
// HELIXMOD FIX BY MIKE_AR69
// Generated by Microsoft (R) HLSL Shader Compiler 9.24.950.2656
//
// Parameters:
//
//   float4x4 camera_inv_view_matrix;
//   float ref_omni_scale;
//   float3 ref_unprojection;
//   float3 render_target_texel_offset;
//   float4x4 view_proj_matrix;
//   float3 vp_offset;
//   float3 vp_size;
//
//
// Registers:
//
//   Name                       Reg   Size
//   -------------------------- ----- ----
//   view_proj_matrix           c0       4
//   camera_inv_view_matrix     c4       3
//   ref_omni_scale             c7       1
//   render_target_texel_offset c8       1
//   ref_unprojection           c9       1
//   vp_offset                  c10      1		
//   vp_size                    c11      1		
//

    vs_3_0
def c200, 0, 0, 0.0625, 0
    def c12, 1, 2, -1, 0.5
dcl_2d s0
    dcl_position v0
	
    dcl_position o0
	dcl_texcoord o1
    dcl_texcoord1 o2


    mul r0.xyz, c7.x, v0
    mov r0.w, c12.x

dp4 r4.x, r0, c0			//r0 is a WORLD coord
dp4 r4.y, r0, c1
dp4 r4.z, r0, c2
dp4 r4.w, r0, c3			//r4 is a PROJ coord

mov r3, r4   				//r3 is unshifted

mov r14.x, c250.x
if_eq r14.x, c200.w
	texldl r12, c200.z, s0
	add r12.y, r4.w, -r12.y
	mul r12.x, r12.x, r12.y
	add r4.x, r4.x, -r12.x		//r4 is shifted
endif
  
	mul r2.xy, r3.xy, c9		//"ref_unprojection"
	mov r2.z, r3.w


//::STEREO VERSION of r2
mul r5.xy, r4.xy, c9	
mov r5.z, r4.w
							
	mov r1.xy, r3.xy
	mov r1.z, r3.z				
//::STEREO VERSION of r1
mov r6.xy, r4.xy
mov r6.z, r4.z

//-----------------------------
	//Swap r2 for r5  		**** THIS FIXES MOST OF THE PROBLEMS
							//BUT introduces issue with light clipping
    dp3 o2.x, r5, c4		
    dp3 o2.y, r5, c5		
    dp3 o2.z, r5, c6

	mov r0.yw, c12			//c12, 1, 2, -1, 0.5

    mov r2.xy, c11			//W and H ?
//::STEREO VERSION of r2
mov r5.xy, c11

    mad r0.xy, c10, r0.y, r2
		//r0.x 	= r0.y * c10.x + r2.x
		//		= (-1) * c10.x + W
		//		= W - Xoffset
		//r0.y 	= (-1) * c10.y + r2.y
		//		= H - Yoffset
	
    add r0.xy, r0, c12.z
		//r0.x = r0.x - 1 = W - Xoffset - 1
		//r0.y = r0.y - 1 = H - Yoffset - 1
		
    mul r0.xy, r2.z, r0
		//r0.x = r0.x*DEPTH
		//r0.y = r0.y*DEPTH
		
    mad r2.x, r1.x, c11.x, r0.x
		//r2.x = r1.x*W + r0.x
		//r2.x = r3.x*W + (W - Xoffset - 1)*DEPTH

    mad r2.y, r1.y, -c11.y, r0.y
		//r2.y = -r3.y*H + (H - Yoffset - 1)*DEPTH

    add r0.xy, r0.w, c8			//r0.w = c12.w = 0.5
		//r0.x = 0.5 * c8.x 	//render_target_texel_offset
		//r0.y = 0.5 * c8.y 	//render_target_texel_offset

    add r0.z, r2.z, r2.z
		//r0.z = 2*r2.z
		//r0.z = 2*DEPTH
	
    mov r1.w, r2.z
		//r1.w = DEPTH

//::STEREO VERSION of r1
mov r6.w, r5.z	
	
	mad o1.xy, r0, r0.z, r2
		//o1.x 	= r0.z * r0.x + r2.x
		//		= DEPTH * c8.x + r3.x * W + (W - Xoffset - 1)*DEPTH
		//o1.y  = DEPTH * c8.y + r3.y * H + (H - Yoffset - 1)*DEPTH

    mov o1.z, r1.z
	mov o1.w, r0.z

//-----------------------------
	mov o0, r6 //r1    //******STEREO SHIFTED PROJ COORD   
	mov o2.w, r6.w //r1.w
  
// approximately 25 instruction slots used
