// PreFix
// ---- Created with 3Dmigoto v1.2.29 on Wed Apr 13 13:31:32 2016

cbuffer _Globals : register(b0)
{
  float3 direction : packoffset(c0);
}

cbuffer static_globals : register(b1)
{
  row_major float3x4 m_V : packoffset(c0);
  row_major float4x4 m_P : packoffset(c3);
  row_major float4x4 m_VP : packoffset(c7);
  float4 timers : packoffset(c11);
  float4 fog_plane : packoffset(c12);
  float4 fog_params : packoffset(c13);
  float4 fog_color : packoffset(c14);
  float4 L_ambient : packoffset(c15);
  float3 L_sun_color : packoffset(c16);
  float3 L_sun_dir_w : packoffset(c17);
  float4 L_hemi_color : packoffset(c18);
  float3 eye_position : packoffset(c19);
  float4 pos_decompression_params : packoffset(c20);
  float4 pos_decompression_params2 : packoffset(c21);
}

cbuffer dynamic_light : register(b2)
{
  float4 Ldynamic_color : packoffset(c0);
  float4 Ldynamic_pos : packoffset(c1);
  float4 Ldynamic_dir : packoffset(c2);
}

Texture2DMS<float4,4> s_position : register(t0);


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


void main( 
  float4 v0 : TEXCOORD0,
  float4 v1 : SV_Position0,
  uint v2 : SV_SAMPLEINDEX0,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xy = (int2)v1.xy;
  r0.zw = float2(0,0);
  r0.xyz = s_position.Load(r0.xy, v2.x).xyz;
  r1.x = abs(r0.y) * 2 + -1;
  r0.w = -r1.x * r1.x + 1;
  r0.w = -r0.x * r0.x + r0.w;
  r0.w = sqrt(abs(r0.w));
  r0.y = cmp(r0.y < 0);
  r0.y = r0.y ? -1 : 1;
  r1.y = r0.y * r0.w;
  r0.yw = v1.xy * pos_decompression_params.zw + -pos_decompression_params.xy;
  r2.xy = r0.zz * r0.yw;
float4 stereo = StereoParams.Load(0);
float4 params = IniParams.Load(0);
r2.x -= stereo.x * (r0.z - stereo.y)/m_P._m00;
  r2.z = r0.z;
  r1.z = r0.x;
  r0.xyz = -Ldynamic_pos.xyz + r2.xyz;
  r0.w = dot(r0.xyz, r0.xyz);
  r1.w = rsqrt(r0.w);
  r0.w = saturate(-r0.w * Ldynamic_pos.w + 1);
  r2.xyz = Ldynamic_color.xyz * r0.www;
  r0.xyz = r1.www * r0.xyz;
  r0.w = saturate(dot(-r0.xyz, r1.xyz));
  r0.x = saturate(dot(r0.xyz, direction.xyz));
  r0.yzw = r2.xyz * r0.www;
  o0.xyz = r0.yzw * r0.xxx;
  o0.w = 0;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Original ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.27.952.3022
//
//
// Buffer Definitions: 
//
// cbuffer $Globals
// {
//
//   float3 direction;                  // Offset:    0 Size:    12
//
// }
//
// cbuffer static_globals
// {
//
//   row_major float3x4 m_V;            // Offset:    0 Size:    48 [unused]
//   row_major float4x4 m_P;            // Offset:   48 Size:    64 [unused]
//   row_major float4x4 m_VP;           // Offset:  112 Size:    64 [unused]
//   float4 timers;                     // Offset:  176 Size:    16 [unused]
//   float4 fog_plane;                  // Offset:  192 Size:    16 [unused]
//   float4 fog_params;                 // Offset:  208 Size:    16 [unused]
//   float4 fog_color;                  // Offset:  224 Size:    16 [unused]
//   float4 L_ambient;                  // Offset:  240 Size:    16 [unused]
//   float3 L_sun_color;                // Offset:  256 Size:    12 [unused]
//   float3 L_sun_dir_w;                // Offset:  272 Size:    12 [unused]
//   float4 L_hemi_color;               // Offset:  288 Size:    16 [unused]
//   float3 eye_position;               // Offset:  304 Size:    12 [unused]
//   float4 pos_decompression_params;   // Offset:  320 Size:    16
//   float4 pos_decompression_params2;  // Offset:  336 Size:    16 [unused]
//
// }
//
// cbuffer dynamic_light
// {
//
//   float4 Ldynamic_color;             // Offset:    0 Size:    16
//   float4 Ldynamic_pos;               // Offset:   16 Size:    16
//   float4 Ldynamic_dir;               // Offset:   32 Size:    16 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// s_position                        texture  float4       2dMS4    0        1
// $Globals                          cbuffer      NA          NA    0        1
// static_globals                    cbuffer      NA          NA    1        1
// dynamic_light                     cbuffer      NA          NA    2        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD                 0   xyzw        0     NONE   float       
// SV_Position              0   xyzw        1      POS   float   xy  
// SV_SAMPLEINDEX           0   x           2   SAMPLE    uint   x   
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
// Pixel Shader runs at sample frequency
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[1], immediateIndexed
dcl_constantbuffer cb1[21], immediateIndexed
dcl_constantbuffer cb2[2], immediateIndexed
dcl_resource_texture2dms(4) (float,float,float,float) t0
dcl_input_ps_siv linear noperspective v1.xy, position
dcl_input_ps_sgv v2.x, sampleIndex
dcl_output o0.xyzw
dcl_temps 3
ftoi r0.xy, v1.xyxx
mov r0.zw, l(0,0,0,0)
ldms_indexable(texture2dms)(float,float,float,float) r0.xyz, r0.xyzw, t0.xyzw, v2.x
mad r1.x, |r0.y|, l(2.000000), l(-1.000000)
mad r0.w, -r1.x, r1.x, l(1.000000)
mad r0.w, -r0.x, r0.x, r0.w
sqrt r0.w, |r0.w|
lt r0.y, r0.y, l(0.000000)
movc r0.y, r0.y, l(-1.000000), l(1.000000)
mul r1.y, r0.w, r0.y
mad r0.yw, v1.xxxy, cb1[20].zzzw, -cb1[20].xxxy
mul r2.xy, r0.ywyy, r0.zzzz
mov r2.z, r0.z
mov r1.z, r0.x
add r0.xyz, r2.xyzx, -cb2[1].xyzx
dp3 r0.w, r0.xyzx, r0.xyzx
rsq r1.w, r0.w
mad_sat r0.w, -r0.w, cb2[1].w, l(1.000000)
mul r2.xyz, r0.wwww, cb2[0].xyzx
mul r0.xyz, r0.xyzx, r1.wwww
dp3_sat r0.w, -r0.xyzx, r1.xyzx
dp3_sat r0.x, r0.xyzx, cb0[0].xyzx
mul r0.yzw, r0.wwww, r2.xxyz
mul o0.xyz, r0.xxxx, r0.yzwy
mov o0.w, l(0)
ret 
// Approximately 26 instruction slots used

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


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Recompiled ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20789
//
//   using 3Dmigoto v1.2.29 on Wed Apr 13 13:31:32 2016
//
//
// Buffer Definitions: 
//
// cbuffer _Globals
// {
//
//   float3 direction;                  // Offset:    0 Size:    12
//
// }
//
// cbuffer static_globals
// {
//
//   row_major float3x4 m_V;            // Offset:    0 Size:    48 [unused]
//   row_major float4x4 m_P;            // Offset:   48 Size:    64 [unused]
//   row_major float4x4 m_VP;           // Offset:  112 Size:    64 [unused]
//   float4 timers;                     // Offset:  176 Size:    16 [unused]
//   float4 fog_plane;                  // Offset:  192 Size:    16 [unused]
//   float4 fog_params;                 // Offset:  208 Size:    16 [unused]
//   float4 fog_color;                  // Offset:  224 Size:    16 [unused]
//   float4 L_ambient;                  // Offset:  240 Size:    16 [unused]
//   float3 L_sun_color;                // Offset:  256 Size:    12 [unused]
//   float3 L_sun_dir_w;                // Offset:  272 Size:    12 [unused]
//   float4 L_hemi_color;               // Offset:  288 Size:    16 [unused]
//   float3 eye_position;               // Offset:  304 Size:    12 [unused]
//   float4 pos_decompression_params;   // Offset:  320 Size:    16
//   float4 pos_decompression_params2;  // Offset:  336 Size:    16 [unused]
//
// }
//
// cbuffer dynamic_light
// {
//
//   float4 Ldynamic_color;             // Offset:    0 Size:    16
//   float4 Ldynamic_pos;               // Offset:   16 Size:    16
//   float4 Ldynamic_dir;               // Offset:   32 Size:    16 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// s_position                        texture  float4       2dMS4    0        1
// _Globals                          cbuffer      NA          NA    0        1
// static_globals                    cbuffer      NA          NA    1        1
// dynamic_light                     cbuffer      NA          NA    2        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD                 0   xyzw        0     NONE   float       
// SV_Position              0   xyzw        1      POS   float   xy  
// SV_SAMPLEINDEX           0   x           2   SAMPLE    uint   x   
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
// Pixel Shader runs at sample frequency
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[1], immediateIndexed
dcl_constantbuffer cb1[21], immediateIndexed
dcl_constantbuffer cb2[2], immediateIndexed
dcl_resource_texture2dms(4) (float,float,float,float) t0
dcl_input_ps_siv linear noperspective v1.xy, position
dcl_input_ps_sgv v2.x, sampleIndex
dcl_output o0.xyzw
dcl_temps 3
round_z r0.xy, v1.xyxx
ftoi r0.xy, r0.xyxx
mov r0.zw, l(0,0,0,0)
ldms_indexable(texture2dms)(float,float,float,float) r0.xyz, r0.xyzw, t0.xyzw, v2.x
mad r1.x, |r0.y|, l(2.000000), l(-1.000000)
mad r0.w, -r1.x, r1.x, l(1.000000)
mad r0.w, -r0.x, r0.x, r0.w
sqrt r0.w, |r0.w|
lt r0.y, r0.y, l(0.000000)
movc r0.y, r0.y, l(-1.000000), l(1.000000)
mul r1.y, r0.w, r0.y
mad r0.yw, v1.xxxy, cb1[20].zzzw, -cb1[20].xxxy
mul r2.xy, r0.ywyy, r0.zzzz
mov r2.z, r0.z
mov r1.z, r0.x
add r0.xyz, r2.xyzx, -cb2[1].xyzx
dp3 r0.w, r0.xyzx, r0.xyzx
rsq r1.w, r0.w
mad_sat r0.w, -r0.w, cb2[1].w, l(1.000000)
mul r2.xyz, r0.wwww, cb2[0].xyzx
mul r0.xyz, r0.xyzx, r1.wwww
dp3_sat r0.w, -r0.xyzx, r1.xyzx
dp3_sat r0.x, r0.xyzx, cb0[0].xyzx
mul r0.yzw, r0.wwww, r2.xxyz
mul o0.xyz, r0.xxxx, r0.yzwy
mov o0.w, l(0)
ret 
// Approximately 27 instruction slots used

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