// PreFix

cbuffer _Globals : register(b0)
{
  row_major float4x4 m_shadow : packoffset(c0);
  row_major float3x4 m_sunmask : packoffset(c4);
}

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);
}

SamplerState smp_nofilter_s : register(s0);
SamplerState smp_linear_s : register(s1);
SamplerComparisonState smp_smap_s : register(s2);
Texture2D<float4> s_smap : register(t0);
Texture2D<float4> s_position : register(t1);
Texture2D<float4> s_water : register(t2);


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


void main( 
  float2 v0 : TEXCOORD0,
  float2 w0 : TEXCOORD1,
  float4 v1 : SV_Position0,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xy = v1.xy * pos_decompression_params.zw + -pos_decompression_params.xy;
  r1.z = s_position.Sample(smp_nofilter_s, v0.xy).z;
  r1.xy = r1.zz * r0.xy;
float4 stereo = StereoParams.Load(0);
float4 params = IniParams.Load(0);
r1.x -= stereo.x * (r1.z - stereo.y)/m_P._m00;
  r1.w = 1;
  r0.x = dot(m_shadow._m00_m01_m02_m03, r1.xyzw);
  r0.y = dot(m_shadow._m10_m11_m12_m13, r1.xyzw);
  r0.z = dot(m_shadow._m20_m21_m22_m23, r1.xyzw);
  r0.w = dot(m_shadow._m30_m31_m32_m33, r1.xyzw);
  r0.xyz = r0.xyz / r0.www;
  r2.xy = float2(-0.000292968762,-0.000292968762) + r0.xy;
  r0.w = s_smap.SampleCmpLevelZero(smp_smap_s, r2.xy, r0.z).x;
  r2.xy = float2(0.000292968762,-0.000292968762) + r0.xy;
  r2.x = s_smap.SampleCmpLevelZero(smp_smap_s, r2.xy, r0.z).x;
  r0.w = r2.x + r0.w;
  r2.xy = float2(-0.000292968762,0.000292968762) + r0.xy;
  r2.x = s_smap.SampleCmpLevelZero(smp_smap_s, r2.xy, r0.z).x;
  r0.w = r2.x + r0.w;
  r0.xy = float2(0.000292968762,0.000292968762) + r0.xy;
  r0.x = s_smap.SampleCmpLevelZero(smp_smap_s, r0.xy, r0.z).x;
  r0.x = r0.w + r0.x;
  r0.y = 0.25 * r0.x;
  o0.w = 0.125 * r0.x;
  r2.x = dot(m_sunmask._m00_m01_m02_m03, r1.xyzw);
  r2.y = dot(m_sunmask._m10_m11_m12_m13, r1.xyzw);
  r0.xz = float2(0.5,0.5) * r2.xy;
  r0.xz = frac(r0.xz);
  r0.xzw = s_water.SampleLevel(smp_linear_s, r0.xz, 0).xyz;
  r0.xzw = float3(-0.5,-0.5,-0.5) + r0.xwz;
  r0.xzw = r0.xzw + r0.xzw;
  r1.x = dot(m_V._m00_m01_m02, r0.xzw);
  r1.y = dot(m_V._m10_m11_m12, r0.xzw);
  r1.z = dot(m_V._m20_m21_m22, r0.xzw);
  o0.xyz = r1.xyz * r0.yyy;
  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
//   row_major float3x4 m_sunmask;      // Offset:   64 Size:    48
//
// }
//
// cbuffer static_globals
// {
//
//   row_major float3x4 m_V;            // Offset:    0 Size:    48
//   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]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// smp_nofilter                      sampler      NA          NA    0        1
// smp_linear                        sampler      NA          NA    1        1
// smp_smap                        sampler_c      NA          NA    2        1
// s_smap                            texture  float4          2d    0        1
// s_position                        texture  float4          2d    1        1
// s_water                           texture  float4          2d    2        1
// $Globals                          cbuffer      NA          NA    0        1
// static_globals                    cbuffer      NA          NA    1        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD                 0   xy          0     NONE   float   xy  
// TEXCOORD                 1     zw        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[6], immediateIndexed
dcl_constantbuffer cb1[21], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_sampler s2, mode_comparison
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_texture2d (float,float,float,float) t2
dcl_input_ps linear v0.xy
dcl_input_ps_siv linear noperspective v1.xy, position
dcl_output o0.xyzw
dcl_temps 3
mad r0.xy, v1.xyxx, cb1[20].zwzz, -cb1[20].xyxx
sample_indexable(texture2d)(float,float,float,float) r1.z, v0.xyxx, t1.xyzw, s0
mul r1.xy, r0.xyxx, r1.zzzz
mov r1.w, l(1.000000)
dp4 r0.x, cb0[0].xyzw, r1.xyzw
dp4 r0.y, cb0[1].xyzw, r1.xyzw
dp4 r0.z, cb0[2].xyzw, r1.xyzw
dp4 r0.w, cb0[3].xyzw, r1.xyzw
div r0.xyz, r0.xyzx, r0.wwww
add r2.xy, r0.xyxx, l(-0.000293, -0.000293, 0.000000, 0.000000)
sample_c_lz_indexable(texture2d)(float,float,float,float) r0.w, r2.xyxx, t0.xxxx, s2, r0.z
add r2.xy, r0.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, s2, r0.z
add r0.w, r0.w, r2.x
add r2.xy, r0.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, s2, r0.z
add r0.w, r0.w, r2.x
add r0.xy, r0.xyxx, l(0.000293, 0.000293, 0.000000, 0.000000)
sample_c_lz_indexable(texture2d)(float,float,float,float) r0.x, r0.xyxx, t0.xxxx, s2, r0.z
add r0.x, r0.x, r0.w
mul r0.y, r0.x, l(0.250000)
mul o0.w, r0.x, l(0.125000)
dp4 r2.x, cb0[4].xyzw, r1.xyzw
dp4 r2.y, cb0[5].xyzw, r1.xyzw
mul r0.xz, r2.xxyx, l(0.500000, 0.000000, 0.500000, 0.000000)
frc r0.xz, r0.xxzx
sample_l_indexable(texture2d)(float,float,float,float) r0.xzw, r0.xzxx, t2.xwyz, s1, l(0.000000)
add r0.xzw, r0.xxwz, l(-0.500000, 0.000000, -0.500000, -0.500000)
add r0.xzw, r0.xxzw, r0.xxzw
dp3 r1.x, cb1[0].xyzx, r0.xzwx
dp3 r1.y, cb1[1].xyzx, r0.xzwx
dp3 r1.z, cb1[2].xyzx, r0.xzwx
mul o0.xyz, r0.yyyy, r1.xyzx
ret 
// Approximately 34 instruction slots used

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


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Recompiled ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20789
//
//   using 3Dmigoto v1.2.29 on Thu Mar 24 07:36:28 2016
//
//
// Buffer Definitions: 
//
// cbuffer _Globals
// {
//
//   row_major float4x4 m_shadow;       // Offset:    0 Size:    64
//   row_major float3x4 m_sunmask;      // Offset:   64 Size:    48
//
// }
//
// cbuffer static_globals
// {
//
//   row_major float3x4 m_V;            // Offset:    0 Size:    48
//   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]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// smp_nofilter_s                    sampler      NA          NA    0        1
// smp_linear_s                      sampler      NA          NA    1        1
// smp_smap_s                      sampler_c      NA          NA    2        1
// s_smap                            texture  float4          2d    0        1
// s_position                        texture  float4          2d    1        1
// s_water                           texture  float4          2d    2        1
// _Globals                          cbuffer      NA          NA    0        1
// static_globals                    cbuffer      NA          NA    1        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD                 0   xy          0     NONE   float   xy  
// TEXCOORD                 1     zw        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[6], immediateIndexed
dcl_constantbuffer cb1[21], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_sampler s2, mode_comparison
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_texture2d (float,float,float,float) t2
dcl_input_ps linear v0.xy
dcl_input_ps_siv linear noperspective v1.xy, position
dcl_output o0.xyzw
dcl_temps 3
mad r0.xy, v1.xyxx, cb1[20].zwzz, -cb1[20].xyxx
sample_indexable(texture2d)(float,float,float,float) r1.z, v0.xyxx, t1.xyzw, s0
mul r1.xy, r0.xyxx, r1.zzzz
mov r1.w, l(1.000000)
dp4 r0.x, cb0[0].xyzw, r1.xyzw
dp4 r0.y, cb0[1].xyzw, r1.xyzw
dp4 r0.z, cb0[2].xyzw, r1.xyzw
dp4 r0.w, cb0[3].xyzw, r1.xyzw
div r0.xyz, r0.xyzx, r0.wwww
add r2.xyzw, r0.xyxy, l(-0.000292968762, -0.000292968762, 0.000292968762, -0.000292968762)
sample_c_lz_indexable(texture2d)(float,float,float,float) r0.w, r2.xyxx, t0.xxxx, s2, r0.z
sample_c_lz_indexable(texture2d)(float,float,float,float) r2.x, r2.zwzz, t0.xxxx, s2, r0.z
add r0.w, r0.w, r2.x
add r2.xyzw, r0.xyxy, l(-0.000292968762, 0.000292968762, 0.000292968762, 0.000292968762)
sample_c_lz_indexable(texture2d)(float,float,float,float) r0.x, r2.xyxx, t0.xxxx, s2, r0.z
sample_c_lz_indexable(texture2d)(float,float,float,float) r0.y, r2.zwzz, t0.xxxx, s2, r0.z
add r0.x, r0.w, r0.x
add r0.x, r0.y, r0.x
mul r0.y, r0.x, l(0.250000)
mul o0.w, r0.x, l(0.125000)
dp4 r2.x, cb0[4].xyzw, r1.xyzw
dp4 r2.y, cb0[5].xyzw, r1.xyzw
mul r0.xz, r2.xxyx, l(0.500000, 0.000000, 0.500000, 0.000000)
frc r0.xz, r0.xxzx
sample_l_indexable(texture2d)(float,float,float,float) r0.xzw, r0.xzxx, t2.xwyz, s1, l(0.000000)
add r0.xzw, r0.xxwz, l(-0.500000, 0.000000, -0.500000, -0.500000)
add r0.xzw, r0.xxzw, r0.xxzw
dp3 r1.x, cb1[0].xyzx, r0.xzwx
dp3 r1.y, cb1[1].xyzx, r0.xzwx
dp3 r1.z, cb1[2].xyzx, r0.xzwx
mul o0.xyz, r0.yyyy, r1.xyzx
ret 
// Approximately 32 instruction slots used

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