// Point lights/shadows - fixed

Texture2D<float4> t3 : register(t3);

TextureCube<float4> t2 : register(t2);

Texture2D<float4> t1 : register(t1);

Texture2D<float4> t0 : register(t0);

SamplerState s3_s : register(s3);

SamplerState s2_s : register(s2);

SamplerState s1_s : register(s1);

SamplerState s0_s : register(s0);

cbuffer cb4 : register(b4)
{
  float4 cb4[4];
}

cbuffer cb3 : register(b3)
{
  float4 cb3[26];
}

cbuffer cb2 : register(b2)
{
  float4 cb2[2];
}

cbuffer cb1 : register(b1)
{
  float4 cb1[8];
}

cbuffer cb0 : register(b0)
{
  float4 cb0[11];
}




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


void main( 
  float4 v0 : SV_POSITION0,
  float4 v1 : TEXCOORD0,
  float3 v2 : TEXCOORD1,
  out float4 o0 : SV_Target0,
  float fov : TEXCOORD2)
{
  float4 r0,r1,r2,r3,r4,r5,r6;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xyz = cb0[9].xyz * cb0[3].xyz;
  r0.xz = r0.xx + r0.yz;
  r0.y = r0.y * r0.z;
  r0.x = cb0[9].z * cb0[3].z + r0.x;
  r0.y = sqrt(r0.y);
  r0.y = dot(cb0[3].ww, r0.yy);
  r0.x = r0.x + r0.y;
  r0.yz = v1.xy / v1.ww;
  r1.xyzw = t0.Sample(s0_s, r0.yz).xyzw;
  r2.xyzw = t3.Sample(s3_s, r0.yz).xyzw;
  r0.y = cb1[7].x * r1.x + cb1[7].y;
  r0.y = 1 / r0.y;
  r0.z = cb1[5].z / v2.z;
  r1.xyz = v2.xyz * r0.zzz;
  r1.xyw = r1.xyz * r0.yyy;
float4 stereo = StereoParams.Load(0);
float4 params = IniParams.Load(0);
r1.x -= stereo.x * (r1.w - stereo.y)*fov;
  r3.xyz = cb4[1].xyz * r1.yyy;
  r3.xyz = cb4[0].xyz * r1.xxx + r3.xyz;
  r3.xyz = cb4[2].xyz * r1.www + r3.xyz;
  r3.xyz = cb4[3].xyz + r3.xyz;
  r4.xyz = -cb0[8].xyz + r3.xyz;
  r5.xyz = float3(0.0078125,0.0078125,0.0078125) + r4.xyz;
  r5.xyzw = t2.Sample(s2_s, r5.xyz).xyzw;
  r6.xyz = float3(-0.0078125,-0.0078125,0.0078125) + r4.xyz;
  r6.xyzw = t2.Sample(s2_s, r6.xyz).xyzw;
  r5.y = r6.x;
  r6.xyz = float3(-0.0078125,0.0078125,-0.0078125) + r4.xyz;
  r6.xyzw = t2.Sample(s2_s, r6.xyz).xyzw;
  r5.z = r6.x;
  r6.xyz = float3(0.0078125,-0.0078125,-0.0078125) + r4.xyz;
  r6.xyzw = t2.Sample(s2_s, r6.xyz).xyzw;
  r5.w = r6.x;
  r0.z = dot(r4.xyz, r4.xyz);
  r0.w = sqrt(r0.z);
  r0.w = cb2[1].w * r0.w;
  r0.w = 0.970000029 * r0.w;
  r5.xyzw = cmp(r5.xyzw < r0.wwww);
  r5.xyzw = r5.xyzw ? cb3[24].xxxx : float4(1,1,1,1);
  r0.w = dot(r5.xyzw, float4(0.25,0.25,0.25,0.25));
  r1.x = cb0[8].w * r0.z;
  r0.z = rsqrt(r0.z);
  r4.xyz = r4.xyz * r0.zzz;
  r5.xyzw = t1.Sample(s1_s, r1.xx).xyzw;
  r0.z = r5.x * r0.w;
  r0.w = saturate(r0.z);
  r5.xyz = -cb1[4].xyz + r3.xyz;
  r3.xyz = -cb3[25].xyz + r3.xyz;
  r1.x = dot(r3.xyz, r3.xyz);
  r1.x = sqrt(r1.x);
  r0.y = -r1.z * r0.y + r1.x;
  r0.y = cb3[25].w * r0.y + r1.w;
  r0.y = r0.y * cb0[10].z + cb0[10].w;
  r0.y = saturate(1 + -r0.y);
  r1.x = dot(r5.xyz, r5.xyz);
  r1.x = rsqrt(r1.x);
  r1.xyz = -r5.xyz * r1.xxx + -r4.xyz;
  r1.w = dot(r1.xyz, r1.xyz);
  r1.w = rsqrt(r1.w);
  r1.xyz = r1.xyz * r1.www;
  r2.xyz = r2.xyz * float3(2,2,2) + float3(-1,-1,-1);
  r1.w = 128 * r2.w;
  r2.w = dot(r2.xyz, r2.xyz);
  r2.w = rsqrt(r2.w);
  r2.xyz = r2.xyz * r2.www;
  r1.x = dot(r1.xyz, r2.xyz);
  r1.y = dot(-r4.xyz, r2.xyz);
  r1.y = max(0, r1.y);
  r0.z = r1.y * r0.z;
  r2.xyz = cb0[9].xyz * r0.zzz;
  r0.z = max(0, r1.x);
  r0.z = log2(r0.z);
  r0.z = r1.w * r0.z;
  r0.z = exp2(r0.z);
  r0.z = r0.z * r0.w;
  r2.w = r0.z * r0.x;
  r0.xyzw = r2.xyzw * r0.yyyy;
  o0.xyzw = exp2(-r0.xyzw);
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Original ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) D3D Shader Disassembler
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float       
// TEXCOORD                 0   xyzw        1     NONE   float   xy w
// TEXCOORD                 1   xyz         2     NONE   float   xyz 
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_4_0
dcl_constantbuffer cb0[11], immediateIndexed
dcl_constantbuffer cb1[8], immediateIndexed
dcl_constantbuffer cb2[2], immediateIndexed
dcl_constantbuffer cb3[26], immediateIndexed
dcl_constantbuffer cb4[4], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_sampler s2, mode_default
dcl_sampler s3, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_texturecube (float,float,float,float) t2
dcl_resource_texture2d (float,float,float,float) t3
dcl_input_ps linear v1.xyw
dcl_input_ps linear v2.xyz
dcl_output o0.xyzw
dcl_temps 7
mul r0.xyz, cb0[3].xyzx, cb0[9].xyzx
add r0.xz, r0.yyzy, r0.xxxx
mul r0.y, r0.z, r0.y
mad r0.x, cb0[9].z, cb0[3].z, r0.x
sqrt r0.y, r0.y
dp2 r0.y, cb0[3].wwww, r0.yyyy
add r0.x, r0.y, r0.x
div r0.yz, v1.xxyx, v1.wwww
sample r1.xyzw, r0.yzyy, t0.xyzw, s0
sample r2.xyzw, r0.yzyy, t3.xyzw, s3
mad r0.y, cb1[7].x, r1.x, cb1[7].y
div r0.y, l(1.000000, 1.000000, 1.000000, 1.000000), r0.y
div r0.z, cb1[5].z, v2.z
mul r1.xyz, r0.zzzz, v2.xyzx
mul r1.xyw, r0.yyyy, r1.xyxz
mul r3.xyz, r1.yyyy, cb4[1].xyzx
mad r3.xyz, cb4[0].xyzx, r1.xxxx, r3.xyzx
mad r3.xyz, cb4[2].xyzx, r1.wwww, r3.xyzx
add r3.xyz, r3.xyzx, cb4[3].xyzx
add r4.xyz, r3.xyzx, -cb0[8].xyzx
add r5.xyz, r4.xyzx, l(0.007813, 0.007813, 0.007813, 0.000000)
sample r5.xyzw, r5.xyzx, t2.xyzw, s2
add r6.xyz, r4.xyzx, l(-0.007813, -0.007813, 0.007813, 0.000000)
sample r6.xyzw, r6.xyzx, t2.xyzw, s2
mov r5.y, r6.x
add r6.xyz, r4.xyzx, l(-0.007813, 0.007813, -0.007813, 0.000000)
sample r6.xyzw, r6.xyzx, t2.xyzw, s2
mov r5.z, r6.x
add r6.xyz, r4.xyzx, l(0.007813, -0.007813, -0.007813, 0.000000)
sample r6.xyzw, r6.xyzx, t2.xyzw, s2
mov r5.w, r6.x
dp3 r0.z, r4.xyzx, r4.xyzx
sqrt r0.w, r0.z
mul r0.w, r0.w, cb2[1].w
mul r0.w, r0.w, l(0.970000)
lt r5.xyzw, r5.xyzw, r0.wwww
movc r5.xyzw, r5.xyzw, cb3[24].xxxx, l(1.000000,1.000000,1.000000,1.000000)
dp4 r0.w, r5.xyzw, l(0.250000, 0.250000, 0.250000, 0.250000)
mul r1.x, r0.z, cb0[8].w
rsq r0.z, r0.z
mul r4.xyz, r0.zzzz, r4.xyzx
sample r5.xyzw, r1.xxxx, t1.xyzw, s1
mul r0.z, r0.w, r5.x
mov_sat r0.w, r0.z
add r5.xyz, r3.xyzx, -cb1[4].xyzx
add r3.xyz, r3.xyzx, -cb3[25].xyzx
dp3 r1.x, r3.xyzx, r3.xyzx
sqrt r1.x, r1.x
mad r0.y, -r1.z, r0.y, r1.x
mad r0.y, cb3[25].w, r0.y, r1.w
mad r0.y, r0.y, cb0[10].z, cb0[10].w
add_sat r0.y, -r0.y, l(1.000000)
dp3 r1.x, r5.xyzx, r5.xyzx
rsq r1.x, r1.x
mad r1.xyz, -r5.xyzx, r1.xxxx, -r4.xyzx
dp3 r1.w, r1.xyzx, r1.xyzx
rsq r1.w, r1.w
mul r1.xyz, r1.wwww, r1.xyzx
mad r2.xyz, r2.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
mul r1.w, r2.w, l(128.000000)
dp3 r2.w, r2.xyzx, r2.xyzx
rsq r2.w, r2.w
mul r2.xyz, r2.wwww, r2.xyzx
dp3 r1.x, r1.xyzx, r2.xyzx
dp3 r1.y, -r4.xyzx, r2.xyzx
max r1.y, r1.y, l(0.000000)
mul r0.z, r0.z, r1.y
mul r2.xyz, r0.zzzz, cb0[9].xyzx
max r0.z, r1.x, l(0.000000)
log r0.z, r0.z
mul r0.z, r0.z, r1.w
exp r0.z, r0.z
mul r0.z, r0.w, r0.z
mul r2.w, r0.x, r0.z
mul r0.xyzw, r0.yyyy, r2.xyzw
exp o0.xyzw, -r0.xyzw
ret 
// Approximately 0 instruction slots used

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


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Recompiled ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20789
//
//   using 3Dmigoto v1.2.43 on Wed Aug 17 22:49:10 2016
//
//
// Buffer Definitions: 
//
// cbuffer cb4
// {
//
//   float4 cb4[4];                     // Offset:    0 Size:    64
//
// }
//
// cbuffer cb3
// {
//
//   float4 cb3[26];                    // Offset:    0 Size:   416
//
// }
//
// cbuffer cb2
// {
//
//   float4 cb2[2];                     // Offset:    0 Size:    32
//
// }
//
// cbuffer cb1
// {
//
//   float4 cb1[8];                     // Offset:    0 Size:   128
//
// }
//
// cbuffer cb0
// {
//
//   float4 cb0[11];                    // Offset:    0 Size:   176
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// s0_s                              sampler      NA          NA    0        1
// s1_s                              sampler      NA          NA    1        1
// s2_s                              sampler      NA          NA    2        1
// s3_s                              sampler      NA          NA    3        1
// t0                                texture  float4          2d    0        1
// t1                                texture  float4          2d    1        1
// t2                                texture  float4        cube    2        1
// t3                                texture  float4          2d    3        1
// cb0                               cbuffer      NA          NA    0        1
// cb1                               cbuffer      NA          NA    1        1
// cb2                               cbuffer      NA          NA    2        1
// cb3                               cbuffer      NA          NA    3        1
// cb4                               cbuffer      NA          NA    4        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float       
// TEXCOORD                 0   xyzw        1     NONE   float   xy w
// TEXCOORD                 1   xyz         2     NONE   float   xyz 
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_4_0
dcl_constantbuffer cb4[4], immediateIndexed
dcl_constantbuffer cb3[26], immediateIndexed
dcl_constantbuffer cb2[2], immediateIndexed
dcl_constantbuffer cb1[8], immediateIndexed
dcl_constantbuffer cb0[11], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_sampler s2, mode_default
dcl_sampler s3, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_texturecube (float,float,float,float) t2
dcl_resource_texture2d (float,float,float,float) t3
dcl_input_ps linear v1.xyw
dcl_input_ps linear v2.xyz
dcl_output o0.xyzw
dcl_temps 7
mul r0.xyz, cb0[3].xyzx, cb0[9].xyzx
add r0.xz, r0.yyzy, r0.xxxx
mul r0.y, r0.z, r0.y
mad r0.x, cb0[9].z, cb0[3].z, r0.x
sqrt r0.y, r0.y
dp2 r0.y, cb0[3].wwww, r0.yyyy
add r0.x, r0.y, r0.x
div r0.yz, v1.xxyx, v1.wwww
sample r1.xyzw, r0.yzyy, t0.xyzw, s0
sample r2.xyzw, r0.yzyy, t3.xyzw, s3
mad r0.y, cb1[7].x, r1.x, cb1[7].y
div r0.y, l(1.000000, 1.000000, 1.000000, 1.000000), r0.y
div r0.z, cb1[5].z, v2.z
mul r1.xyz, r0.zzzz, v2.xyzx
mul r1.xyw, r0.yyyy, r1.xyxz
mul r3.xyz, r1.yyyy, cb4[1].xyzx
mad r3.xyz, cb4[0].xyzx, r1.xxxx, r3.xyzx
mad r3.xyz, cb4[2].xyzx, r1.wwww, r3.xyzx
add r3.xyz, r3.xyzx, cb4[3].xyzx
add r4.xyz, r3.xyzx, -cb0[8].xyzx
add r5.xyz, r4.xyzx, l(0.00781250000, 0.00781250000, 0.00781250000, 0.000000)
sample r5.xyzw, r5.xyzx, t2.xyzw, s2
add r6.xyz, r4.xyzx, l(-0.00781250000, -0.00781250000, 0.00781250000, 0.000000)
sample r6.xyzw, r6.xyzx, t2.xyzw, s2
mov r5.y, r6.x
add r6.xyz, r4.xyzx, l(-0.00781250000, 0.00781250000, -0.00781250000, 0.000000)
sample r6.xyzw, r6.xyzx, t2.xyzw, s2
mov r5.z, r6.x
add r6.xyz, r4.xyzx, l(0.00781250000, -0.00781250000, -0.00781250000, 0.000000)
sample r6.xyzw, r6.xyzx, t2.xyzw, s2
mov r5.w, r6.x
dp3 r0.z, r4.xyzx, r4.xyzx
sqrt r0.w, r0.z
mul r0.w, r0.w, cb2[1].w
mul r0.w, r0.w, l(0.970000)
lt r5.xyzw, r5.xyzw, r0.wwww
movc r5.xyzw, r5.xyzw, cb3[24].xxxx, l(1.000000,1.000000,1.000000,1.000000)
dp4 r0.w, r5.xyzw, l(0.250000, 0.250000, 0.250000, 0.250000)
mul r1.x, r0.z, cb0[8].w
rsq r0.z, r0.z
mul r4.xyz, r0.zzzz, r4.xyzx
sample r5.xyzw, r1.xxxx, t1.xyzw, s1
mul r0.z, r0.w, r5.x
mov_sat r0.w, r0.z
add r5.xyz, r3.xyzx, -cb1[4].xyzx
add r3.xyz, r3.xyzx, -cb3[25].xyzx
dp3 r1.x, r3.xyzx, r3.xyzx
sqrt r1.x, r1.x
mad r0.y, -r1.z, r0.y, r1.x
mad r0.y, cb3[25].w, r0.y, r1.w
mad r0.y, r0.y, cb0[10].z, cb0[10].w
add_sat r0.y, -r0.y, l(1.000000)
dp3 r1.x, r5.xyzx, r5.xyzx
rsq r1.x, r1.x
mad r1.xyz, -r5.xyzx, r1.xxxx, -r4.xyzx
dp3 r1.w, r1.xyzx, r1.xyzx
rsq r1.w, r1.w
mul r1.xyz, r1.wwww, r1.xyzx
mad r2.xyz, r2.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
mul r1.w, r2.w, l(128.000000)
dp3 r2.w, r2.xyzx, r2.xyzx
rsq r2.w, r2.w
mul r2.xyz, r2.wwww, r2.xyzx
dp3 r1.x, r1.xyzx, r2.xyzx
dp3 r1.y, -r4.xyzx, r2.xyzx
max r1.y, r1.y, l(0.000000)
mul r0.z, r0.z, r1.y
mul r2.xyz, r0.zzzz, cb0[9].xyzx
max r0.z, r1.x, l(0.000000)
log r0.z, r0.z
mul r0.z, r0.z, r1.w
exp r0.z, r0.z
mul r0.z, r0.w, r0.z
mul r2.w, r0.x, r0.z
mul r0.xyzw, r0.yyyy, r2.xyzw
exp o0.xyzw, -r0.xyzw
ret 
// Approximately 77 instruction slots used

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