// Reflections on Water

cbuffer _Globals : register(b4)
{
  float2 gm_vTextureSizeInv : packoffset(c0);
  float1 TextureNormal_01_BumpScale : packoffset(c0.z);
  float4 gm_mTextureTransform_01[2] : packoffset(c1);
  float4 Multiply_04_V2 : packoffset(c3);
  float4 Multiply_11_V2 : packoffset(c4);
  float Panner_01_ScrollX : packoffset(c5);
  float Panner_01_ScrollY : packoffset(c5.y);
  float4 gm_mTextureTransform_02[2] : packoffset(c6);
  float1 ConstantVector1D_03_Value : packoffset(c8);
  float1 TextureNormal_02_BumpScale : packoffset(c8.y);
  float4 gm_mTextureTransform_03[2] : packoffset(c9);
  float1 ConstantVector1D_02_Value : packoffset(c11);
  float1 ConstantVector1D_05_Value : packoffset(c11.y);
  float3 ConstantColorRGB_03_Value : packoffset(c12);
  float3 ConstantColorRGB_02_Value : packoffset(c13);
  float1 Lighting_01_SpecularIntensity : packoffset(c13.w);
  float1 Lighting_01_SpecularPower : packoffset(c14);
  float3 ConstantColorRGB_01_Value : packoffset(c14.y);
}

cbuffer _cbSharedPerViewData : register(b1)
{

  struct
  {
    row_major float4x4 mProjection;
    row_major float4x4 mViewToViewport;
    row_major float4x4 mViewToWorld;
    float4 vViewRemap;
    float4 vViewDepthRemap;
    float4 vEyeVectorUL;
    float4 vEyeVectorLR;
    float4 v4ShadowRange;
    float4 vViewSpaceUpVector;
    float4 vGlobalLitFactor;
    float4 vViewportSize;
    float4 vEngineTime;
    float4 vShaderColor0;
    float4 vShaderColor1;
    float4 vShaderColor2;
    float4 vShaderColor3;
    float4 vShaderColor4;
    float4 vClipPlane;
  } cbSharedPerViewData : packoffset(c0);

}

SamplerState samplerReflection2D_s : register(s0);
SamplerState samplerTextureNormal_01_s : register(s1);
SamplerState samplerTexture_04_s : register(s2);
SamplerState samplerTextureNormal_02_s : register(s3);
Texture2D<float4> mapReflection2D : register(t0);
Texture2D<float4> mapTextureNormal_01 : register(t1);
Texture2D<float4> mapTexture_04 : register(t2);
Texture2D<float4> mapTextureNormal_02 : register(t3);


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


void main( 
  float4 v0 : SV_POSITION0,
  float4 v1 : TEXCOORD0,
  float4 v2 : TEXCOORD2,
  float4 v3 : TEXCOORD3,
  float4 v4 : TEXCOORD4,
  float4 v5 : TEXCOORD5,
  float4 v6 : TEXCOORD6,
  float4 v7 : TEXCOORD7,
  out float4 o0 : SV_TARGET0)
{
  float4 r0,r1,r2,r3;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xy = v2.xy;
  r0.z = 1;
  r1.x = dot(gm_mTextureTransform_02[0].xyz, r0.xyz);
  r1.y = dot(gm_mTextureTransform_02[1].xyz, r0.xyz);
  r0.xy = Panner_01_ScrollX * cbSharedPerViewData.vEngineTime.xx + r1.xy;
  r0.xyzw = mapTexture_04.Sample(samplerTexture_04_s, r0.xy).xyzw;
  r0.x = Multiply_11_V2.x * r0.x;
  r0.x = cbSharedPerViewData.vEngineTime.x * Multiply_04_V2.x + r0.x;
  r0.y = 0.5 + r0.x;
  r0.xy = frac(r0.xy);
  r0.zw = v6.xy * float2(2,2) + float2(-1,-1);
  r1.xy = r0.zw * r0.yy;
  r0.yz = r0.xx * r0.zw;
  r0.x = -0.5 + r0.x;
  r0.x = r0.x + r0.x;
  r2.xy = r0.yz * ConstantVector1D_03_Value + v2.xy;
  r1.xy = r1.xy * ConstantVector1D_03_Value + v2.xy;
  r1.z = 1;
  r3.x = dot(gm_mTextureTransform_03[0].xyz, r1.xyz);
  r3.y = dot(gm_mTextureTransform_03[1].xyz, r1.xyz);
  r1.xyzw = mapTextureNormal_02.Sample(samplerTextureNormal_02_s, r3.xy).xyzw;
  r0.yz = float2(-0.5,-0.5) + r1.xy;
  r0.yz = saturate(r0.yz * TextureNormal_02_BumpScale + float2(0.5,0.5));
  r2.z = 1;
  r1.x = dot(gm_mTextureTransform_01[0].xyz, r2.xyz);
  r1.y = dot(gm_mTextureTransform_01[1].xyz, r2.xyz);
  r1.xyzw = mapTextureNormal_01.Sample(samplerTextureNormal_01_s, r1.xy).xyzw;
  r1.xy = float2(-0.5,-0.5) + r1.xy;
  r1.xy = saturate(r1.xy * TextureNormal_01_BumpScale + float2(0.5,0.5));
  r0.yz = -r1.xy + r0.yz;
  r0.xy = abs(r0.xx) * r0.yz + r1.xy;
  r0.xy = float2(-0.5,-0.5) + r0.xy;
  r0.xy = r0.xy + r0.xy;
  r1.xyzw = v5.xyzz * r0.yyyy;
  r1.xyzw = v4.xyzz * r0.xxxx + r1.xyzw;
  r0.x = dot(r0.xy, r0.xy);
  r0.x = min(1, r0.x);
  r0.x = 1 + -r0.x;
  r0.x = sqrt(r0.x);
  r0.xyzw = v3.xyzz * r0.xxxx + r1.xyzw;
  r0.xyzw = v3.xyzw + -r0.xyzw;
  r1.x = ConstantVector1D_02_Value + -ConstantVector1D_05_Value;
  r1.x = v6.w * r1.x + ConstantVector1D_05_Value;
  r0.xyzw = r0.xyzw * r1.xxxx + v1.xyzw;
  
  float4 stereo = StereoParams.Load(0);
  //r0.x += stereo.x * (v1.z / 2 - stereo.y/2) / cbSharedPerViewData.mProjection._m00;
  r0.x -= -stereo.x * (v1.z/2 - stereo.y/2) / cbSharedPerViewData.mProjection._m00 * (stereo.y/2);
  
  r1.xyz = cbSharedPerViewData.mViewToViewport._m10_m11_m13 * r0.yyy;
  r1.xyz = r0.xxx * cbSharedPerViewData.mViewToViewport._m00_m01_m03 + r1.xyz;
  r0.xyz = r0.zzz * cbSharedPerViewData.mViewToViewport._m20_m21_m23 + r1.xyz;
  r0.xyz = r0.www * cbSharedPerViewData.mViewToViewport._m30_m31_m33 + r0.xyz;
  r0.xy = r0.xy / r0.zz;
  r0.z = 1 + -r0.x;
  r0.xyzw = mapReflection2D.Sample(samplerReflection2D_s, r0.zy).xyzw;
  r0.xyz = r0.xyz * r0.xyz;
  r1.xyz = -ConstantColorRGB_02_Value.xyz + ConstantColorRGB_03_Value.xyz;
  r1.xyz = v6.www * r1.xyz + ConstantColorRGB_02_Value.xyz;
  o0.xyz = r1.xyz * r0.xyz;
  o0.w = 1;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.27.952.3022
//
//   using 3Dmigoto v1.2.19 on Mon Dec 21 15:00:59 2015
//
//
// Buffer Definitions: 
//
// cbuffer $Globals
// {
//
//   float2 gm_vTextureSizeInv;         // Offset:    0 Size:     8 [unused]
//   float1 TextureNormal_01_BumpScale; // Offset:    8 Size:     4
//   float4 gm_mTextureTransform_01[2]; // Offset:   16 Size:    32
//   float4 Multiply_04_V2;             // Offset:   48 Size:    16
//   float4 Multiply_11_V2;             // Offset:   64 Size:    16
//   float Panner_01_ScrollX;           // Offset:   80 Size:     4
//   float Panner_01_ScrollY;           // Offset:   84 Size:     4
//   float4 gm_mTextureTransform_02[2]; // Offset:   96 Size:    32
//   float1 ConstantVector1D_03_Value;  // Offset:  128 Size:     4
//   float1 TextureNormal_02_BumpScale; // Offset:  132 Size:     4
//   float4 gm_mTextureTransform_03[2]; // Offset:  144 Size:    32
//   float1 ConstantVector1D_02_Value;  // Offset:  176 Size:     4
//   float1 ConstantVector1D_05_Value;  // Offset:  180 Size:     4
//   float3 ConstantColorRGB_03_Value;  // Offset:  192 Size:    12
//   float3 ConstantColorRGB_02_Value;  // Offset:  208 Size:    12
//   float1 Lighting_01_SpecularIntensity;// Offset:  220 Size:     4 [unused]
//   float1 Lighting_01_SpecularPower;  // Offset:  224 Size:     4 [unused]
//   float3 ConstantColorRGB_01_Value;  // Offset:  228 Size:    12 [unused]
//
// }
//
// cbuffer _cbSharedPerViewData
// {
//
//   struct
//   {
//       
//       row_major float4x4 mProjection;// Offset:    0
//       row_major float4x4 mViewToViewport;// Offset:   64
//       row_major float4x4 mViewToWorld;// Offset:  128
//       float4 vViewRemap;             // Offset:  192
//       float4 vViewDepthRemap;        // Offset:  208
//       float4 vEyeVectorUL;           // Offset:  224
//       float4 vEyeVectorLR;           // Offset:  240
//       float4 v4ShadowRange;          // Offset:  256
//       float4 vViewSpaceUpVector;     // Offset:  272
//       float4 vGlobalLitFactor;       // Offset:  288
//       float4 vViewportSize;          // Offset:  304
//       float4 vEngineTime;            // Offset:  320
//       float4 vShaderColor0;          // Offset:  336
//       float4 vShaderColor1;          // Offset:  352
//       float4 vShaderColor2;          // Offset:  368
//       float4 vShaderColor3;          // Offset:  384
//       float4 vShaderColor4;          // Offset:  400
//       float4 vClipPlane;             // Offset:  416
//
//   } cbSharedPerViewData;             // Offset:    0 Size:   432
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// samplerReflection2D               sampler      NA          NA    0        1
// samplerTextureNormal_01           sampler      NA          NA    1        1
// samplerTexture_04                 sampler      NA          NA    2        1
// samplerTextureNormal_02           sampler      NA          NA    3        1
// mapReflection2D                   texture  float4          2d    0        1
// mapTextureNormal_01               texture  float4          2d    1        1
// mapTexture_04                     texture  float4          2d    2        1
// mapTextureNormal_02               texture  float4          2d    3        1
// _cbSharedPerViewData              cbuffer      NA          NA    1        1
// $Globals                          cbuffer      NA          NA    4        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float       
// TEXCOORD                 0   xyzw        1     NONE   float   xyzw
// TEXCOORD                 2   xyzw        2     NONE   float   xy  
// TEXCOORD                 3   xyzw        3     NONE   float   xyzw
// TEXCOORD                 4   xyzw        4     NONE   float   xyz 
// TEXCOORD                 5   xyzw        5     NONE   float   xyz 
// TEXCOORD                 6   xyzw        6     NONE   float   xyzw
// TEXCOORD                 7   xyzw        7     NONE   float       
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_TARGET                0   xyzw        0   TARGET   float   xyzw
//
ps_4_0
dcl_constantbuffer cb4[14], immediateIndexed
dcl_constantbuffer cb1[21], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_sampler s2, mode_default
dcl_sampler s3, mode_default
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_resource_texture2d (float,float,float,float) t3
dcl_input_ps linear v1.xyzw
dcl_input_ps linear v2.xy
dcl_input_ps linear v3.xyzw
dcl_input_ps linear v4.xyz
dcl_input_ps linear v5.xyz
dcl_input_ps linear v6.xyw
dcl_output o0.xyzw
dcl_temps 4
mov r0.xy, v2.xyxx
mov r0.z, l(1.000000)
dp3 r1.x, cb4[6].xyzx, r0.xyzx
dp3 r1.y, cb4[7].xyzx, r0.xyzx
mad r0.xy, cb4[5].xyxx, cb1[20].xxxx, r1.xyxx
sample r0.xyzw, r0.xyxx, t2.xyzw, s2
mul r0.x, r0.x, cb4[4].x
mad r0.x, cb1[20].x, cb4[3].x, r0.x
add r0.y, r0.x, l(0.500000)
frc r0.xy, r0.xyxx
mad r0.zw, v6.xxxy, l(0.000000, 0.000000, 2.000000, 2.000000), l(0.000000, 0.000000, -1.000000, -1.000000)
mul r1.xy, r0.yyyy, r0.zwzz
mul r0.yz, r0.zzwz, r0.xxxx
add r0.x, r0.x, l(-0.500000)
add r0.x, r0.x, r0.x
mad r2.xy, r0.yzyy, cb4[8].xxxx, v2.xyxx
mad r1.xy, r1.xyxx, cb4[8].xxxx, v2.xyxx
mov r1.z, l(1.000000)
dp3 r3.x, cb4[9].xyzx, r1.xyzx
dp3 r3.y, cb4[10].xyzx, r1.xyzx
sample r1.xyzw, r3.xyxx, t3.xyzw, s3
add r0.yz, r1.xxyx, l(0.000000, -0.500000, -0.500000, 0.000000)
mad_sat r0.yz, r0.yyzy, cb4[8].yyyy, l(0.000000, 0.500000, 0.500000, 0.000000)
mov r2.z, l(1.000000)
dp3 r1.x, cb4[1].xyzx, r2.xyzx
dp3 r1.y, cb4[2].xyzx, r2.xyzx
sample r1.xyzw, r1.xyxx, t1.xyzw, s1
add r1.xy, r1.xyxx, l(-0.500000, -0.500000, 0.000000, 0.000000)
mad_sat r1.xy, r1.xyxx, cb4[0].zzzz, l(0.500000, 0.500000, 0.000000, 0.000000)
add r0.yz, r0.yyzy, -r1.xxyx
mad r0.xy, |r0.xxxx|, r0.yzyy, r1.xyxx
add r0.xy, r0.xyxx, l(-0.500000, -0.500000, 0.000000, 0.000000)
add r0.xy, r0.xyxx, r0.xyxx
mul r1.xyzw, r0.yyyy, v5.xyzz
mad r1.xyzw, v4.xyzz, r0.xxxx, r1.xyzw
dp2 r0.x, r0.xyxx, r0.xyxx
min r0.x, r0.x, l(1.000000)
add r0.x, -r0.x, l(1.000000)
sqrt r0.x, r0.x
mad r0.xyzw, v3.xyzz, r0.xxxx, r1.xyzw
add r0.xyzw, -r0.xyzw, v3.xyzw
add r1.x, -cb4[11].y, cb4[11].x
mad r1.x, v6.w, r1.x, cb4[11].y
mad r0.xyzw, r0.xyzw, r1.xxxx, v1.xyzw
mul r1.xyz, r0.yyyy, cb1[5].xywx
mad r1.xyz, r0.xxxx, cb1[4].xywx, r1.xyzx
mad r0.xyz, r0.zzzz, cb1[6].xywx, r1.xyzx
mad r0.xyz, r0.wwww, cb1[7].xywx, r0.xyzx
div r0.xy, r0.xyxx, r0.zzzz
add r0.z, -r0.x, l(1.000000)
sample r0.xyzw, r0.zyzz, t0.xyzw, s0
mul r0.xyz, r0.xyzx, r0.xyzx
add r1.xyz, cb4[12].xyzx, -cb4[13].xyzx
mad r1.xyz, v6.wwww, r1.xyzx, cb4[13].xyzx
mul o0.xyz, r0.xyzx, r1.xyzx
mov o0.w, l(1.000000)
ret 
// Approximately 57 instruction slots used

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