// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 295d088a804d96ce-vs_replace.txt
// 3DMigoto: 295d088a804d96ce | Matched 2 variants of 2 shaders: PlayWay Water/Standard Volume, PlayWay Water/Variations/Water Volume _ALPHABLEND_ON _CUBEMAP_REFLECTIONS _VOLUMETRIC_LIGHTING _WATER_REFRACTION _WAVES_FFT
//
// 1:    Unity headers extracted from PlayWay Water - Volume.shader
// 2:    Unity headers extracted from PlayWay Water Volume Variation #-1229508536.shader
// 1:    Shader "PlayWay Water/Standard Volume" {
// 2:    Shader "PlayWay Water/Variations/Water Volume _ALPHABLEND_ON _CUBEMAP_REFLECTIONS _VOLUMETRIC_LIGHTING _WATER_REFRACTION _WAVES_FFT" {
//         Properties {
//          _Color ("Color", Color) = (1,1,1,1)
//          _MainTex ("Albedo", 2D) = "white" { }
//          _DepthColor ("Depth Color", Color) = (0,0.012,0.05,1)
//          _Cutoff ("Alpha Cutoff", Range(0,1)) = 0.5
//          _Glossiness ("Smoothness", Range(0,1)) = 0.5
//          _SpecColor ("Specular", Color) = (0.2,0.2,0.2,1)
//          _BumpScale ("Bump Scale", Vector) = (1,1,0,0)
//          _BumpMap ("Normal Map", 2D) = "bump" { }
//          _DisplacementNormalsIntensity ("Displacement Normals Intensity", Float) = 1.4
//          _GlobalNormalMap ("", 2D) = "black" { }
//          _GlobalNormalMap1 ("", 2D) = "black" { }
//          _GlobalNormalMap2 ("", 2D) = "black" { }
//          _GlobalNormalMap3 ("", 2D) = "black" { }
//          _GlobalDisplacementMap ("", 2D) = "black" { }
//          _GlobalDisplacementMap1 ("", 2D) = "black" { }
//          _GlobalDisplacementMap2 ("", 2D) = "black" { }
//          _GlobalDisplacementMap3 ("", 2D) = "black" { }
//          _DisplacementsScale ("Horizontal Displacement Scale", Float) = 1
//          _OcclusionStrength ("Strength", Range(0,1)) = 1
//          _OcclusionMap ("Occlusion", 2D) = "white" { }
//          _EmissionColor ("Color", Color) = (0,0,0,1)
//          _EmissionMap ("Emission", 2D) = "white" { }
//          _SubtractiveMask ("", 2D) = "black" { }
//          _AdditiveMask ("", 2D) = "black" { }
//          _DetailAlbedoMap ("Detail Albedo x2", 2D) = "grey" { }
//          _DetailNormalMapScale ("Scale", Float) = 1
//          _DetailNormalMap ("Normal Map", 2D) = "bump" { }
//          _DetailFadeFactor ("", Float) = 2
//          _PlanarReflectionTex ("Planar Reflection", 2D) = "black" { }
//          _PlanarReflectionPack ("Planar reflection (distortion, intensity, offset Y, unused)", Vector) = (1,0.45,-0.3,0)
//          _LightSmoothnessMul ("Light Smoothness Multiplier", Float) = 1
//          _WrapSubsurfaceScatteringPack ("Wrap SSS", Vector) = (0.2,0.833333,0.5,0.66666)
//          _SpecularFresnelBias ("Specular Fresnel Bias", Float) = 0.02041
//          _RefractionDistortion ("Refraction Distortion", Float) = 0.55
//          _WaterTileSize ("Heightmap Tile Size", Vector) = (180,18,600,1800)
//          _WaterTileSizeScales ("", Vector) = (0.63241,0.113151,3.16513,10.2651)
//          _Foam ("Foam (intensity, cutoff)", Vector) = (0.1,0.375,0,0)
//          _FoamTex ("Foam texture ", 2D) = "black" { }
//          _FoamNormalMap ("Foam Normal Map", 2D) = "bump" { }
//          _FoamNormalScale ("Foam Normal Scale", Float) = 2.2
//          _FoamTiling ("Foam Tiling", Vector) = (5.4,5.4,1,1)
//          _FoamSpecularColor ("Foam Specular Color", Color) = (1,1,1,1)
//          _EdgeBlendFactorInv ("Edge Blend Factor", Float) = 0.3333
//          _FoamMapWS ("", 2D) = "black" { }
//          _AbsorptionColor ("", Color) = (0.35,0.04,0.001,1)
//          _ReflectionColor ("", Color) = (1,1,1,1)
//          _LocalDisplacementMap ("", 2D) = "black" { }
//          _LocalSlopeMap ("", 2D) = "black" { }
//          _DisplacedHeightMaps ("", 2D) = "black" { }
//          _SubsurfaceScatteringPack ("Subsurface Scattering", Vector) = (1,0.15,1.65,0)
//          _SlopeVariance ("", 3D) = "black" { }
//          _TesselationFactor ("Tesselation Factor", Float) = 14
//          _MaxDisplacement ("", Float) = 10
//          _SurfaceOffset ("", Vector) = (0,0,0,0)
//          _WaterId ("", Vector) = (128,256,0,0)
//          _WaterStencilId ("", Float) = 0
//          _WaterStencilIdInv ("", Float) = 0
//         [HideInInspector]  _Cull ("_Cull", Float) = 2
//         [HideInInspector]  _Mode ("__mode", Float) = 0
//         [HideInInspector]  _SrcBlend ("__src", Float) = 1
//         [HideInInspector]  _DstBlend ("__dst", Float) = 0
//         }
//         SubShader 1/1 {
//           LOD 300
//           Tags { "QUEUE"="Transparent" "RenderType"="Opaque" "PerformanceChecks"="False" "CustomType"="WaterVolume" }
//           GrabPass {
//             "_RefractionTex2"
//            }
//           Pass 1/4 {
//             Name "FORWARD"
//             Tags { "LIGHTMODE"="ForwardBase" "QUEUE"="Transparent" "RenderType"="Opaque" "PerformanceChecks"="False" "CustomType"="WaterVolume" }
//             Cull [_Cull]
//             Blend SrcAlpha OneMinusSrcAlpha
// 1:          GpuProgramID 16274
// 2:          GpuProgramID 20796
//             Program "vp" {
//               SubProgram "d3d11 " {
//                 GpuProgramIndex 3
//               }
//             }
//           }
//         }
//       }
//
// 1: Unity 5.3 headers extracted from PlayWay Water - Volume.shader.decompressed:
// 2: Unity 5.3 headers extracted from PlayWay Water Volume Variation #-1229508536.shader.decompressed:
//      API d3d11
//      Shader model vs_4_0
//      undeciphered1: 201509030 56 0 0
// 2:   Keywords { "DIRECTIONAL" "SHADOWS_OFF" "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "DYNAMICLIGHTMAP_OFF" "VERTEXLIGHT_ON" "_WAVES_FFT" }
// 1:   Keywords { "DIRECTIONAL" "SHADOWS_OFF" "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "DYNAMICLIGHTMAP_OFF" "VERTEXLIGHT_ON" }
//      undeciphered2: 1 0 5 0 0
//      undeciphered3: 3 2 0 0 1 2
//      ConstBuffer "$Globals" 1296
//      Vector 48 [unity_ColorSpaceLuminance]
//      Vector 144 [_LocalMapsCoords]
//      Vector 1216 [_DetailAlbedoMap_ST]
//      Vector 1232 [_BumpMap_ST]
//      ConstBuffer "UnityPerCamera" 144
//      Vector 64 [_WorldSpaceCameraPos] 3
//      Vector 80 [_ProjectionParams]
//      ConstBuffer "UnityLighting" 720
//      Vector 32 [unity_4LightPosX0]
//      Vector 48 [unity_4LightPosY0]
//      Vector 64 [unity_4LightPosZ0]
//      Vector 80 [unity_4LightAtten0]
//      Vector 96 [unity_LightColor0]
//      Vector 112 [unity_LightColor1]
//      Vector 128 [unity_LightColor2]
//      Vector 144 [unity_LightColor3]
//      Vector 160 [unity_LightColor4]
//      Vector 176 [unity_LightColor5]
//      Vector 192 [unity_LightColor6]
//      Vector 208 [unity_LightColor7]
//      Vector 704 [unity_SHC]
//      ConstBuffer "UnityPerDraw" 352
//      Matrix 192 [_Object2World]
//      Matrix 256 [_World2Object]
//      ConstBuffer "UnityPerFrame" 256
//      Matrix 144 [unity_MatrixVP]
//      BindCB "$Globals" 0
//      BindCB "UnityPerCamera" 1
//      BindCB "UnityLighting" 2
//      BindCB "UnityPerDraw" 3
//      BindCB "UnityPerFrame" 4
//
// Headers extracted with DarkStarSword's extract_unity53_shaders.py
// https://raw.githubusercontent.com/DarkStarSword/3d-fixes/master/extract_unity53_shaders.py

// ---- Created with 3Dmigoto v1.2.38 on Thu Feb 09 12:25:47 2017
cbuffer cb4 : register(b4)
{
  float4 cb4[13];
}

cbuffer cb3 : register(b3)
{
  float4 cb3[19];
}

cbuffer cb2 : register(b2)
{
  float4 cb2[45];
}

cbuffer cb1 : register(b1)
{
  float4 cb1[9];
}

cbuffer cb0 : register(b0)
{
  float4 cb0[78];
}




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



cbuffer UnityPerDraw : register(b11) {
	float4x4 glstate_matrix_mvp;
	float4x4 glstate_matrix_modelview0;
	float4x4 glstate_matrix_invtrans_modelview0;
	#define UNITY_MATRIX_MVP glstate_matrix_mvp
	#define UNITY_MATRIX_MV glstate_matrix_modelview0
	#define UNITY_MATRIX_IT_MV glstate_matrix_invtrans_modelview0

	uniform float4x4 _Object2World;
	uniform float4x4 _World2Object;
	uniform float4 unity_LODFade; // x is the fade value ranging within [0,1]. y is x quantized into 16 levels
	uniform float4 unity_WorldTransformParams; // w is usually 1.0, or -1.0 for odd-negative scale transforms
}


#include <matrix.hlsl>

void main( 
  float4 v0 : POSITION0,
  float3 v1 : NORMAL0,
  out float4 o0 : SV_POSITION0,
  out float4 o1 : TEXCOORD0,
  out float4 o2 : TEXCOORD1,
  out float4 o3 : TEXCOORD2,
  out float4 o4 : TEXCOORD3,
  out float4 o5 : TEXCOORD4,
  out float4 o6 : TEXCOORD5,
  out float4 o7 : TEXCOORD6)
{
  float4 r0,r1,r2,r3;
  uint4 bitmask, uiDest;
  float4 fDest;

float4 stereo = StereoParams.Load(0);
float separation = stereo.x, convergence = stereo.y, eye = stereo.z;

// Unity reflection/specular fix inserted with DarkStarSword's hlsltool.py:
// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 295d088a804d96ce-vs_replace.txt
float4 _WorldSpaceCameraPos = cb1[4];
float4 clip_space_adj = float4(-separation * convergence, 0, 0, 0);
float4 local_space_adj = mul(inverse(glstate_matrix_mvp), clip_space_adj);
float4 world_space_adj = mul(_Object2World, local_space_adj);
_WorldSpaceCameraPos.xyz -= world_space_adj.xyz;

  r0.xyzw = cb3[13].xyzw * v0.yyyy;
  r0.xyzw = cb3[12].xyzw * v0.xxxx + r0.xyzw;
  r0.xyzw = cb3[14].xyzw * v0.zzzz + r0.xyzw;
  r0.xyzw = cb3[15].xyzw * v0.wwww + r0.xyzw;
  r1.xyzw = cb4[10].xyzw * r0.yyyy;
  r1.xyzw = cb4[9].xyzw * r0.xxxx + r1.xyzw;
  r1.xyzw = cb4[11].xyzw * r0.zzzz + r1.xyzw;
  r1.xyzw = cb4[12].xyzw * r0.wwww + r1.xyzw;
  o0.xyzw = r1.xyzw;

// Automatic vertex shader halo fix inserted with DarkStarSword's hlsltool.py:
// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 295d088a804d96ce-vs_replace.txt
if (r1.w != 1.0) { r1.x += separation * (r1.w - convergence); }

  r2.xy = float2(0.00999999978,0.00999999978) * r0.xz;
  o1.xy = r2.xy * cb0[77].xy + cb0[77].zw;
  o1.zw = r2.xy * cb0[76].xy + cb0[76].zw;
  o2.w = 0;
  o2.xyz = -_WorldSpaceCameraPos.xyz + r0.xyz;
  o3.xy = float2(0,0);
  r2.xy = cb0[9].xy + r0.xz;
  o3.zw = cb0[9].zz * r2.xy;
  r0.w = cb1[5].x * r1.y;
  r2.w = 0.5 * r0.w;
  r2.xz = float2(0.5,0.5) * r1.xw;
  o4.zw = r1.zw;
  o4.xy = r2.xw + r2.zz;
  r1.xyzw = cb2[2].xyzw + -r0.xxxx;
  r2.xyzw = cb2[3].xyzw + -r0.yyyy;
  r3.xyzw = r2.xyzw * r2.xyzw;
  r1.xyzw = r1.xyzw * r1.xyzw + r3.xyzw;
  r3.xyzw = cb2[4].xyzw + -r0.zzzz;
  o7.yzw = r0.xyz;
  r0.xyzw = r3.xyzw * r3.xyzw + r1.xyzw;
  r1.xyzw = rsqrt(r0.xyzw);
  r0.xyzw = r0.xyzw * cb2[5].xyzw + float4(1,1,1,1);
  r0.xyzw = float4(1,1,1,1) / r0.xyzw;
  r1.xyzw = r2.xyzw * r1.xyzw;
  r1.xyzw = max(float4(0,0,0,0), r1.xyzw);
  r0.xyzw = r1.xyzw * r0.xyzw;
  r1.xyz = cb2[7].xyz * r0.yyy;
  r1.xyz = cb2[6].xyz * r0.xxx + r1.xyz;
  r0.xyz = cb2[8].xyz * r0.zzz + r1.xyz;
  r0.xyz = cb2[9].xyz * r0.www + r0.xyz;
  r1.xyz = max(float3(0,0,0), -cb2[44].xyz);
  r1.xyz = log2(r1.xyz);
  r1.xyz = float3(0.416666657,0.416666657,0.416666657) * r1.xyz;
  r1.xyz = exp2(r1.xyz);
  r1.xyz = r1.xyz * float3(1.05499995,1.05499995,1.05499995) + float3(-0.0549999997,-0.0549999997,-0.0549999997);
  r1.xyz = max(float3(0,0,0), r1.xyz);
  r0.w = cmp(cb0[3].w == 0.000000);
  r1.xyz = r0.www ? r1.xyz : -cb2[44].xyz;
  o5.xyz = r1.xyz + r0.xyz;
  o5.w = 0;
  r0.x = cb3[16].x * v1.x;
  r0.y = cb3[17].x * v1.x;
  r0.z = cb3[18].x * v1.x;
  r1.x = cb3[16].y * v1.y;
  r1.y = cb3[17].y * v1.y;
  r1.z = cb3[18].y * v1.y;
  r0.xyz = r1.xyz + r0.xyz;
  r1.x = cb3[16].z * v1.z;
  r1.y = cb3[17].z * v1.z;
  r1.z = cb3[18].z * v1.z;
  r0.xyz = r1.xyz + r0.xyz;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  o6.xyz = r0.xyz * r0.www;
  o6.w = 0;
  o7.x = 0;
  return;
}
