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

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_linear_s : register(s0);
SamplerComparisonState smp_smap_s : register(s1);
Texture2D<float4> s_smap : register(t0);
Texture2DMS<float4,2> 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 = (int2)v1.xy;
  r0.zw = float2(0,0);
  r0.z = s_position.Load(r0.xy, 0).z;
  r1.xy = v1.xy * pos_decompression_params.zw + -pos_decompression_params.xy;
  r0.xy = r1.xy * r0.zz;
float4 stereo = StereoParams.Load(0);
float4 params = IniParams.Load(0);
r0.x -= stereo.x * (r0.z - stereo.y)/m_P._m00;
  r0.w = 1;
  r1.x = dot(m_shadow._m00_m01_m02_m03, r0.xyzw);
  r1.y = dot(m_shadow._m10_m11_m12_m13, r0.xyzw);
  r1.z = dot(m_shadow._m20_m21_m22_m23, r0.xyzw);
  r1.w = dot(m_shadow._m30_m31_m32_m33, r0.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.y = 0.25 * r1.x;
  o0.w = 0.125 * r1.x;
  r2.x = dot(m_sunmask._m00_m01_m02_m03, r0.xyzw);
  r2.y = dot(m_sunmask._m10_m11_m12_m13, r0.xyzw);
  r0.xy = float2(0.5,0.5) * r2.xy;
  r0.xy = frac(r0.xy);
  r0.xyz = s_water.SampleLevel(smp_linear_s, r0.xy, 0).xyz;
  r0.xyz = float3(-0.5,-0.5,-0.5) + r0.xzy;
  r0.xyz = r0.xyz + r0.xyz;
  r2.x = dot(m_V._m00_m01_m02, r0.xyz);
  r2.y = dot(m_V._m10_m11_m12, r0.xyz);
  r2.z = dot(m_V._m20_m21_m22, r0.xyz);
  o0.xyz = r2.xyz * r1.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_linear                        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_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       
// 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_comparison
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2dms(2) (float,float,float,float) t1
dcl_resource_texture2d (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.z, r0.xyzw, t1.xyzw, l(0)
mad r1.xy, v1.xyxx, cb1[20].zwzz, -cb1[20].xyxx
mul r0.xy, r0.zzzz, r1.xyxx
mov r0.w, l(1.000000)
dp4 r1.x, cb0[0].xyzw, r0.xyzw
dp4 r1.y, cb0[1].xyzw, r0.xyzw
dp4 r1.z, cb0[2].xyzw, r0.xyzw
dp4 r1.w, cb0[3].xyzw, r0.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.y, r1.x, l(0.250000)
mul o0.w, r1.x, l(0.125000)
dp4 r2.x, cb0[4].xyzw, r0.xyzw
dp4 r2.y, cb0[5].xyzw, r0.xyzw
mul r0.xy, r2.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000)
frc r0.xy, r0.xyxx
sample_l_indexable(texture2d)(float,float,float,float) r0.xyz, r0.xyxx, t2.xyzw, s0, l(0.000000)
add r0.xyz, r0.xzyx, l(-0.500000, -0.500000, -0.500000, 0.000000)
add r0.xyz, r0.xyzx, r0.xyzx
dp3 r2.x, cb1[0].xyzx, r0.xyzx
dp3 r2.y, cb1[1].xyzx, r0.xyzx
dp3 r2.z, cb1[2].xyzx, r0.xyzx
mul o0.xyz, r1.yyyy, r2.xyzx
ret 
// Approximately 36 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 _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_linear_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_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       
// 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_comparison
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2dms(2) (float,float,float,float) t1
dcl_resource_texture2d (float,float,float,float) t2
dcl_input_ps_siv linear noperspective v1.xy, position
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.z, r0.xyzw, t1.xyzw, l(0)
mad r1.xy, v1.xyxx, cb1[20].zwzz, -cb1[20].xyxx
mul r0.xy, r0.zzzz, r1.xyxx
mov r0.w, l(1.000000)
dp4 r1.x, cb0[0].xyzw, r0.xyzw
dp4 r1.y, cb0[1].xyzw, r0.xyzw
dp4 r1.z, cb0[2].xyzw, r0.xyzw
dp4 r1.w, cb0[3].xyzw, r0.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.y, r1.x, l(0.250000)
mul o0.w, r1.x, l(0.125000)
dp4 r2.x, cb0[4].xyzw, r0.xyzw
dp4 r2.y, cb0[5].xyzw, r0.xyzw
mul r0.xy, r2.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000)
frc r0.xy, r0.xyxx
sample_l_indexable(texture2d)(float,float,float,float) r0.xyz, r0.xyxx, t2.xyzw, s0, l(0.000000)
add r0.xyz, r0.xzyx, l(-0.500000, -0.500000, -0.500000, 0.000000)
add r0.xyz, r0.xyzx, r0.xyzx
dp3 r2.x, cb1[0].xyzx, r0.xyzx
dp3 r2.y, cb1[1].xyzx, r0.xyzx
dp3 r2.z, cb1[2].xyzx, r0.xyzx
mul o0.xyz, r1.yyyy, r2.xyzx
ret 
// Approximately 35 instruction slots used

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