// PreFix
// ---- Created with 3Dmigoto v1.2.29 on Mon Apr 04 23:03:54 2016

cbuffer static_globals : register(b0)
{
  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(b1)
{
  float4 Ldynamic_color : packoffset(c0);
  float4 Ldynamic_pos : packoffset(c1);
  float4 Ldynamic_dir : packoffset(c2);
}

SamplerState smp_nofilter_s : register(s0);
SamplerState smp_material_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( 
  float2 v0 : TEXCOORD0,
  float2 w0 : TEXCOORD1,
  float2 v1 : TEXCOORD2,
  float2 w1 : TEXCOORD3,
  float2 v2 : TEXCOORD4,
  float2 w2 : TEXCOORD5,
  float4 v3 : SV_Position0,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xy = v3.xy * pos_decompression_params.zw + -pos_decompression_params.xy;
  r1.xy = (int2)v3.xy;
  r1.zw = float2(0,0);
  r1.xyzw = s_position.Load(r1.xy, 0).xyzw;
  r0.xy = r1.zz * r0.xy;
float4 stereo = StereoParams.Load(0);
float4 params = IniParams.Load(0);
r0.x -= stereo.x * (r1.z - stereo.y)/m_P._m00;
  r0.z = r1.z;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r0.xyz = -r0.xyz * r0.www + -Ldynamic_dir.xyz;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r0.xyz = r0.xyz * r0.www;
  r2.x = abs(r1.y) * 2 + -1;
  r0.w = -r2.x * r2.x + 1;
  r0.w = -r1.x * r1.x + r0.w;
  r0.w = sqrt(abs(r0.w));
  r1.y = cmp(r1.y < 0);
  r1.y = r1.y ? -1 : 1;
  r2.y = r1.y * r0.w;
  r2.z = r1.x;
  r0.y = dot(r0.xyz, r2.xyz);
  r0.x = dot(-Ldynamic_dir.xyz, r2.xyz);
  r0.w = (int)r1.w & 0x80000000;
  if (4 == 0) r1.x = 0; else if (4+21 < 32) {   r1.x = (int)r1.w << (32-(4 + 21)); r1.x = (uint)r1.x >> (32-4);  } else r1.x = (uint)r1.w >> 21;
  r0.w = r0.w ? 16 : 0;
  bitmask.w = ((~(-1 << 4)) << 0) & 0xffffffff;
  r0.w = (((uint)r1.x << 0) & bitmask.w) | ((uint)r0.w & ~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;
  r1.x = s_smap.Sample(smp_nofilter_s, v1.xy).x;
  r1.y = s_smap.Sample(smp_nofilter_s, w1.xy).y;
  r1.x = r1.x + r1.y;
  r1.y = s_smap.Sample(smp_nofilter_s, v2.xy).z;
  r1.z = s_smap.Sample(smp_nofilter_s, w2.xy).w;
  r1.y = r1.y + r1.z;
  r1.x = r1.x + r1.y;
  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 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_nofilter                      sampler      NA          NA    0        1
// smp_material                      sampler      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
// static_globals                    cbuffer      NA          NA    0        1
// dynamic_light                     cbuffer      NA          NA    1        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD                 0   xy          0     NONE   float       
// TEXCOORD                 1     zw        0     NONE   float       
// TEXCOORD                 2   xy          1     NONE   float   xy  
// TEXCOORD                 3     zw        1     NONE   float     zw
// TEXCOORD                 4   xy          2     NONE   float   xy  
// TEXCOORD                 5     zw        2     NONE   float     zw
// SV_Position              0   xyzw        3      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[21], immediateIndexed
dcl_constantbuffer cb1[3], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
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 linear v1.xy
dcl_input_ps linear v1.zw
dcl_input_ps linear v2.xy
dcl_input_ps linear v2.zw
dcl_input_ps_siv linear noperspective v3.xy, position
dcl_output o0.xyzw
dcl_temps 3
mad r0.xy, v3.xyxx, cb0[20].zwzz, -cb0[20].xyxx
ftoi r1.xy, v3.xyxx
mov r1.zw, l(0,0,0,0)
ldms_indexable(texture2dms)(float,float,float,float) r1.xyzw, r1.xyzw, t1.xyzw, l(0)
mul r0.xy, r0.xyxx, r1.zzzz
mov r0.z, r1.z
dp3 r0.w, r0.xyzx, r0.xyzx
rsq r0.w, r0.w
mad r0.xyz, -r0.xyzx, r0.wwww, -cb1[2].xyzx
dp3 r0.w, r0.xyzx, r0.xyzx
rsq r0.w, r0.w
mul r0.xyz, r0.wwww, r0.xyzx
mad r2.x, |r1.y|, l(2.000000), l(-1.000000)
mad r0.w, -r2.x, r2.x, l(1.000000)
mad r0.w, -r1.x, r1.x, r0.w
sqrt r0.w, |r0.w|
lt r1.y, r1.y, l(0.000000)
movc r1.y, r1.y, l(-1.000000), l(1.000000)
mul r2.y, r0.w, r1.y
mov r2.z, r1.x
dp3 r0.y, r0.xyzx, r2.xyzx
dp3 r0.x, -cb1[2].xyzx, r2.xyzx
and r0.w, r1.w, l(0x80000000)
ubfe r1.x, l(4), l(21), r1.w
movc r0.w, r0.w, l(16), l(0)
bfi r0.w, l(4), l(0), r1.x, r0.w
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, s1
mul r0.xyzw, r0.xxxy, cb1[0].xyzw
sample_indexable(texture2d)(float,float,float,float) r1.x, v1.xyxx, t0.xyzw, s0
sample_indexable(texture2d)(float,float,float,float) r1.y, v1.zwzz, t0.xyzw, s0
add r1.x, r1.y, r1.x
sample_indexable(texture2d)(float,float,float,float) r1.y, v2.xyxx, t0.xzyw, s0
sample_indexable(texture2d)(float,float,float,float) r1.z, v2.zwzz, t0.xywz, s0
add r1.y, r1.z, r1.y
add r1.x, r1.y, r1.x
mul r1.x, r1.x, l(0.250000)
mul o0.xyzw, r0.xyzw, r1.xxxx
ret 
// Approximately 40 instruction slots used

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


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Recompiled ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20789
//
//   using 3Dmigoto v1.2.29 on Mon Apr 04 23:03:55 2016
//
//
// Buffer Definitions: 
//
// 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_nofilter_s                    sampler      NA          NA    0        1
// smp_material_s                    sampler      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
// static_globals                    cbuffer      NA          NA    0        1
// dynamic_light                     cbuffer      NA          NA    1        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD                 0   xy          0     NONE   float       
// TEXCOORD                 1     zw        0     NONE   float       
// TEXCOORD                 2   xy          1     NONE   float   xy  
// TEXCOORD                 3     zw        1     NONE   float     zw
// TEXCOORD                 4   xy          2     NONE   float   xy  
// TEXCOORD                 5     zw        2     NONE   float     zw
// SV_Position              0   xyzw        3      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[21], immediateIndexed
dcl_constantbuffer cb1[3], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
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 linear v1.xy
dcl_input_ps linear v1.zw
dcl_input_ps linear v2.xy
dcl_input_ps linear v2.zw
dcl_input_ps_siv linear noperspective v3.xy, position
dcl_output o0.xyzw
dcl_temps 3
mad r0.xy, v3.xyxx, cb0[20].zwzz, -cb0[20].xyxx
round_z r0.zw, v3.xxxy
ftoi r1.xy, r0.zwzz
mov r1.zw, l(0,0,0,0)
ldms_indexable(texture2dms)(float,float,float,float) r1.xyzw, r1.xyzw, t1.xyzw, l(0)
mul r0.xy, r0.xyxx, r1.zzzz
mov r0.z, r1.z
dp3 r0.w, r0.xyzx, r0.xyzx
rsq r0.w, r0.w
mad r0.xyz, -r0.xyzx, r0.wwww, -cb1[2].xyzx
dp3 r0.w, r0.xyzx, r0.xyzx
rsq r0.w, r0.w
mul r0.xyz, r0.wwww, r0.xyzx
mad r2.x, |r1.y|, l(2.000000), l(-1.000000)
mad r0.w, -r2.x, r2.x, l(1.000000)
mad r0.w, -r1.x, r1.x, r0.w
sqrt r0.w, |r0.w|
lt r1.y, r1.y, l(0.000000)
movc r1.y, r1.y, l(-1.000000), l(1.000000)
mul r2.y, r0.w, r1.y
mov r2.z, r1.x
ftoi r0.w, r1.w
dp3 r0.y, r0.xyzx, r2.xyzx
dp3 r0.x, -cb1[2].xyzx, r2.xyzx
ishl r1.x, r0.w, l(7)
and r0.w, r0.w, l(0x80000000)
utof r0.w, r0.w
ne r0.w, l(0.000000, 0.000000, 0.000000, 0.000000), r0.w
and r0.w, r0.w, l(16)
itof r1.x, r1.x
ftou r1.x, r1.x
ushr r1.x, r1.x, l(28)
iadd r0.w, r0.w, r1.x
utof r0.w, r0.w
mul r0.z, r0.w, l(0.0430107526)
sample_indexable(texture3d)(float,float,float,float) r0.xy, r0.xyzx, t2.xyzw, s1
mul r0.xyzw, r0.xxxy, cb1[0].xyzw
sample_indexable(texture2d)(float,float,float,float) r1.x, v1.xyxx, t0.xyzw, s0
sample_indexable(texture2d)(float,float,float,float) r1.y, v1.zwzz, t0.xyzw, s0
add r1.x, r1.y, r1.x
sample_indexable(texture2d)(float,float,float,float) r1.y, v2.xyxx, t0.xzyw, s0
sample_indexable(texture2d)(float,float,float,float) r1.z, v2.zwzz, t0.xywz, s0
add r1.y, r1.z, r1.y
add r1.x, r1.y, r1.x
mul r1.x, r1.x, l(0.250000)
mul o0.xyzw, r0.xyzw, r1.xxxx
ret 
// Approximately 47 instruction slots used

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