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

cbuffer cbLightAccParam : register(b0)
{
  float4x4 g_InvProjMatrix : packoffset(c0);
  float4x3 g_ViewMatrix : packoffset(c4);
  float4 g_ScreenSize : packoffset(c7);
  float4x4 g_CameraMatrix : packoffset(c8);
  float4 g_specPowerParam : packoffset(c12);
  float4x4 g_ProjMatrix : packoffset(c13);
  uint g_lightCount : packoffset(c17);
  bool g_visualizeLightCount : packoffset(c17.y);
  uint g_spotLightCount : packoffset(c17.z);
  uint g_lineLightCount : packoffset(c17.w);
  float g_frustumNear : packoffset(c18);
  float g_frustumFar : packoffset(c18.y);
  float g_frustumSliceScale : packoffset(c18.z);
  float g_frustumSliceBias : packoffset(c18.w);
  uint4 g_lightTileSize : packoffset(c19);
}

cbuffer cbLightAccLightParam : register(b1)
{

  struct
  {
    float4 PositionAndRadius;
    float4 DiffColor;
    float4 SpecColor;
    float4 TransLightParam;
  } g_aPointLight : packoffset(c0);

}

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);
Texture2D<float4> g_SSAOTexture : register(t33);


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


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

  r0.z = g_DepthTexture.Sample(SS_ClampPoint_s, v1.xy).x;
  r0.xy = v2.xy;
  r0.w = 1;
  r1.x = dot(r0.xyzw, g_InvProjMatrix._m00_m10_m20_m30);
  r1.y = dot(r0.xyzw, g_InvProjMatrix._m01_m11_m21_m31);
  r1.z = dot(r0.xyzw, g_InvProjMatrix._m02_m12_m22_m32);
  r0.x = dot(r0.xyzw, g_InvProjMatrix._m03_m13_m23_m33);
  r0.xyz = r1.xyz / r0.xxx;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = r0.xyz * r0.www;
  r2.xyz = g_aPointLight.PositionAndRadius.xyz + -r0.xyz;
  r0.w = dot(r2.xyz, r2.xyz);
  r1.w = rsqrt(r0.w);
  r2.xyz = r2.xyz * r1.www;
  r1.w = saturate(dot(r2.xyz, r1.xyz));
  r1.w = log2(r1.w);
  r2.w = 32 * g_aPointLight.TransLightParam.y;
  r1.w = r2.w * r1.w;
  r1.w = exp2(r1.w);
  r3.xyz = g_LightPrepassAttrTexture.Sample(SS_ClampPoint_s, v1.xy).xyz;
  r3.xyz = r3.xyz * float3(2,2,2) + float3(-1,-1,-1);
  r2.w = dot(r3.xyz, r3.xyz);
  r2.w = rsqrt(r2.w);
  r3.xyz = r3.xyz * r2.www;
  r4.x = dot(r3.xyz, g_ViewMatrix._m00_m10_m20);
  r4.y = dot(r3.xyz, g_ViewMatrix._m01_m11_m21);
  r4.z = dot(r3.xyz, g_ViewMatrix._m02_m12_m22);
  r1.x = dot(-r1.xyz, r4.xyz);
  r1.x = 1 + r1.x;
  r1.x = max(0, r1.x);
  r1.x = 0.5 * r1.x;
  r1.x = r1.x * r1.x;
  r1.x = r1.w * r1.x;
  r1.x = g_aPointLight.TransLightParam.x * r1.x;
  r1.xyz = g_aPointLight.DiffColor.xyz * r1.xxx;
  r3.xy = g_GBuffer1Texture.Sample(SS_ClampPoint_s, v1.xy).xy;
  r3.xz = float2(10,13) * r3.yx;
  r1.xyz = r3.xxx * r1.xyz;
  r1.w = exp2(r3.z);
  r2.w = 1 / r0.w;
  r0.w = saturate(g_aPointLight.PositionAndRadius.w * r0.w);
  r0.w = 1 + -r0.w;
  r2.w = -g_aPointLight.PositionAndRadius.w + r2.w;
  r2.w = max(0, r2.w);
  r1.xyz = r2.www * r1.xyz;
  r3.x = dot(r4.xyz, r2.xyz);
  r3.z = r3.y * 10 + r3.x;
  r3.x = saturate(r3.x);
  r3.z = max(0, r3.z);
  r3.w = r3.y * 20 + 1;
  r3.y = cmp(r3.y == 0.000000);
  r3.z = r3.z / r3.w;
  r5.xyz = g_aPointLight.DiffColor.xyz * r3.zzz;
  r1.xyz = r5.xyz * r2.www + r1.xyz;
  r5.xyz = g_aPointLight.DiffColor.xyz * r3.xxx;
  r3.x = log2(r3.x);
  r3.x = 0.100000001 * r3.x;
  r3.x = exp2(r3.x);
  r5.xyz = r5.xyz * r2.www;
  r1.xyz = r3.yyy ? r5.xyz : r1.xyz;
  r3.yzw = g_GBuffer3Texture.Sample(SS_ClampPoint_s, v1.xy).xyz;
  r3.yzw = r3.yzw * r3.yzw;
  r5.xyz = -r3.yzw * float3(0.5,0.5,0.5) + float3(1,1,1);
  r1.xyz = r5.xyz * r1.xyz;
  r2.w = g_SSAOTexture.Sample(SS_WrapLinear_s, v1.xy).x;
  o0.xyz = r2.www * r1.xyz;
  o0.w = 1;
  r1.x = dot(-r0.xyz, -r0.xyz);
  r1.x = rsqrt(r1.x);
  r0.xyz = -r0.xyz * r1.xxx + r2.xyz;
  r1.x = dot(r0.xyz, r0.xyz);
  r1.x = rsqrt(r1.x);
  r0.xyz = r1.xxx * r0.xyz;
  r0.x = saturate(dot(r0.xyz, r4.xyz));
  r0.x = log2(r0.x);
  r0.y = g_aPointLight.DiffColor.w * r1.w;
  r0.z = r1.w * 0.00999999978 + g_aPointLight.DiffColor.w;
  r0.y = r0.y / r0.z;
  r0.y = max(1, r0.y);
  r0.x = r0.y * r0.x;
  r0.y = r0.y * 0.125 + 0.25;
  r0.x = exp2(r0.x);
  r1.xyz = g_aPointLight.SpecColor.xyz * r0.xxx;
  r1.xyz = r1.xyz * r3.xxx;
  r0.xzw = r1.xyz * r0.www;
  r0.xyz = r0.xzw * r0.yyy;
  r0.xyz = r0.xyz * r3.yzw;
  o1.xyz = r0.xyz * r2.www;
  o1.w = 1;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Original ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
//
//
// Buffer Definitions: 
//
// cbuffer cbLightAccParam
// {
//
//   float4x4 g_InvProjMatrix;          // Offset:    0 Size:    64
//   float4x3 g_ViewMatrix;             // Offset:   64 Size:    48
//   float4 g_ScreenSize;               // Offset:  112 Size:    16 [unused]
//   float4x4 g_CameraMatrix;           // Offset:  128 Size:    64 [unused]
//   float4 g_specPowerParam;           // Offset:  192 Size:    16 [unused]
//   float4x4 g_ProjMatrix;             // Offset:  208 Size:    64 [unused]
//   uint g_lightCount;                 // Offset:  272 Size:     4 [unused]
//   bool g_visualizeLightCount;        // Offset:  276 Size:     4 [unused]
//   uint g_spotLightCount;             // Offset:  280 Size:     4 [unused]
//   uint g_lineLightCount;             // Offset:  284 Size:     4 [unused]
//   float g_frustumNear;               // Offset:  288 Size:     4 [unused]
//   float g_frustumFar;                // Offset:  292 Size:     4 [unused]
//   float g_frustumSliceScale;         // Offset:  296 Size:     4 [unused]
//   float g_frustumSliceBias;          // Offset:  300 Size:     4 [unused]
//   uint4 g_lightTileSize;             // Offset:  304 Size:    16 [unused]
//
// }
//
// cbuffer cbLightAccLightParam
// {
//
//   struct PointLight
//   {
//       
//       float4 PositionAndRadius;      // Offset:    0
//       float4 DiffColor;              // Offset:   16
//       float4 SpecColor;              // Offset:   32
//       float4 TransLightParam;        // Offset:   48
//
//   } g_aPointLight;                   // Offset:    0 Size:    64
//
// }
//
//
// 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_SSAOTexture                     texture  float4          2d   33        1
// cbLightAccParam                   cbuffer      NA          NA    0        1
// cbLightAccLightParam              cbuffer      NA          NA    1        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float       
// TEXCOORD                 0   xy          1     NONE   float   xy  
// TEXCOORD                 1   xyzw        2     NONE   float   xy  
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_TARGET                0   xyzw        0   TARGET   float   xyzw
// SV_TARGET                1   xyzw        1   TARGET   float   xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[7], immediateIndexed
dcl_constantbuffer cb1[4], 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_texture2d (float,float,float,float) t33
dcl_input_ps linear v1.xy
dcl_input_ps linear v2.xy
dcl_output o0.xyzw
dcl_output o1.xyzw
dcl_temps 6
sample_indexable(texture2d)(float,float,float,float) r0.z, v1.xyxx, t1.yzxw, s7
mov r0.xy, v2.xyxx
mov r0.w, l(1.000000)
dp4 r1.x, r0.xyzw, cb0[0].xyzw
dp4 r1.y, r0.xyzw, cb0[1].xyzw
dp4 r1.z, r0.xyzw, cb0[2].xyzw
dp4 r0.x, r0.xyzw, cb0[3].xyzw
div r0.xyz, r1.xyzx, r0.xxxx
dp3 r0.w, r0.xyzx, r0.xyzx
rsq r0.w, r0.w
mul r1.xyz, r0.wwww, r0.xyzx
add r2.xyz, -r0.xyzx, cb1[0].xyzx
dp3 r0.w, r2.xyzx, r2.xyzx
rsq r1.w, r0.w
mul r2.xyz, r1.wwww, r2.xyzx
dp3_sat r1.w, r2.xyzx, r1.xyzx
log r1.w, r1.w
mul r2.w, cb1[3].y, l(32.000000)
mul r1.w, r1.w, r2.w
exp r1.w, r1.w
sample_indexable(texture2d)(float,float,float,float) r3.xyz, v1.xyxx, t0.xyzw, s7
mad r3.xyz, r3.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
dp3 r2.w, r3.xyzx, r3.xyzx
rsq r2.w, r2.w
mul r3.xyz, r2.wwww, r3.xyzx
dp3 r4.x, r3.xyzx, cb0[4].xyzx
dp3 r4.y, r3.xyzx, cb0[5].xyzx
dp3 r4.z, r3.xyzx, cb0[6].xyzx
dp3 r1.x, -r1.xyzx, r4.xyzx
add r1.x, r1.x, l(1.000000)
max r1.x, r1.x, l(0.000000)
mul r1.x, r1.x, l(0.500000)
mul r1.x, r1.x, r1.x
mul r1.x, r1.x, r1.w
mul r1.x, r1.x, cb1[3].x
mul r1.xyz, r1.xxxx, cb1[1].xyzx
sample_indexable(texture2d)(float,float,float,float) r3.xy, v1.xyxx, t3.xyzw, s7
mul r3.xz, r3.yyxy, l(10.000000, 0.000000, 13.000000, 0.000000)
mul r1.xyz, r1.xyzx, r3.xxxx
exp r1.w, r3.z
div r2.w, l(1.000000, 1.000000, 1.000000, 1.000000), r0.w
mul_sat r0.w, r0.w, cb1[0].w
add r0.w, -r0.w, l(1.000000)
add r2.w, r2.w, -cb1[0].w
max r2.w, r2.w, l(0.000000)
mul r1.xyz, r1.xyzx, r2.wwww
dp3 r3.x, r4.xyzx, r2.xyzx
mad r3.z, r3.y, l(10.000000), r3.x
mov_sat r3.x, r3.x
max r3.z, r3.z, l(0.000000)
mad r3.w, r3.y, l(20.000000), l(1.000000)
eq r3.y, r3.y, l(0.000000)
div r3.z, r3.z, r3.w
mul r5.xyz, r3.zzzz, cb1[1].xyzx
mad r1.xyz, r5.xyzx, r2.wwww, r1.xyzx
mul r5.xyz, r3.xxxx, cb1[1].xyzx
log r3.x, r3.x
mul r3.x, r3.x, l(0.100000)
exp r3.x, r3.x
mul r5.xyz, r2.wwww, r5.xyzx
movc r1.xyz, r3.yyyy, r5.xyzx, r1.xyzx
sample_indexable(texture2d)(float,float,float,float) r3.yzw, v1.xyxx, t5.wxyz, s7
mul r3.yzw, r3.yyzw, r3.yyzw
mad r5.xyz, -r3.yzwy, l(0.500000, 0.500000, 0.500000, 0.000000), l(1.000000, 1.000000, 1.000000, 0.000000)
mul r1.xyz, r1.xyzx, r5.xyzx
sample_indexable(texture2d)(float,float,float,float) r2.w, v1.xyxx, t33.yzwx, s8
mul o0.xyz, r1.xyzx, r2.wwww
mov o0.w, l(1.000000)
dp3 r1.x, -r0.xyzx, -r0.xyzx
rsq r1.x, r1.x
mad r0.xyz, -r0.xyzx, r1.xxxx, r2.xyzx
dp3 r1.x, r0.xyzx, r0.xyzx
rsq r1.x, r1.x
mul r0.xyz, r0.xyzx, r1.xxxx
dp3_sat r0.x, r0.xyzx, r4.xyzx
log r0.x, r0.x
mul r0.y, r1.w, cb1[1].w
mad r0.z, r1.w, l(0.010000), cb1[1].w
div r0.y, r0.y, r0.z
max r0.y, r0.y, l(1.000000)
mul r0.x, r0.x, r0.y
mad r0.y, r0.y, l(0.125000), l(0.250000)
exp r0.x, r0.x
mul r1.xyz, r0.xxxx, cb1[2].xyzx
mul r1.xyz, r3.xxxx, r1.xyzx
mul r0.xzw, r0.wwww, r1.xxyz
mul r0.xyz, r0.yyyy, r0.xzwx
mul r0.xyz, r3.yzwy, r0.xyzx
mul o1.xyz, r2.wwww, r0.xyzx
mov o1.w, l(1.000000)
ret 
// Approximately 91 instruction slots used

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