// PreFix
// ---- Created with 3Dmigoto v1.2.29 on Thu Apr 07 23:45:32 2016

cbuffer _Globals : register(b0)
{
  row_major float4x4 m_shadow : 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);
}

SamplerState smp_material_s : register(s0);
SamplerComparisonState smp_smap_s : register(s1);
Texture2D<float4> s_smap : register(t0);
Texture2DMS<float4,2> s_position : register(t1);
Texture3D<float4> s_material : register(t2);


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


void main( 
  float4 v0 : TEXCOORD0,
  float4 v1 : SV_Position0,
  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.xyzw = s_position.Load(r0.xy, 0).xyzw;
  r1.x = abs(r0.y) * 2 + -1;
  r1.w = -r1.x * r1.x + 1;
  r1.w = -r0.x * r0.x + r1.w;
  r1.w = sqrt(abs(r1.w));
  r0.y = cmp(r0.y < 0);
  r0.y = r0.y ? -1 : 1;
  r1.y = r0.y * r1.w;
  r2.xy = v1.xy * pos_decompression_params.zw + -pos_decompression_params.xy;
  r2.xy = r2.xy * r0.zz;
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;
  r2.xyz = r1.xyz * float3(0.0149999997,0.0149999997,0.0149999997) + r2.xyz;
  r0.x = dot(r2.xyz, r2.xyz);
  r0.x = rsqrt(r0.x);
  r0.xyz = -r2.xyz * r0.xxx + -Ldynamic_dir.xyz;
  r1.w = dot(r0.xyz, r0.xyz);
  r1.w = rsqrt(r1.w);
  r0.xyz = r1.www * r0.xyz;
  r0.y = dot(r0.xyz, r1.xyz);
  r0.x = dot(-Ldynamic_dir.xyz, r1.xyz);
  r1.x = (int)r0.w & 0x80000000;
  if (4 == 0) r0.w = 0; else if (4+21 < 32) {   r0.w = (int)r0.w << (32-(4 + 21)); r0.w = (uint)r0.w >> (32-4);  } else r0.w = (uint)r0.w >> 21;
  r1.x = r1.x ? 16 : 0;
  bitmask.w = ((~(-1 << 4)) << 0) & 0xffffffff;
  r0.w = (((uint)r0.w << 0) & bitmask.w) | ((uint)r1.x & ~bitmask.w);
  r0.w = (uint)r0.w;
  r0.z = 0.0430107526 * r0.w;
  r0.xy = s_material.Sample(smp_material_s, r0.xyz).xy;
  r0.xyzw = Ldynamic_color.xyzw * r0.xxxy;
  r2.w = 1;
  r1.x = dot(m_shadow._m00_m01_m02_m03, r2.xyzw);
  r1.y = dot(m_shadow._m10_m11_m12_m13, r2.xyzw);
  r1.z = dot(m_shadow._m20_m21_m22_m23, r2.xyzw);
  r1.w = dot(m_shadow._m30_m31_m32_m33, r2.xyzw);
  r1.xyz = r1.xyz / r1.www;
  r2.xy = float2(-0.000292968762,-0.000292968762) + r1.xy;
  r1.w = s_smap.SampleCmpLevelZero(smp_smap_s, r2.xy, r1.z).x;
  r2.xy = float2(0.000292968762,-0.000292968762) + r1.xy;
  r2.x = s_smap.SampleCmpLevelZero(smp_smap_s, r2.xy, r1.z).x;
  r1.w = r2.x + r1.w;
  r2.xy = float2(-0.000292968762,0.000292968762) + r1.xy;
  r2.x = s_smap.SampleCmpLevelZero(smp_smap_s, r2.xy, r1.z).x;
  r1.w = r2.x + r1.w;
  r1.xy = float2(0.000292968762,0.000292968762) + r1.xy;
  r1.x = s_smap.SampleCmpLevelZero(smp_smap_s, r1.xy, r1.z).x;
  r1.x = r1.w + r1.x;
  r1.x = 0.25 * r1.x;
  o0.xyzw = r1.xxxx * r0.xyzw;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Original ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.27.952.3022
//
//
// Buffer Definitions: 
//
// cbuffer $Globals
// {
//
//   row_major float4x4 m_shadow;       // Offset:    0 Size:    64
//
// }
//
// 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 [unused]
//   float4 Ldynamic_dir;               // Offset:   32 Size:    16
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// smp_material                      sampler      NA          NA    0        1
// smp_smap                        sampler_c      NA          NA    1        1
// s_smap                            texture  float4          2d    0        1
// s_position                        texture  float4       2dMS2    1        1
// s_material                        texture  float4          3d    2        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  
//
//
// 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 cb0[4], immediateIndexed
dcl_constantbuffer cb1[21], immediateIndexed
dcl_constantbuffer cb2[3], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_comparison
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2dms(2) (float,float,float,float) t1
dcl_resource_texture3d (float,float,float,float) t2
dcl_input_ps_siv linear noperspective v1.xy, position
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.xyzw, r0.xyzw, t1.xyzw, l(0)
mad r1.x, |r0.y|, l(2.000000), l(-1.000000)
mad r1.w, -r1.x, r1.x, l(1.000000)
mad r1.w, -r0.x, r0.x, r1.w
sqrt r1.w, |r1.w|
lt r0.y, r0.y, l(0.000000)
movc r0.y, r0.y, l(-1.000000), l(1.000000)
mul r1.y, r1.w, r0.y
mad r2.xy, v1.xyxx, cb1[20].zwzz, -cb1[20].xyxx
mul r2.xy, r0.zzzz, r2.xyxx
mov r2.z, r0.z
mov r1.z, r0.x
mad r2.xyz, r1.xyzx, l(0.015000, 0.015000, 0.015000, 0.000000), r2.xyzx
dp3 r0.x, r2.xyzx, r2.xyzx
rsq r0.x, r0.x
mad r0.xyz, -r2.xyzx, r0.xxxx, -cb2[2].xyzx
dp3 r1.w, r0.xyzx, r0.xyzx
rsq r1.w, r1.w
mul r0.xyz, r0.xyzx, r1.wwww
dp3 r0.y, r0.xyzx, r1.xyzx
dp3 r0.x, -cb2[2].xyzx, r1.xyzx
and r1.x, r0.w, l(0x80000000)
ubfe r0.w, l(4), l(21), r0.w
movc r1.x, r1.x, l(16), l(0)
bfi r0.w, l(4), l(0), r0.w, r1.x
utof r0.w, r0.w
mul r0.z, r0.w, l(0.043011)
sample_indexable(texture3d)(float,float,float,float) r0.xy, r0.xyzx, t2.xyzw, s0
mul r0.xyzw, r0.xxxy, cb2[0].xyzw
mov r2.w, l(1.000000)
dp4 r1.x, cb0[0].xyzw, r2.xyzw
dp4 r1.y, cb0[1].xyzw, r2.xyzw
dp4 r1.z, cb0[2].xyzw, r2.xyzw
dp4 r1.w, cb0[3].xyzw, r2.xyzw
div r1.xyz, r1.xyzx, r1.wwww
add r2.xy, r1.xyxx, l(-0.000293, -0.000293, 0.000000, 0.000000)
sample_c_lz_indexable(texture2d)(float,float,float,float) r1.w, r2.xyxx, t0.xxxx, s1, r1.z
add r2.xy, r1.xyxx, l(0.000293, -0.000293, 0.000000, 0.000000)
sample_c_lz_indexable(texture2d)(float,float,float,float) r2.x, r2.xyxx, t0.xxxx, s1, r1.z
add r1.w, r1.w, r2.x
add r2.xy, r1.xyxx, l(-0.000293, 0.000293, 0.000000, 0.000000)
sample_c_lz_indexable(texture2d)(float,float,float,float) r2.x, r2.xyxx, t0.xxxx, s1, r1.z
add r1.w, r1.w, r2.x
add r1.xy, r1.xyxx, l(0.000293, 0.000293, 0.000000, 0.000000)
sample_c_lz_indexable(texture2d)(float,float,float,float) r1.x, r1.xyxx, t0.xxxx, s1, r1.z
add r1.x, r1.x, r1.w
mul r1.x, r1.x, l(0.250000)
mul o0.xyzw, r0.xyzw, r1.xxxx
ret 
// Approximately 51 instruction slots used

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


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Recompiled ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20789
//
//   using 3Dmigoto v1.2.29 on Thu Apr 07 23:45:32 2016
//
//
// Buffer Definitions: 
//
// cbuffer _Globals
// {
//
//   row_major float4x4 m_shadow;       // Offset:    0 Size:    64
//
// }
//
// 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 [unused]
//   float4 Ldynamic_dir;               // Offset:   32 Size:    16
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// smp_material_s                    sampler      NA          NA    0        1
// smp_smap_s                      sampler_c      NA          NA    1        1
// s_smap                            texture  float4          2d    0        1
// s_position                        texture  float4       2dMS2    1        1
// s_material                        texture  float4          3d    2        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  
//
//
// 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 cb0[4], immediateIndexed
dcl_constantbuffer cb1[21], immediateIndexed
dcl_constantbuffer cb2[3], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_comparison
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2dms(2) (float,float,float,float) t1
dcl_resource_texture3d (float,float,float,float) t2
dcl_input_ps_siv linear noperspective v1.xy, position
dcl_output o0.xyzw
dcl_temps 4
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.xyzw, r0.xyzw, t1.xyzw, l(0)
mad r1.x, |r0.y|, l(2.000000), l(-1.000000)
mad r1.w, -r1.x, r1.x, l(1.000000)
mad r1.w, -r0.x, r0.x, r1.w
sqrt r1.w, |r1.w|
lt r0.y, r0.y, l(0.000000)
movc r0.y, r0.y, l(-1.000000), l(1.000000)
mul r1.y, r1.w, r0.y
mad r2.xy, v1.xyxx, cb1[20].zwzz, -cb1[20].xyxx
mul r2.xy, r0.zzzz, r2.xyxx
mov r2.z, r0.z
mov r1.z, r0.x
ftoi r0.x, r0.w
mad r2.xyz, r1.xyzx, l(0.015000, 0.015000, 0.015000, 0.000000), r2.xyzx
dp3 r0.y, r2.xyzx, r2.xyzx
rsq r0.y, r0.y
mad r0.yzw, -r2.xxyz, r0.yyyy, -cb2[2].xxyz
dp3 r1.w, r0.yzwy, r0.yzwy
rsq r1.w, r1.w
mul r0.yzw, r0.yyzw, r1.wwww
dp3 r3.y, r0.yzwy, r1.xyzx
dp3 r3.x, -cb2[2].xyzx, r1.xyzx
ishl r0.y, r0.x, l(7)
and r0.x, r0.x, l(0x80000000)
utof r0.x, r0.x
ne r0.x, l(0.000000, 0.000000, 0.000000, 0.000000), r0.x
and r0.x, r0.x, l(16)
itof r0.y, r0.y
ftou r0.y, r0.y
ushr r0.y, r0.y, l(28)
iadd r0.x, r0.x, r0.y
utof r0.x, r0.x
mul r3.z, r0.x, l(0.0430107526)
sample_indexable(texture3d)(float,float,float,float) r0.xy, r3.xyzx, t2.xyzw, s0
mul r0.xyzw, r0.xxxy, cb2[0].xyzw
mov r2.w, l(1.000000)
dp4 r1.x, cb0[0].xyzw, r2.xyzw
dp4 r1.y, cb0[1].xyzw, r2.xyzw
dp4 r1.z, cb0[2].xyzw, r2.xyzw
dp4 r1.w, cb0[3].xyzw, r2.xyzw
div r1.xyz, r1.xyzx, r1.wwww
add r2.xyzw, r1.xyxy, l(-0.000292968762, -0.000292968762, 0.000292968762, -0.000292968762)
sample_c_lz_indexable(texture2d)(float,float,float,float) r1.w, r2.xyxx, t0.xxxx, s1, r1.z
sample_c_lz_indexable(texture2d)(float,float,float,float) r2.x, r2.zwzz, t0.xxxx, s1, r1.z
add r1.w, r1.w, r2.x
add r2.xyzw, r1.xyxy, l(-0.000292968762, 0.000292968762, 0.000292968762, 0.000292968762)
sample_c_lz_indexable(texture2d)(float,float,float,float) r1.x, r2.xyxx, t0.xxxx, s1, r1.z
sample_c_lz_indexable(texture2d)(float,float,float,float) r1.y, r2.zwzz, t0.xxxx, s1, r1.z
add r1.x, r1.w, r1.x
add r1.x, r1.y, r1.x
mul r1.x, r1.x, l(0.250000)
mul o0.xyzw, r0.xyzw, r1.xxxx
ret 
// Approximately 56 instruction slots used

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