//Shadows/Lights
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
// Parameters:
//
//   sampler2D Base;
//   sampler2D GBuffer1;
//   sampler2D GBuffer2;
//   sampler2D GBuffer3;
//   sampler2D GBuffer4;
//   sampler2D Shadow;
//   float4x4 global_LightPropertyMatrix;
//   float4 global_ViewPos;
//   row_major float3x3 invViewMatrix;
//   float4 shaderProperties;
//
//
// Registers:
//
//   Name                       Reg   Size
//   -------------------------- ----- ----
//   invViewMatrix              c0       3
//   shaderProperties           c3       1
//   global_ViewPos             c214     1
//   global_LightPropertyMatrix c220     4
//   GBuffer1                   s0       1
//   GBuffer2                   s1       1
//   GBuffer3                   s2       1
//   GBuffer4                   s3       1
//   Base                       s4       1
//   Shadow                     s5       1
//

    ps_3_0
    def c4, 0, 1, 3.55539989, -1.77769995
    def c5, 2, -1, 4, 0.5
def c190, 1, 0, 0.0625, 0.5
dcl_2d s13
    dcl_texcoord v0.xy  // In<4,5>
    dcl_texcoord2 v1.xyz  // In<6,7,8>
    dcl_2d s0
    dcl_2d s1
    dcl_2d s2
    dcl_2d s3
    dcl_2d s4
    dcl_2d s5

////------Work out Inverse matrix------
def c201, 1, 0, 0, 0
////Initialise 
mov r9, c204
mov r10, c205
mov r11, c206
mov r12, c207

mov r13, c201.y  	
mov r13.x, c201.x  	
mov r14, c201.y  	
mov r14.y, c201.x  	
mov r15, c201.y  	
mov r15.z, c201.x  	
mov r16, c201.y  	
mov r16.w, c201.x  
	
////First row reduction
if_ne r9.x, c201.w
	rcp r3.x, r9.x
	mul r9, r9, r3.x
	mul r13, r13, r3.x
endif
if_ne r10.x, c201.w
	rcp r3.x, r10.x
	mul r10, r10, r3.x
	mul r14, r14, r3.x
endif
if_ne r11.x, c201.w
	rcp r3.x, r11.x
	mul r11, r11, r3.x
	mul r15, r15, r3.x
endif
if_ne r12.x, c201.w
	rcp r3.x, r12.x
	mul r12, r12, r3.x
	mul r16, r16, r3.x
endif
if_ne r10.x, c201.w
	sub r10, r10, r9
	sub r14, r14, r13
endif
if_ne r11.x, c201.w
	sub r11, r11, r9
	sub r15, r15, r13
endif
if_ne r12.x, c201.w
	sub r12, r12, r9
	sub r16, r16, r13
endif

////Second row reduction
if_ne r9.y, c201.w
	mov r3.y, r9.y
	rcp r3.x, r9.y
	mul r9, r9, r3.x
	mul r13, r13, r3.x
else
	mov r3.y, c201.x
endif
if_ne r10.y, c201.w
	rcp r3.x, r10.y
	mul r10, r10, r3.x
	mul r14, r14, r3.x
endif
if_ne r11.y, c201.w
	rcp r3.x, r11.y
	mul r11, r11, r3.x
	mul r15, r15, r3.x
endif
if_ne r12.y, c201.w
	rcp r3.x, r12.y
	mul r12, r12, r3.x
	mul r16, r16, r3.x
endif
if_ne r9.y, c201.w
	sub r9, r9, r10
	sub r13, r13, r14
endif
if_ne r11.y, c201.w
	sub r11, r11, r10
	sub r15, r15, r14
endif
if_ne r12.y, c201.w
	sub r12, r12, r10
	sub r16, r16, r14
endif

mul r9, r9, r3.y
mul r13, r13, r3.y

////Third row reduction
if_ne r9.z, c201.w
	mov r3.y, r9.z
	rcp r3.x, r9.z
	mul r9, r9, r3.x
	mul r13, r13, r3.x
else
	mov r3.y, c201.x
endif
if_ne r10.z, c201.w
	mov r3.z, r10.z
	rcp r3.x, r10.z
	mul r10, r10, r3.x
	mul r14, r14, r3.x
else
	mov r3.z, c201.x
endif
if_ne r11.z, c201.w
	rcp r3.x, r11.z
	mul r11, r11, r3.x
	mul r15, r15, r3.x
endif
if_ne r12.z, c201.w
	rcp r3.x, r12.z
	mul r12, r12, r3.x
	mul r16, r16, r3.x
endif
if_ne r9.z, c201.w
	sub r9, r9, r11
	sub r13, r13, r15
endif
if_ne r10.z, c201.w
	sub r10, r10, r11
	sub r14, r14, r15
endif
if_ne r12.z, c201.w
	sub r12, r12, r11
	sub r16, r16, r15
endif

mul r9, r9, r3.y
mul r13, r13, r3.y
mul r10, r10, r3.z
mul r14, r14, r3.z

////Fourth row reduction
if_ne r9.w, c201.w
	mov r3.y, r9.w
	rcp r3.x, r9.w
	mul r9, r9, r3.x
	mul r13, r13, r3.x
else
	mov r3.y, c201.x
endif
if_ne r10.w, c201.w
	mov r3.z, r10.w
	rcp r3.x, r10.w
	mul r10, r10, r3.x
	mul r14, r14, r3.x
else
	mov r3.z, c201.x
endif
if_ne r11.w, c201.w
	mov r3.w, r11.w
	rcp r3.x, r11.w
	mul r11, r11, r3.x
	mul r15, r15, r3.x
else
	mov r3.w, c201.x
endif
if_ne r12.w, c201.w
	rcp r3.x, r12.w
	mul r12, r12, r3.x
	mul r16, r16, r3.x
endif
if_ne r9.w, c201.w
	sub r9, r9, r12
	sub r13, r13, r16
endif
if_ne r10.w, c201.w
	sub r10, r10, r12
	sub r14, r14, r16
endif
if_ne r11.w, c201.w
	sub r11, r11, r12
	sub r15, r15, r16
endif
mul r9, r9, r3.y
mul r13, r13, r3.y
mul r10, r10, r3.z
mul r14, r14, r3.z
mul r11, r11, r3.w
mul r15, r15, r3.w
////--------- END INVERSE MATRIX --------------

#line 32 "c:\Develop\LSProjects\EyesOfAChild\Tools\Glasses\build\memory"
    texld r0, v0, s0  // ::depth<0>
    texld r1, v0, s1  // ::GBuffer2values<0,1,2,3>
    texld r2, v0, s2  // ::GBuffer3values<0,1,2,3>
    texld r3, v0, s3  // ::GBuffer4values<0,1,2,3>

#line 39
    mov r4.xy, c4
    if_lt -c3.x, r4.x
      texld r5, v0, s4  // ::ao<0>
    else
      mov r5.x, c4.y  // ::ao<0>
    endif

#line 45
    if_lt -c3.w, r4.x
      texld r6, v0, s5  // ::shadowValue<0,1,2,3>
    else
      mov r6.xyz, c4.y  // ::shadowValue<0,1,2>
    endif

#line 18 "Shaders/Deferred.shdh"
    mov_pp r7.x, r1.w
    mov_pp r7.y, r3.w
    mad_pp r7.xy, r7, c4.z, c4.w  // ::nn<0,1>
    mov_pp r7.z, c4.y  // ::nn<2>
    dp3_pp r0.y, r7, r7
    rcp r0.y, r0.y
    add_pp r0.z, r0.y, r0.y  // ::g<0>
    mul_pp r7.xy, r7, r0.z  // ::n<0,1>
    mad_pp r7.z, r0.y, c5.x, c5.y  // ::n<2>

#line 48 "c:\Develop\LSProjects\EyesOfAChild\Tools\Glasses\build\memory"
    dp3 r8.x, c0, r7  // ::WorldNormal<0>
    dp3 r8.y, c1, r7  // ::WorldNormal<1>
    dp3 r8.z, c2, r7  // ::WorldNormal<2>
    mad r0.xyz, r0.x, v1, c214  // ::WorldPos<0,1,2>
	
texldl r24, c190.z, s13
if_ne r24.x, c4.x
	mov r20.xyz, r0.xyz
	mov r20.w, c190.x
		
	dp4 r21.x, r20, c204 //r13 //c208
	dp4 r21.y, r20, c205 //r14 //c209
	dp4 r21.z, r20, c206 //r15 //c210
	dp4 r21.w, r20, c207 //r16 //c211

	add r24.y, r21.w, -r24.y
	mul r24.x, r24.x, r24.y
	add r21.x, r21.x, -r24.x

	dp4 r20.x, r21, r13 //c204
	dp4 r20.y, r21, r14 //c205
	dp4 r20.z, r21, r15 //c206
	dp4 r20.w, r21, r16 //c207

	rcp r21.w, r20.w
	mul r20, r20, r21.w

	mov r0, r20	
endif	
	
	
    add r0.xyz, -r0, c214
    dp3 r0.w, r0, r0
    rsq r0.w, r0.w

#line 68 "Shaders/Deferred.shdh"
    mov r7.x, c220.x
    mov r7.y, c221.x
    mov r7.z, c222.x
    nrm r9.xyz, r7
    dp3 r1.w, r9, r8  // ::NdotL<0>

#line 78
    mov_sat r3.w, r1.w  // ::intensity<0>

#line 85
    mad r0.xyz, r0, r0.w, r7
    nrm r7.xyz, r0  // ::halfvector<0,1,2>
    dp3 r0.x, r7, r8  // ::specularIntensity<0>
    pow r4.x, r0.x, r2.w  // ::specularIntensity<0>
    mul_sat r0.x, r1.w, c5.z
    mul r0.x, r0.x, r4.x  // ::specularIntensity<0>

#line 94
    mul r7.x, r3.w, c220.z  // DirectionLight::lightDiffuseColorOut<0>
    mul r7.y, r3.w, c221.z  // DirectionLight::lightDiffuseColorOut<1>
    mul r7.z, r3.w, c222.z  // DirectionLight::lightDiffuseColorOut<2>
    mul r9.x, r0.x, c220.w
    mul r9.y, r0.x, c221.w
    mul r9.z, r0.x, c222.w
    mad r0.x, r8.y, c5.w, c5.w
    mov r8.xyz, c223  // ::global_LightPropertyMatrix<3,7,11>
    add r10.x, -r8.x, c220.y
    add r10.y, -r8.y, c221.y
    add r10.z, -r8.z, c222.y
    mad r0.xyz, r0.x, r10, c223  // DirectionLight::lightAmbientColorOut<0,1,2>

#line 58 "c:\Develop\LSProjects\EyesOfAChild\Tools\Glasses\build\memory"
    mul r0.xyz, r0, r1
    add r0.w, r5.x, -c4.y
    mad r4.xy, c3.zyzw, r0.w, r4.y
    mul r1.xyz, r1, r7
    mul r1.xyz, r4.y, r1
    mul r1.xyz, r6, r1  // ::LightDiffuseColorOut<0,1,2>
    mul r2.xyz, r2, r9
    mul r2.xyz, r4.y, r2
    mul r2.xyz, r6, r2
    cmp r2.xyz, -r3.w, c4.x, r2  // ::LightSpecularColorOut<0,1,2>
    mad r0.xyz, r0, r4.x, r1
    add r0.xyz, r2, r0  // ::Out<0,1,2>
    add r0.xyz, r3, r0  // ::Out<0,1,2>
    max oC0.xyz, r0, c4.x  // ::main<0,1,2>
    mov oC0.w, c4.y  // ::main<3>

// approximately 80 instruction slots used (6 texture, 74 arithmetic)
 