//water fountain, various effects
// ---- Created with 3Dmigoto v1.3.16 on Thu Jul 23 01:48:28 2020

cbuffer constantsVS : register(b1)
{
  float aspectRatio : packoffset(c0);
  float lightMultiplier : packoffset(c0.y);
  float vsType : packoffset(c0.z);
  float __padding : packoffset(c0.w);
}

cbuffer SceneConstants : register(b0)
{
  row_major float4x4 g_matrixV : packoffset(c0);
  row_major float4x4 g_matrixP : packoffset(c4);
  row_major float4x4 g_matrixVP : packoffset(c8);
  float3 g_cameraPosition : packoffset(c12);
  float g_time : packoffset(c12.w);
  float3 g_sunDirection : packoffset(c13);
  float g_parallaxScale : packoffset(c13.w);
  float2 g_shadowDepthScale : packoffset(c14);
  float g_vtScale : packoffset(c14.z);
  float gp_shadowDrawDistance : packoffset(c14.w);
  float4 paddingSC2 : packoffset(c15);
}



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

void main(
  float4 v0 : POSITION0,
  float4 v1 : POSITIONB0,
  float4 v2 : POSITIONC0,
  uint4 v3 : POSITIOND0,
  out float4 o0 : POS1,
  out float4 o1 : POS2,
  out float4 o2 : POS3,
  out float4 o3 : POS4)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7;
  uint4 bitmask, uiDest;
  float4 fDest;

float4 stereo = StereoParams.Load(0);
  r0.x = cmp((int)v3.y != 2);
  if (r0.x != 0) {
    r0.xyzw = g_matrixVP._m10_m11_m12_m13 * v0.yyyy;
    r0.xyzw = v0.xxxx * g_matrixVP._m00_m01_m02_m03 + r0.xyzw;
    r0.xyzw = v0.zzzz * g_matrixVP._m20_m21_m22_m23 + r0.xyzw;
    r0.xyzw = g_matrixVP._m30_m31_m32_m33 + r0.xyzw;

r0.x += stereo.x*(r0.w - stereo.y);

    r0.xyz = r0.xyz / r0.www;
    o0.y = r0.y / aspectRatio;
    r0.y = g_matrixP._m11 * v0.w;
    r0.y = r0.y / r0.w;
    sincos(v1.x, r1.x, r2.x);
    r3.x = -r1.x;
    o1.x = r3.x * r0.y;
    o1.y = r2.x * r0.y;
    r1.yzw = float3(-1,1,1) * g_sunDirection.xyz;
    r0.w = dot(r1.yzw, r1.yzw);
    r0.w = rsqrt(r0.w);
    r4.x = -g_sunDirection.x * r0.w;
    r4.yz = g_sunDirection.yz * r0.ww;
    r3.y = r2.x;
    r2.x = dot(r3.yx, -r4.xy);
    r3.z = r1.x;
    r0.w = dot(r3.zy, -r4.xy);
    r2.y = -r0.w;
    r2.z = -r4.z;
    r1.xyz = v3.xxx ? r2.xyz : float3(0,0,65536);
    o0.xz = r0.xz * float2(1,-1) + float2(0,1);
    o0.w = r0.y;
    o1.z = 0;
    o1.w = r0.y;
  } else {
    r0.xyz = -v1.xyz * float3(0.5,0.5,0.5) + v0.xyz;
    r2.xyz = v1.xyz * float3(0.5,0.5,0.5) + v0.xyz;
    r3.xyzw = g_matrixVP._m10_m11_m12_m13 * r0.yyyy;
    r3.xyzw = r0.xxxx * g_matrixVP._m00_m01_m02_m03 + r3.xyzw;
    r0.xyzw = r0.zzzz * g_matrixVP._m20_m21_m22_m23 + r3.xyzw;
    r0.xyzw = g_matrixVP._m30_m31_m32_m33 + r0.xyzw;

r0.x += stereo.x*(r0.w - stereo.y);

    r3.xyzw = g_matrixVP._m10_m11_m12_m13 * r2.yyyy;
    r3.xyzw = r2.xxxx * g_matrixVP._m00_m01_m02_m03 + r3.xyzw;
    r2.xyzw = r2.zzzz * g_matrixVP._m20_m21_m22_m23 + r3.xyzw;
    r2.xyzw = g_matrixVP._m30_m31_m32_m33 + r2.xyzw;

r2.x += stereo.x*(r2.w - stereo.y);

    r3.xyz = r0.xyz / r0.www;
    r4.xyz = r2.xyz / r2.www;
    r3.w = r3.y / aspectRatio;
    r4.w = r4.y / aspectRatio;
    r0.x = g_matrixP._m11 * v0.w;
    r5.w = r0.x / r0.w;
    r0.w = r0.x / r2.w;
    r2.xyz = -r4.xwz + r3.xwz;
    r2.w = dot(r2.xy, r2.xy);
    r2.w = sqrt(r2.w);
    r2.xyz = r2.xyz / r2.www;
    r3.xyz = r2.xyz * r5.www + r3.xwz;
    r2.xyz = -r2.xyz * r0.www + r4.xwz;
    r2.xyw = r3.xyz + r2.xyz;
    r4.xyz = float3(0.5,0.5,0.5) * r2.xyw;
    r0.xy = -r2.xy * float2(0.5,0.5) + r3.xy;
    r2.xyw = float3(-1,1,1) * g_sunDirection.xyz;
    r2.x = dot(r2.xyw, r2.xyw);
    r2.x = rsqrt(r2.x);
    r6.x = -g_sunDirection.x * r2.x;
    r6.yz = g_sunDirection.yz * r2.xx;
    r2.x = dot(r0.xy, r0.xy);
    r2.x = rsqrt(r2.x);
    r7.xy = r2.xx * r0.xy;
    r7.z = -r7.x;
    r6.x = dot(r7.yz, -r6.xy);
    r2.x = -g_sunDirection.y;
    r2.y = g_sunDirection.x;
    r6.y = dot(r7.yx, r2.xy);
    r6.z = -r6.z;
    r1.xyz = v3.xxx ? r6.xyz : float3(0,0,65536);
    r2.x = cmp(r3.z >= 0.5);
    r2.y = cmp(r2.z >= 0.5);
    r2.x = (int)r2.y | (int)r2.x;
    r5.xyz = r4.xyz * float3(1,1,-1) + float3(0,0,1);
    o0.xyzw = r2.xxxx ? float4(9999,9999,9999,0) : r5.xyzw;
    r0.z = 0;
    o1.xyzw = r2.xxxx ? float4(9.99999975e-006,0,0,0) : r0.xyzw;
  }
  o2.xyzw = v2.xyzw;
  r1.w = v1.w;
  o3.xyzw = r1.xyzw;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.27.952.3022
//
//   using 3Dmigoto v1.3.16 on Thu Jul 23 01:48:28 2020
//
//
// Buffer Definitions:
//
// cbuffer constantsVS
// {
//
//   float aspectRatio;                 // Offset:    0 Size:     4
//   float lightMultiplier;             // Offset:    4 Size:     4 [unused]
//   float vsType;                      // Offset:    8 Size:     4 [unused]
//   float __padding;                   // Offset:   12 Size:     4 [unused]
//
// }
//
// cbuffer SceneConstants
// {
//
//   row_major float4x4 g_matrixV;      // Offset:    0 Size:    64 [unused]
//   row_major float4x4 g_matrixP;      // Offset:   64 Size:    64
//   row_major float4x4 g_matrixVP;     // Offset:  128 Size:    64
//   float3 g_cameraPosition;           // Offset:  192 Size:    12 [unused]
//   float g_time;                      // Offset:  204 Size:     4 [unused]
//   float3 g_sunDirection;             // Offset:  208 Size:    12
//   float g_parallaxScale;             // Offset:  220 Size:     4 [unused]
//   float2 g_shadowDepthScale;         // Offset:  224 Size:     8 [unused]
//   float g_vtScale;                   // Offset:  232 Size:     4 [unused]
//   float gp_shadowDrawDistance;       // Offset:  236 Size:     4 [unused]
//   float4 paddingSC2;                 // Offset:  240 Size:    16 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// SceneConstants                    cbuffer      NA          NA    0        1
// constantsVS                       cbuffer      NA          NA    1        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// POSITION                 0   xyzw        0     NONE   float   xyzw
// POSITIONB                0   xyzw        1     NONE   float   xyzw
// POSITIONC                0   xyzw        2     NONE   float   xyzw
// POSITIOND                0   xyzw        3     NONE    uint   xy
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// POS                      1   xyzw        0     NONE   float   xyzw
// POS                      2   xyzw        1     NONE   float   xyzw
// POS                      3   xyzw        2     NONE   float   xyzw
// POS                      4   xyzw        3     NONE   float   xyzw
//
vs_4_1
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb1[1], immediateIndexed
dcl_constantbuffer cb0[14], immediateIndexed
dcl_input v0.xyzw
dcl_input v1.xyzw
dcl_input v2.xyzw
dcl_input v3.xy
dcl_output o0.xyzw
dcl_output o1.xyzw
dcl_output o2.xyzw
dcl_output o3.xyzw
dcl_temps 8
ine r0.x, v3.y, l(2)
if_nz r0.x
  mul r0.xyzw, v0.yyyy, cb0[9].xyzw
  mad r0.xyzw, v0.xxxx, cb0[8].xyzw, r0.xyzw
  mad r0.xyzw, v0.zzzz, cb0[10].xyzw, r0.xyzw
  add r0.xyzw, r0.xyzw, cb0[11].xyzw
  div r0.xyz, r0.xyzx, r0.wwww
  div o0.y, r0.y, cb1[0].x
  mul r0.y, v0.w, cb0[5].y
  div r0.y, r0.y, r0.w
  sincos r1.x, r2.x, v1.x
  mov r3.x, -r1.x
  mul o1.x, r0.y, r3.x
  mul o1.y, r0.y, r2.x
  mul r1.yzw, cb0[13].xxyz, l(0.000000, -1.000000, 1.000000, 1.000000)
  dp3 r0.w, r1.yzwy, r1.yzwy
  rsq r0.w, r0.w
  mul r4.x, r0.w, -cb0[13].x
  mul r4.yz, r0.wwww, cb0[13].yyzy
  mov r3.y, r2.x
  dp2 r2.x, r3.yxyy, -r4.xyxx
  mov r3.z, r1.x
  dp2 r0.w, r3.zyzz, -r4.xyxx
  mov r2.y, -r0.w
  mov r2.z, -r4.z
  movc r1.xyz, v3.xxxx, r2.xyzx, l(0,0,65536.000000,0)
  mad o0.xz, r0.xxzx, l(1.000000, 0.000000, -1.000000, 0.000000), l(0.000000, 0.000000, 1.000000, 0.000000)
  mov o0.w, r0.y
  mov o1.z, l(0)
  mov o1.w, r0.y
else
  mad r0.xyz, -v1.xyzx, l(0.500000, 0.500000, 0.500000, 0.000000), v0.xyzx
  mad r2.xyz, v1.xyzx, l(0.500000, 0.500000, 0.500000, 0.000000), v0.xyzx
  mul r3.xyzw, r0.yyyy, cb0[9].xyzw
  mad r3.xyzw, r0.xxxx, cb0[8].xyzw, r3.xyzw
  mad r0.xyzw, r0.zzzz, cb0[10].xyzw, r3.xyzw
  add r0.xyzw, r0.xyzw, cb0[11].xyzw
  mul r3.xyzw, r2.yyyy, cb0[9].xyzw
  mad r3.xyzw, r2.xxxx, cb0[8].xyzw, r3.xyzw
  mad r2.xyzw, r2.zzzz, cb0[10].xyzw, r3.xyzw
  add r2.xyzw, r2.xyzw, cb0[11].xyzw
  div r3.xyz, r0.xyzx, r0.wwww
  div r4.xyz, r2.xyzx, r2.wwww
  div r3.w, r3.y, cb1[0].x
  div r4.w, r4.y, cb1[0].x
  mul r0.x, v0.w, cb0[5].y
  div r5.w, r0.x, r0.w
  div r0.w, r0.x, r2.w
  add r2.xyz, r3.xwzx, -r4.xwzx
  dp2 r2.w, r2.xyxx, r2.xyxx
  sqrt r2.w, r2.w
  div r2.xyz, r2.xyzx, r2.wwww
  mad r3.xyz, r2.xyzx, r5.wwww, r3.xwzx
  mad r2.xyz, -r2.xyzx, r0.wwww, r4.xwzx
  add r2.xyw, r2.xyxz, r3.xyxz
  mul r4.xyz, r2.xywx, l(0.500000, 0.500000, 0.500000, 0.000000)
  mad r0.xy, -r2.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000), r3.xyxx
  mul r2.xyw, cb0[13].xyxz, l(-1.000000, 1.000000, 0.000000, 1.000000)
  dp3 r2.x, r2.xywx, r2.xywx
  rsq r2.x, r2.x
  mul r6.x, r2.x, -cb0[13].x
  mul r6.yz, r2.xxxx, cb0[13].yyzy
  dp2 r2.x, r0.xyxx, r0.xyxx
  rsq r2.x, r2.x
  mul r7.xy, r0.xyxx, r2.xxxx
  mov r7.z, -r7.x
  dp2 r6.x, r7.yzyy, -r6.xyxx
  mov r2.x, -cb0[13].y
  mov r2.y, cb0[13].x
  dp2 r6.y, r7.yxyy, r2.xyxx
  mov r6.z, -r6.z
  movc r1.xyz, v3.xxxx, r6.xyzx, l(0,0,65536.000000,0)
  ge r2.x, r3.z, l(0.500000)
  ge r2.y, r2.z, l(0.500000)
  or r2.x, r2.y, r2.x
  mad r5.xyz, r4.xyzx, l(1.000000, 1.000000, -1.000000, 0.000000), l(0.000000, 0.000000, 1.000000, 0.000000)
  movc o0.xyzw, r2.xxxx, l(9999.000000,9999.000000,9999.000000,0), r5.xyzw
  mov r0.z, l(0)
  movc o1.xyzw, r2.xxxx, l(0.000010,0,0,0), r0.xyzw
endif
mov o2.xyzw, v2.xyzw
mov r1.w, v1.w
mov o3.xyzw, r1.xyzw
ret
// Approximately 84 instruction slots used

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