
cbuffer _Globals : register(b0)
{
  float2 g_invScreenSize : packoffset(c0);
  float4x4 g_invViewProjMatrix : packoffset(c1);
  float4 g_shadowmapHalfSizeAndInvHalfSize : packoffset(c5);
  float g_subRolloff : packoffset(c6);
  float4 g_exposureMultipliers : packoffset(c7);
  uint4 g_shadowmapDimensions : packoffset(c8);
}
SamplerComparisonState g_shadowmapSampler_s : register(s0);
Texture2D<float4> g_shadowmapTexture : register(t0);
Texture2DMS<float4,2> g_depthTexture : register(t1);
Texture2DMS<float4,2> g_gbufferTexture0 : register(t2);
Texture2DMS<float4,2> g_gbufferTexture1 : register(t3);
Texture2DMS<float4,2> g_gbufferTexture2 : register(t4);
Texture2D<float> g_msaaClassifyTexture : register(t5);

Texture2D<float4> StereoParams : register(t125);

void main(
  float4 v0 : SV_Position0,
  float4 v1 : TEXCOORD0,
  float4 v2 : TEXCOORD1,
  float4 v3 : TEXCOORD2,
  float4 v4 : TEXCOORD3,
  float4 v5 : TEXCOORD4,
  float4 v6 : TEXCOORD5,
  float4 v7 : TEXCOORD6,
  float4 v8 : TEXCOORD7,
  float4 v9 : TEXCOORD8,
  float4 v10 : TEXCOORD9,
  out float4 o0 : SV_Target0,
  out float4 o1 : SV_Target1)
{
  const float4 icb[] = { { 0.250000, 0, 0, 0},
                              { -0.250000, 0, 0, 0} };
  float4 r0,r1,r2,r3,r4,r5,r6,r7;
  uint4 bitmask;

//Work out Inverse
//...Variables
float4 a1, a2, a3, a4;
float4 b1, b2, b3, b4;
float det;
//...Original Matrix
a1 = g_invViewProjMatrix._m00_m10_m20_m30;
a2 = g_invViewProjMatrix._m01_m11_m21_m31;
a3 = g_invViewProjMatrix._m02_m12_m22_m32;
a4 = g_invViewProjMatrix._m03_m13_m23_m33;
//...Determinant
det  = a1.x*(a2.y*(a3.z*a4.w - a3.w*a4.z) + a2.z*(a3.w*a4.y - a3.y*a4.w) + a2.w*(a3.y*a4.z - a3.z*a4.y));
det += a1.y*(a2.x*(a3.w*a4.z - a3.z*a4.w) + a2.z*(a3.x*a4.w - a3.w*a4.z) + a2.w*(a3.z*a4.x - a3.x*a4.z));
det += a1.z*(a2.x*(a3.y*a4.w - a3.w*a4.y) + a2.y*(a3.w*a4.x - a3.x*a4.w) + a2.w*(a3.x*a4.y - a3.y*a4.x));
det += a1.w*(a2.x*(a3.z*a4.y - a3.y*a4.z) + a2.y*(a3.x*a4.z - a3.z*a4.x) + a2.z*(a3.y*a4.x - a3.x*a4.y));
//...Inverse Matrix Elements
b1.x = a2.y*(a3.z*a4.w - a3.w*a4.z) + a2.z*(a3.w*a4.y - a3.y*a4.w) + a2.w*(a3.y*a4.z - a3.z*a4.y);
b1.y = a1.y*(a3.w*a4.z - a3.z*a4.w) + a1.z*(a3.y*a4.w - a3.w*a4.y) + a1.w*(a3.z*a4.y - a3.y*a4.z);
b1.z = a1.y*(a2.z*a4.w - a2.w*a4.z) + a1.z*(a2.w*a4.y - a2.y*a4.w) + a1.w*(a2.y*a4.z - a2.z*a4.y);
b1.w = a1.y*(a2.w*a3.z - a2.z*a3.w) + a1.z*(a2.y*a3.w - a2.w*a3.y) + a1.w*(a2.z*a3.y - a2.y*a3.z);
b2.x = a2.x*(a3.w*a4.z - a3.z*a4.w) + a2.z*(a3.x*a4.w - a3.w*a4.x) + a2.w*(a3.z*a4.x - a3.x*a4.z);
b2.y = a1.x*(a3.z*a4.w - a3.w*a4.z) + a1.z*(a3.w*a4.x - a3.x*a4.w) + a1.w*(a3.x*a4.z - a3.z*a4.x);
b2.z = a1.x*(a2.w*a4.z - a2.z*a4.w) + a1.z*(a2.x*a4.w - a2.w*a4.x) + a1.w*(a2.z*a4.x - a2.x*a4.z);
b2.w = a1.x*(a2.z*a3.w - a2.w*a3.z) + a1.z*(a2.w*a3.x - a2.x*a3.w) + a1.w*(a2.x*a3.z - a2.z*a3.x);
b3.x = a2.x*(a3.y*a4.w - a3.w*a4.y) + a2.y*(a3.w*a4.x - a3.x*a4.w) + a2.w*(a3.x*a4.y - a3.y*a4.x);
b3.y = a1.x*(a3.w*a4.y - a3.y*a4.w) + a1.y*(a3.x*a4.w - a3.w*a4.x) + a1.w*(a3.y*a4.x - a3.x*a4.y);
b3.z = a1.x*(a2.y*a4.w - a2.w*a4.y) + a1.y*(a2.w*a4.x - a2.x*a4.w) + a1.w*(a2.x*a4.y - a2.y*a4.x);
b3.w = a1.x*(a2.w*a3.y - a2.y*a3.w) + a1.y*(a2.x*a3.w - a2.w*a3.x) + a1.w*(a2.y*a3.x - a2.x*a3.y);
b4.x = a2.x*(a3.z*a4.y - a3.y*a4.z) + a2.y*(a3.x*a4.z - a3.z*a4.x) + a2.z*(a3.y*a4.x - a3.x*a4.y);
b4.y = a1.x*(a3.y*a4.z - a3.z*a4.y) + a1.y*(a3.z*a4.x - a3.x*a4.z) + a1.z*(a3.x*a4.y - a3.y*a4.x);
b4.z = a1.x*(a2.z*a4.y - a2.y*a4.z) + a1.y*(a2.x*a4.z - a2.z*a4.x) + a1.z*(a2.y*a4.x - a2.x*a4.y);
b4.w = a1.x*(a2.y*a3.z - a2.z*a3.y) + a1.y*(a2.z*a3.x - a2.x*a3.z) + a1.z*(a2.x*a3.y - a2.y*a3.x);
b1.xyzw /= det;
b2.xyzw /= det;
b3.xyzw /= det;
b4.xyzw /= det;
//End Inverse


  r0.xy = (int2)v0.xy;
  r0.zw = float2(0.000000e+000,0.000000e+000);
  r1.x = g_msaaClassifyTexture.Load(r0.xyw).x;
  r1.x = 0.000000000e+000 < r1.x;
  r1.xy = r1.xx ? float2(2.000000e+000,5.000000e-001) : float2(1.000000e+000,1.000000e+000);
  r2.w = 1.000000000e+000;
  r3.w = 1.000000000e+000;
  r4.xyz = float3(0.000000e+000,0.000000e+000,0.000000e+000);
  r1.z = 0.000000000e+000;
  while (true) {
    r1.w = (int)r1.z >= (int)r1.x;
    if (r1.w != 0) break;
    r5.xy = icb[r1.z].xx * g_invScreenSize.xy;
    r5.xy = v0.xy * g_invScreenSize.xy + r5.xy;
    r6.xyz = g_gbufferTexture0.Load(r0.xyw,r1.z).xyz;
    r7.xyzw = g_gbufferTexture1.Load(r0.xyw,r1.z).xyzw;
    r1.w = g_gbufferTexture2.Load(r0.xyw,r1.z).w;
    r2.z = g_depthTexture.Load(r0.xyz,r1.z).x;
    r6.xyz = r6.xyz * float3(2.000000e+000,2.000000e+000,2.000000e+000) + float3(-1.000000e+000,-1.000000e+000,-1.000000e+000);
    r4.w = dot(r6.xyz, r6.xyz);
    r4.w = rsqrt(r4.w);
    r6.xyz = r6.xyz * r4.www;
    r1.w = 2.550000000e+002 * r1.w;
    r1.w = round(r1.w);
    r1.w = (int)r1.w;
    r7.xyzw = r7.xyzw * r7.xyzw;
    r1.w = r1.w == 5;
    if (r1.w != 0) {
      r7.xyz = r7.xyz * r7.www;
    }
    r5.xy = r5.xy * float2(2.000000e+000,2.000000e+000) + float2(-1.000000e+000,-1.000000e+000);
    r2.xy = float2(1.000000e+000,-1.000000e+000) * r5.xy;
    r5.x = dot(r2.xyzw, g_invViewProjMatrix._m00_m10_m20_m30);
    r5.y = dot(r2.xyzw, g_invViewProjMatrix._m01_m11_m21_m31);
    r5.z = dot(r2.xyzw, g_invViewProjMatrix._m02_m12_m22_m32);
    r1.w = dot(r2.xyzw, g_invViewProjMatrix._m03_m13_m23_m33);
    r1.w = 1.000000e+000 / r1.w;


float4 r28, r26, r27;
r26.xyz = r5.xyz * r1.www;
r26.w = 1.0;
r28.x = dot(r26.xyzw, b1.xyzw);
r28.y = dot(r26.xyzw, b2.xyzw);
r28.z = dot(r26.xyzw, b3.xyzw);
r28.w = dot(r26.xyzw, b4.xyzw);
float4 stereo = StereoParams.Load(0);
r28.x -= stereo.x * (r28.w - stereo.y); 
r26.x = dot(r28.xyzw, a1.xyzw);
r26.y = dot(r28.xyzw, a2.xyzw);
r26.z = dot(r28.xyzw, a3.xyzw);
r26.w = dot(r28.xyzw, a4.xyzw);
r5.xyz = r26.xyz / r1.www;

    r3.xyz = r5.xyz * r1.www;


    r2.xyz = -r5.xyz * r1.www + v1.xyz;
    r1.w = dot(r2.xyz, r2.xyz);
    r4.w = rsqrt(r1.w);
    r2.xyz = r4.www * r2.xyz;
    r1.w = v3.w + r1.w;
    r1.w = 1.000000e+000 / r1.w;
    r1.w = v1.w + r1.w;
    r1.w = max(r1.w, 0.000000000e+000);
    r4.w = dot(v6.xyz, r2.xyz);
    r4.w = saturate(r4.w * v5.x + v5.y);
    r4.w = 1.000000000e+000 + -r4.w;
    r1.w = r4.w * r1.w;
    r5.x = dot(r3.xyzw, v7.xyzw);
    r5.y = dot(r3.xyzw, v8.xyzw);
    r4.w = dot(r3.xyzw, v9.xyzw);
    r3.x = dot(r3.xyzw, v10.xyzw);
    r3.x = 1.000000e+000 / r3.x;
    r3.yz = r5.xy * r3.xx;
    r3.x = r4.w * r3.x;
    r5.x = max(abs(r3.z), abs(r3.y));
    r5.x = 1.000000000e+000 + -r5.x;
    r4.w = min(r4.w, r5.x);
    r4.w = r4.w < 0.000000000e+000;
    if (r4.w != 0) discard;
    r3.yz = r3.yz * float2(5.000000e-001,-5.000000e-001) + float2(5.000000e-001,5.000000e-001);
    r3.x = g_shadowmapTexture.SampleCmpLevelZero(g_shadowmapSampler_s, r3.yz, r3.x).x;
    r1.w = r3.x * r1.w;
    r2.x = saturate(dot(r6.xyz, r2.xyz));
    r2.xyz = v2.xyz * r2.xxx;
    r2.xyz = r2.xyz * r1.www;
    r4.xyz = r2.xyz * r7.xyz + r4.xyz;
    r1.z = (int)r1.z + 1;
  }
  o0.xyz = r4.xyz * r1.yyy;
  o1.xyzw = float4(0.000000e+000,0.000000e+000,0.000000e+000,0.000000e+000);
  o0.w = 0.000000000e+000;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HLSL errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E:\Program Files (x86)\Origin Games\Dragon Age Inquisition\wrapper1349(54,14-48): warning X3206: 'Load': implicit truncation of vector type
E:\Program Files (x86)\Origin Games\Dragon Age Inquisition\wrapper1349(55,15-49): warning X3206: 'Load': implicit truncation of vector type
E:\Program Files (x86)\Origin Games\Dragon Age Inquisition\wrapper1349(56,12-46): warning X3206: 'Load': implicit truncation of vector type
E:\Program Files (x86)\Origin Games\Dragon Age Inquisition\wrapper1349(57,12-43): warning X3206: 'Load': implicit truncation of vector type
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
