// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 23815a7b13b02b4e-vs_replace.txt
// 3DMigoto: 23815a7b13b02b4e | Matched 16 variants of 4 shaders: PlayWay Water/Variations/Water _ALPHABLEND_ON _CUBEMAP_REFLECTIONS _INCLUDE_SLOPE_VARIANCE _NORMALMAP _PLANAR_REFLECTIONS _VOLUMETRIC_LIGHTING _WATER_FOAM_WS _WATER_REFRACTION _WAVES_FFT, PlayWay Water/Variations/Water _ALPHABLEND_ON _CUBEMAP_REFLECTIONS _INCLUDE_SLOPE_VARIANCE _NORMALMAP _PLANAR_REFLECTIONS _VOLUMETRIC_LIGHTING _WATER_REFRACTION _WAVES_FFT, PlayWay Water/Variations/Water _ALPHABLEND_ON _CUBEMAP_REFLECTIONS _INCLUDE_SLOPE_VARIANCE _NORMALMAP _PLANAR_REFLECTIONS_HQ _VOLUMETRIC_LIGHTING _WATER_FOAM_WS _WATER_REFRACTION _WAVES_FFT, PlayWay Water/Variations/Water _ALPHABLEND_ON _CUBEMAP_REFLECTIONS _INCLUDE_SLOPE_VARIANCE _NORMALMAP _PLANAR_REFLECTIONS_HQ _VOLUMETRIC_LIGHTING _WATER_REFRACTION _WAVES_FFT
//
// 000f:    Unity headers extracted from PlayWay Water Variation #-16807626.shader
// 00f0:    Unity headers extracted from PlayWay Water Variation #-1747073184.shader
// 0f00:    Unity headers extracted from PlayWay Water Variation #1252587827.shader
// f000:    Unity headers extracted from PlayWay Water Variation #2084531273.shader
// 00f0:    Shader "PlayWay Water/Variations/Water _ALPHABLEND_ON _CUBEMAP_REFLECTIONS _INCLUDE_SLOPE_VARIANCE _NORMALMAP _PLANAR_REFLECTIONS _VOLUMETRIC_LIGHTING _WATER_FOAM_WS _WATER_REFRACTION _WAVES_FFT" {
// f000:    Shader "PlayWay Water/Variations/Water _ALPHABLEND_ON _CUBEMAP_REFLECTIONS _INCLUDE_SLOPE_VARIANCE _NORMALMAP _PLANAR_REFLECTIONS _VOLUMETRIC_LIGHTING _WATER_REFRACTION _WAVES_FFT" {
// 000f:    Shader "PlayWay Water/Variations/Water _ALPHABLEND_ON _CUBEMAP_REFLECTIONS _INCLUDE_SLOPE_VARIANCE _NORMALMAP _PLANAR_REFLECTIONS_HQ _VOLUMETRIC_LIGHTING _WATER_FOAM_WS _WATER_REFRACTION _WAVES_FFT" {
// 0f00:    Shader "PlayWay Water/Variations/Water _ALPHABLEND_ON _CUBEMAP_REFLECTIONS _INCLUDE_SLOPE_VARIANCE _NORMALMAP _PLANAR_REFLECTIONS_HQ _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
//             _RefractionMaxDepth ("Refraction Max Depth", Float) = -1
//             _WaterTileSize ("Heightmap Tile Size", Vector) = (180,18,600,1800)
//             _WaterTileOffsets ("Tile Offsets", Vector) = (0,0,0,0)
//             _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,1)
//             _WaterId ("", Vector) = (128,256,0,0)
//             _WaterStencilId ("", Float) = 0
//             _WaterStencilIdInv ("", Float) = 0
//             _GerstnerOrigin ("", Vector) = (0,0,0,0)
//             _GrAmp0 ("", Vector) = (0,0,0,0)
//             _GrOff0 ("", Vector) = (0,0,0,0)
//             _GrFrq0 ("", Vector) = (0,0,0,0)
//             _GrAB0 ("", Vector) = (0,0,0,0)
//             _GrCD0 ("", Vector) = (0,0,0,0)
//             _GrAmp1 ("", Vector) = (0,0,0,0)
//             _GrOff1 ("", Vector) = (0,0,0,0)
//             _GrFrq1 ("", Vector) = (0,0,0,0)
//             _GrAB1 ("", Vector) = (0,0,0,0)
//             _GrCD1 ("", Vector) = (0,0,0,0)
//             _GrAmp2 ("", Vector) = (0,0,0,0)
//             _GrOff2 ("", Vector) = (0,0,0,0)
//             _GrFrq2 ("", Vector) = (0,0,0,0)
//             _GrAB2 ("", Vector) = (0,0,0,0)
//             _GrCD2 ("", Vector) = (0,0,0,0)
//             _GrAmp3 ("", Vector) = (0,0,0,0)
//             _GrOff3 ("", Vector) = (0,0,0,0)
//             _GrFrq3 ("", Vector) = (0,0,0,0)
//             _GrAB3 ("", Vector) = (0,0,0,0)
//             _GrCD3 ("", Vector) = (0,0,0,0)
//             _GrAmp4 ("", Vector) = (0,0,0,0)
//             _GrOff4 ("", Vector) = (0,0,0,0)
//             _GrFrq4 ("", Vector) = (0,0,0,0)
//             _GrAB4 ("", Vector) = (0,0,0,0)
//             _GrCD4 ("", Vector) = (0,0,0,0)
//            [HideInInspector]  _Cull ("_Cull", Float) = 2
//            [HideInInspector]  _Mode ("__mode", Float) = 0
//            [HideInInspector]  _SrcBlend ("__src", Float) = 1
//            [HideInInspector]  _DstBlend ("__dst", Float) = 0
//            }
//            SubShader 2/3 {
//              LOD 300
//              Tags { "QUEUE"="Transparent-1" "RenderType"="Opaque" "PerformanceChecks"="False" "CustomType"="Water" }
//              GrabPass {
//                "_RefractionTex"
//               }
//              Pass 2/4 {
//                Name "FORWARD_DELTA"
//                Tags { "LIGHTMODE"="ForwardAdd" "QUEUE"="Transparent-1" "RenderType"="Opaque" "PerformanceChecks"="False" "CustomType"="Water" }
//                ZWrite Off
//                Cull [_Cull]
//                Blend [_SrcBlend] One
// 000f:          GpuProgramID 356849
// f000:          GpuProgramID 375056
// 0f00:          GpuProgramID 375115
// 00f0:          GpuProgramID 391789
//                Program "vp" {
//                  SubProgram "d3d11 " {
// 1111:              GpuProgramIndex 75
// 2222:              GpuProgramIndex 81
// 4444:              GpuProgramIndex 85
// 8888:              GpuProgramIndex 91
//                  }
//                }
//              }
//            }
//          }
//
// 000f: Unity 5.3 headers extracted from PlayWay Water Variation #-16807626.shader.decompressed:
// 00f0: Unity 5.3 headers extracted from PlayWay Water Variation #-1747073184.shader.decompressed:
// 0f00: Unity 5.3 headers extracted from PlayWay Water Variation #1252587827.shader.decompressed:
// f000: Unity 5.3 headers extracted from PlayWay Water Variation #2084531273.shader.decompressed:
//         API d3d11
//         Shader model vs_4_0
//         undeciphered1: 201509030 37 0 0
// 4444:   Keywords { "POINT" "_WAVES_FFT" "_WATER_BACK" }
// 1111:   Keywords { "POINT" "_WAVES_FFT" "_WATER_FRONT" }
// 8888:   Keywords { "POINT_COOKIE" "_WAVES_FFT" "_WATER_BACK" }
// 2222:   Keywords { "POINT_COOKIE" "_WAVES_FFT" "_WATER_FRONT" }
//         undeciphered2: 1 4 5 4 0
//         undeciphered3: 1 1 0 0
//         ConstBuffer "$Globals" 1360
//         Float 160 [_DetailFadeFactor]
//         Vector 176 [_WaterTileSize]
//         Vector 224 [_SurfaceOffset]
//         Vector 1216 [_DetailAlbedoMap_ST]
//         Vector 1232 [_BumpMap_ST]
//         Matrix 1296 [_LightMatrix0]
//         ConstBuffer "UnityPerCamera" 144
//         Vector 64 [_WorldSpaceCameraPos] 3
//         Vector 80 [_ProjectionParams]
//         ConstBuffer "UnityLighting" 720
//         Vector 0 [_WorldSpaceLightPos0]
//         ConstBuffer "UnityPerDraw" 352
//         Matrix 192 [_Object2World]
//         ConstBuffer "UnityPerFrame" 256
//         Matrix 144 [unity_MatrixVP]
//         SetTexture 0 [_GlobalDisplacementMap] 2D 0
//         SetTexture 1 [_GlobalDisplacementMap1] 2D 1
//         SetTexture 2 [_GlobalDisplacementMap2] 2D 2
//         SetTexture 3 [_GlobalDisplacementMap3] 2D 3
//         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:30 2017
Texture2D<float4> t3 : register(t3);

Texture2D<float4> t2 : register(t2);

Texture2D<float4> t1 : register(t1);

Texture2D<float4> t0 : register(t0);

SamplerState s3_s : register(s3);

SamplerState s2_s : register(s2);

SamplerState s1_s : register(s1);

SamplerState s0_s : register(s0);

cbuffer cb4 : register(b4)
{
  float4 cb4[13];
}

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

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

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

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




// 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 : TEXCOORD5,
  out float4 o6 : TEXCOORD6,
  out float4 o7 : TEXCOORD7,
  out float4 o8 : TEXCOORD8)
{
  float4 r0,r1,r2,r3,r4,r5,r6;
  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 23815a7b13b02b4e-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.xyz = cb0[11].xyz * cb0[10].xxx;
  r1.xyzw = cb3[13].xyzw * v0.yyyy;
  r1.xyzw = cb3[12].xyzw * v0.xxxx + r1.xyzw;
  r1.xyzw = cb3[14].xyzw * v0.zzzz + r1.xyzw;
  r1.xyzw = cb3[15].xyzw * v0.wwww + r1.xyzw;
  r2.xyz = _WorldSpaceCameraPos.xyz + -r1.xyz;
  r0.w = dot(r2.xyz, r2.xyz);
  r0.w = sqrt(r0.w);
  r2.xyz = -cb0[11].xyz + r0.www;
  r0.xyz = saturate(r2.xyz / r0.xyz);
  r0.xyz = float3(1,1,1) + -r0.xyz;
  r2.xyz = float3(1,1,1) / r0.xyz;
  r2.xyz = float3(-1,-1,-1) + r2.xyz;
  r3.xyzw = cb0[14].xzxz + r1.xzxz;
  r4.xyzw = r3.zwzw / cb0[11].xxyy;
  r3.xyzw = r3.xyzw / cb0[11].zzww;
  r5.xyzw = t1.SampleLevel(s1_s, r4.zw, r2.y).xyzw;
  r5.xyz = r5.xyz * r0.yyy;
  r6.xyzw = t0.SampleLevel(s0_s, r4.xy, r2.x).xyzw;
  r2.xyzw = t2.SampleLevel(s2_s, r3.xy, r2.z).xyzw;
  r3.xyzw = t3.SampleLevel(s3_s, r3.zw, 0).xyzw;
  r0.xyw = r6.xyz * r0.xxx + r5.xyz;
  r0.xyz = r2.xyz * r0.zzz + r0.xyw;
  r0.xyz = r0.xyz + r3.xyz;
  r0.xyz = r0.xyz * cb0[14].www + r1.xyz;
  r2.xyzw = cb4[10].xyzw * r0.yyyy;
  r2.xyzw = cb4[9].xyzw * r0.xxxx + r2.xyzw;
  r2.xyzw = cb4[11].xyzw * r0.zzzz + r2.xyzw;
  r2.xyzw = cb4[12].xyzw * r1.wwww + r2.xyzw;
  o0.xyzw = r2.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 23815a7b13b02b4e-vs_replace.txt
if (r2.w != 1.0) { r2.x += separation * (r2.w - convergence); }

  o1.xy = r1.xz * cb0[77].xy + cb0[77].zw;
  o1.zw = r1.xz * cb0[76].xy + cb0[76].zw;
  o2.xyz = -_WorldSpaceCameraPos.xyz + r0.xyz;
  o2.w = 0;
  o3.xyz = -r0.xyz * cb2[0].www + cb2[0].xyz;
  o3.w = 0;
  r1.xyz = cb0[82].xyz * r0.yyy;
  r1.xyz = cb0[81].xyz * r0.xxx + r1.xyz;
  r1.xyz = cb0[83].xyz * r0.zzz + r1.xyz;
  o5.yzw = r0.xyz;
  o4.xyz = cb0[84].xyz * r1.www + r1.xyz;
  o5.x = 0;
  o6.zw = r4.zw;
  o8.xy = r4.xy;
  o6.xy = float2(0,0);
  r0.x = cb1[5].x * r2.y;
  r0.w = 0.5 * r0.x;
  r0.xz = float2(0.5,0.5) * r2.xw;
  o7.zw = r2.zw;
  o7.xy = r0.xw + r0.zz;
  o8.zw = float2(0,0);
  return;
}
