// ---- Created with 3Dmigoto v1.2.35 on Tue Apr 26 22:30:26 2016

cbuffer cbSceneParam : register(b8)
{
  float4 FC_FarClipInfo : packoffset(c0);
  float4 FC_ScreenSize : packoffset(c1);
  float4 FC_DepthComputeParam : packoffset(c2);
  float4 SC_CameraPos : packoffset(c3);
  float4 VC_ClipPlane : packoffset(c4);
  float4x3 FC_MatrixView : packoffset(c5);
  float4x4 FC_MatrixInvViewProj : packoffset(c8);
  float4x4 FC_MatrixInvProj : packoffset(c12);
  float4x4 FC_MatrixProj : packoffset(c16);
  float4x4 FC_MatrixInvView : packoffset(c20);
  float4x4 VC_MatrixViewProj : packoffset(c24);
  float4 FC_ShadowMapParam : packoffset(c28);
  float4 FC_ShadowColor : packoffset(c29);
  float4 FC_ShadowDir : packoffset(c30);
  float4x4 VC_ShadowMapMatrix : packoffset(c31);
  float FC_ShadowDepthRate : packoffset(c35);
  float FC_ShadowDepthScale : packoffset(c35.y);
  float FC_ShadowKernelScale : packoffset(c35.z);
  float FC_ShadowRandTexInvScale : packoffset(c35.w);
  float FC_ShadowTexInvScaleX : packoffset(c36);
  float FC_ShadowTexInvScaleY : packoffset(c36.y);
  float FC_ShadowDepthOffsetScale : packoffset(c36.z);
  float4 FC_ShadowViewKernelScale : packoffset(c37);
  float4x4 FC_ProjSpaceToShadowMatrix[4] : packoffset(c38);
  float4 FC_CascadeSelectDist : packoffset(c54);
  float FC_FrustumNear : packoffset(c55);
  float FC_FrustumSliceScale : packoffset(c55.y);
  float FC_FrustumSliceBias : packoffset(c55.z);
  uint FC_LightTile_Width : packoffset(c56);
  uint FC_LightTile_NumCellX : packoffset(c56.y);
  float4 FC_CloudShadowParam0 : packoffset(c57);
  float4 FC_CloudShadowParam1 : packoffset(c58);
  float FC_ShadowScale0 : packoffset(c59);
  float FC_ShadowScale1 : packoffset(c59.y);
}

cbuffer CB_ENVMAP_REGION : register(b3)
{
  float4x4 g_envMapWorld : packoffset(c0);
  float4x4 g_envMapInvWorld : packoffset(c4);
  float4 g_envMapDrawAreaExtents : packoffset(c8);
  float g_envMapColorScale : packoffset(c9);
  float g_envMapFadeDistance : packoffset(c9.y);
  float4x4 g_envMapMatPccObb : packoffset(c10);
  float4x4 g_envMapMatInvPccObb : packoffset(c14);
  float4 g_envMapRegionPccOrigin : packoffset(c18);
  float4 g_envMapDebugOutputColor : packoffset(c19);
  float g_envMapFadeRate : packoffset(c20);
  float g_envMapDiffuseColorScale : packoffset(c20.y);
  float4x4 g_envMapInvIv : packoffset(c21);
}

SamplerState SS_ClampPoint_s : register(s7);
SamplerState SS_WrapLinear_s : register(s8);
Texture2D<float4> g_LightPrepassAttrTexture : register(t0);
Texture2D<float4> g_DepthTexture : register(t1);
Texture2D<float4> g_GBuffer1Texture : register(t3);
Texture2D<float4> g_GBuffer3Texture : register(t5);
TextureCube<float4> g_IBLTexture : register(t30);


// 3Dmigoto declarations
#define cmp -
Texture1D<float4> IniParams : register(t120);
Texture2D<float4> StereoParams : register(t125);


void main( 
  float4 v0 : SV_POSITION0,
  out float4 o0 : SV_TARGET0)
{
  float4 r0,r1,r2,r3,r4,r5;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xy = FC_ScreenSize.zw * v0.xy;
  r1.z = g_DepthTexture.Sample(SS_ClampPoint_s, r0.xy).x;
  r1.xy = r0.xy * float2(2,-2) + float2(-1,1);
  r1.w = 1;
  r2.x = dot(r1.xyzw, FC_MatrixInvProj._m00_m10_m20_m30);
  r2.y = dot(r1.xyzw, FC_MatrixInvProj._m01_m11_m21_m31);
  r2.z = dot(r1.xyzw, FC_MatrixInvProj._m02_m12_m22_m32);
  r2.w = dot(r1.xyzw, FC_MatrixInvProj._m03_m13_m23_m33);
  r1.xyzw = r2.xyzw / r2.wwww;
  r2.x = dot(r1.xyzw, FC_MatrixInvView._m00_m10_m20_m30);
  r2.y = dot(r1.xyzw, FC_MatrixInvView._m01_m11_m21_m31);
  r2.z = dot(r1.xyzw, FC_MatrixInvView._m02_m12_m22_m32);
  r2.w = dot(r1.xyzw, FC_MatrixInvView._m03_m13_m23_m33);
  r3.x = dot(r2.xyzw, g_envMapInvWorld._m00_m10_m20_m30);
  r3.y = dot(r2.xyzw, g_envMapInvWorld._m01_m11_m21_m31);
  r3.z = dot(r2.xyzw, g_envMapInvWorld._m02_m12_m22_m32);
  r2.xyz = float3(1,1,1) + -abs(r3.xyz);
  r2.xyz = g_envMapDrawAreaExtents.xyz * r2.xyz;
  r0.z = min(r2.x, r2.y);
  r0.z = min(r0.z, r2.z);
  r0.w = cmp(r0.z < 0);
  r2.xyz = g_LightPrepassAttrTexture.Sample(SS_ClampPoint_s, r0.xy).xyz;
  r3.xyz = g_GBuffer3Texture.Sample(SS_ClampPoint_s, r0.xy).xyz;
  r0.x = g_GBuffer1Texture.Sample(SS_ClampPoint_s, r0.xy).x;
  if (r0.w != 0) {
    o0.xyzw = float4(0,0,0,0);
    return;
  }
  r0.y = saturate(r0.z / g_envMapFadeDistance);
  r0.z = r0.y * -2 + 3;
  r0.y = r0.y * r0.y;
  r0.y = r0.z * r0.y;
  r2.xyz = r2.xyz * float3(2,2,2) + float3(-1,-1,-1);
  r0.z = dot(r2.xyz, r2.xyz);
  r0.z = rsqrt(r0.z);
  r2.xyz = r2.xyz * r0.zzz;
  r4.xyz = r3.xyz * r3.xyz;
  r0.z = dot(r1.xyz, r1.xyz);
  r0.z = rsqrt(r0.z);
  r1.xyz = r1.xyz * r0.zzz;
  r5.x = dot(-r1.xyz, FC_MatrixInvView._m00_m10_m20);
  r5.y = dot(-r1.xyz, FC_MatrixInvView._m01_m11_m21);
  r5.z = dot(-r1.xyz, FC_MatrixInvView._m02_m12_m22);
  r0.z = dot(r5.xyz, r2.xyz);
  r0.w = saturate(r0.z);
  r0.w = 1 + -r0.w;
  r0.z = r0.z + r0.z;
  r1.xyz = r0.zzz * r2.xyz + -r5.xyz;
  r0.z = r0.w * r0.w;
  r0.z = r0.z * r0.z;
  r0.z = r0.w * r0.z;
  r0.w = -r0.x * 6.5 + 6.5;
  r0.w = min(6, r0.w);
  r3.xyz = -r3.xyz * r3.xyz + float3(1,1,1);
  r3.xyz = r3.xyz * r0.zzz;
  r0.x = r0.x * r0.x;
  r3.xyz = r3.xyz * r0.xxx + r4.xyz;
  r0.xzw = g_IBLTexture.SampleLevel(SS_WrapLinear_s, r1.xyz, r0.w).xyz;
  r0.xzw = r0.xzw * r3.xyz;
  r0.xzw = g_envMapColorScale * r0.xzw;
  r1.x = dot(r1.xyz, r2.xyz);
  r1.x = saturate(1 + r1.x);
  r1.x = r1.x * r1.x;
  o0.xyz = r1.xxx * r0.xzw;
  o0.w = g_envMapFadeRate * r0.y;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Original ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
//
//
// Buffer Definitions: 
//
// cbuffer cbSceneParam
// {
//
//   float4 FC_FarClipInfo;             // Offset:    0 Size:    16 [unused]
//   float4 FC_ScreenSize;              // Offset:   16 Size:    16
//   float4 FC_DepthComputeParam;       // Offset:   32 Size:    16 [unused]
//   float4 SC_CameraPos;               // Offset:   48 Size:    16 [unused]
//   float4 VC_ClipPlane;               // Offset:   64 Size:    16 [unused]
//   float4x3 FC_MatrixView;            // Offset:   80 Size:    48 [unused]
//   float4x4 FC_MatrixInvViewProj;     // Offset:  128 Size:    64 [unused]
//   float4x4 FC_MatrixInvProj;         // Offset:  192 Size:    64
//   float4x4 FC_MatrixProj;            // Offset:  256 Size:    64 [unused]
//   float4x4 FC_MatrixInvView;         // Offset:  320 Size:    64
//   float4x4 VC_MatrixViewProj;        // Offset:  384 Size:    64 [unused]
//   float4 FC_ShadowMapParam;          // Offset:  448 Size:    16 [unused]
//   float4 FC_ShadowColor;             // Offset:  464 Size:    16 [unused]
//   float4 FC_ShadowDir;               // Offset:  480 Size:    16 [unused]
//   float4x4 VC_ShadowMapMatrix;       // Offset:  496 Size:    64 [unused]
//   float FC_ShadowDepthRate;          // Offset:  560 Size:     4 [unused]
//   float FC_ShadowDepthScale;         // Offset:  564 Size:     4 [unused]
//   float FC_ShadowKernelScale;        // Offset:  568 Size:     4 [unused]
//   float FC_ShadowRandTexInvScale;    // Offset:  572 Size:     4 [unused]
//   float FC_ShadowTexInvScaleX;       // Offset:  576 Size:     4 [unused]
//   float FC_ShadowTexInvScaleY;       // Offset:  580 Size:     4 [unused]
//   float FC_ShadowDepthOffsetScale;   // Offset:  584 Size:     4 [unused]
//   float4 FC_ShadowViewKernelScale;   // Offset:  592 Size:    16 [unused]
//   float4x4 FC_ProjSpaceToShadowMatrix[4];// Offset:  608 Size:   256 [unused]
//   float4 FC_CascadeSelectDist;       // Offset:  864 Size:    16 [unused]
//   float FC_FrustumNear;              // Offset:  880 Size:     4 [unused]
//   float FC_FrustumSliceScale;        // Offset:  884 Size:     4 [unused]
//   float FC_FrustumSliceBias;         // Offset:  888 Size:     4 [unused]
//   uint FC_LightTile_Width;           // Offset:  896 Size:     4 [unused]
//   uint FC_LightTile_NumCellX;        // Offset:  900 Size:     4 [unused]
//   float4 FC_CloudShadowParam0;       // Offset:  912 Size:    16 [unused]
//   float4 FC_CloudShadowParam1;       // Offset:  928 Size:    16 [unused]
//   float FC_ShadowScale0;             // Offset:  944 Size:     4 [unused]
//   float FC_ShadowScale1;             // Offset:  948 Size:     4 [unused]
//
// }
//
// cbuffer CB_ENVMAP_REGION
// {
//
//   float4x4 g_envMapWorld;            // Offset:    0 Size:    64 [unused]
//   float4x4 g_envMapInvWorld;         // Offset:   64 Size:    64
//   float4 g_envMapDrawAreaExtents;    // Offset:  128 Size:    16
//   float g_envMapColorScale;          // Offset:  144 Size:     4
//   float g_envMapFadeDistance;        // Offset:  148 Size:     4
//   float4x4 g_envMapMatPccObb;        // Offset:  160 Size:    64 [unused]
//   float4x4 g_envMapMatInvPccObb;     // Offset:  224 Size:    64 [unused]
//   float4 g_envMapRegionPccOrigin;    // Offset:  288 Size:    16 [unused]
//   float4 g_envMapDebugOutputColor;   // Offset:  304 Size:    16 [unused]
//   float g_envMapFadeRate;            // Offset:  320 Size:     4
//   float g_envMapDiffuseColorScale;   // Offset:  324 Size:     4 [unused]
//   float4x4 g_envMapInvIv;            // Offset:  336 Size:    64 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// SS_ClampPoint                     sampler      NA          NA    7        1
// SS_WrapLinear                     sampler      NA          NA    8        1
// g_LightPrepassAttrTexture         texture  float4          2d    0        1
// g_DepthTexture                    texture  float4          2d    1        1
// g_GBuffer1Texture                 texture  float4          2d    3        1
// g_GBuffer3Texture                 texture  float4          2d    5        1
// g_IBLTexture                      texture  float4        cube   30        1
// CB_ENVMAP_REGION                  cbuffer      NA          NA    3        1
// cbSceneParam                      cbuffer      NA          NA    8        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float   xy  
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_TARGET                0   xyzw        0   TARGET   float   xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb8[24], immediateIndexed
dcl_constantbuffer cb3[21], immediateIndexed
dcl_sampler s7, mode_default
dcl_sampler s8, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_texture2d (float,float,float,float) t3
dcl_resource_texture2d (float,float,float,float) t5
dcl_resource_texturecube (float,float,float,float) t30
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_output o0.xyzw
dcl_temps 6
mul r0.xy, v0.xyxx, cb8[1].zwzz
sample_indexable(texture2d)(float,float,float,float) r1.z, r0.xyxx, t1.yzxw, s7
mad r1.xy, r0.xyxx, l(2.000000, -2.000000, 0.000000, 0.000000), l(-1.000000, 1.000000, 0.000000, 0.000000)
mov r1.w, l(1.000000)
dp4 r2.x, r1.xyzw, cb8[12].xyzw
dp4 r2.y, r1.xyzw, cb8[13].xyzw
dp4 r2.z, r1.xyzw, cb8[14].xyzw
dp4 r2.w, r1.xyzw, cb8[15].xyzw
div r1.xyzw, r2.xyzw, r2.wwww
dp4 r2.x, r1.xyzw, cb8[20].xyzw
dp4 r2.y, r1.xyzw, cb8[21].xyzw
dp4 r2.z, r1.xyzw, cb8[22].xyzw
dp4 r2.w, r1.xyzw, cb8[23].xyzw
dp4 r3.x, r2.xyzw, cb3[4].xyzw
dp4 r3.y, r2.xyzw, cb3[5].xyzw
dp4 r3.z, r2.xyzw, cb3[6].xyzw
add r2.xyz, -|r3.xyzx|, l(1.000000, 1.000000, 1.000000, 0.000000)
mul r2.xyz, r2.xyzx, cb3[8].xyzx
min r0.z, r2.y, r2.x
min r0.z, r2.z, r0.z
lt r0.w, r0.z, l(0.000000)
sample_indexable(texture2d)(float,float,float,float) r2.xyz, r0.xyxx, t0.xyzw, s7
sample_indexable(texture2d)(float,float,float,float) r3.xyz, r0.xyxx, t5.xyzw, s7
sample_indexable(texture2d)(float,float,float,float) r0.x, r0.xyxx, t3.xyzw, s7
if_nz r0.w
  mov o0.xyzw, l(0,0,0,0)
  ret 
endif 
div_sat r0.y, r0.z, cb3[9].y
mad r0.z, r0.y, l(-2.000000), l(3.000000)
mul r0.y, r0.y, r0.y
mul r0.y, r0.y, r0.z
mad r2.xyz, r2.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
dp3 r0.z, r2.xyzx, r2.xyzx
rsq r0.z, r0.z
mul r2.xyz, r0.zzzz, r2.xyzx
mul r4.xyz, r3.xyzx, r3.xyzx
dp3 r0.z, r1.xyzx, r1.xyzx
rsq r0.z, r0.z
mul r1.xyz, r0.zzzz, r1.xyzx
dp3 r5.x, -r1.xyzx, cb8[20].xyzx
dp3 r5.y, -r1.xyzx, cb8[21].xyzx
dp3 r5.z, -r1.xyzx, cb8[22].xyzx
dp3 r0.z, r5.xyzx, r2.xyzx
mov_sat r0.w, r0.z
add r0.w, -r0.w, l(1.000000)
add r0.z, r0.z, r0.z
mad r1.xyz, r0.zzzz, r2.xyzx, -r5.xyzx
mul r0.z, r0.w, r0.w
mul r0.z, r0.z, r0.z
mul r0.z, r0.z, r0.w
mad r0.w, -r0.x, l(6.500000), l(6.500000)
min r0.w, r0.w, l(6.000000)
mad r3.xyz, -r3.xyzx, r3.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000)
mul r3.xyz, r0.zzzz, r3.xyzx
mul r0.x, r0.x, r0.x
mad r3.xyz, r3.xyzx, r0.xxxx, r4.xyzx
sample_l_indexable(texturecube)(float,float,float,float) r0.xzw, r1.xyzx, t30.xwyz, s8, r0.w
mul r0.xzw, r3.xxyz, r0.xxzw
mul r0.xzw, r0.xxzw, cb3[9].xxxx
dp3 r1.x, r1.xyzx, r2.xyzx
add_sat r1.x, r1.x, l(1.000000)
mul r1.x, r1.x, r1.x
mul o0.xyz, r0.xzwx, r1.xxxx
mul o0.w, r0.y, cb3[20].x
ret 
// Approximately 66 instruction slots used

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
