// hlsltool.py -I ../.. --auto-fix-vertex-halo --fix-unity-reflection --fix-unity-frustum-world --only-autofixed --fxc /home/rshan/fxc.exe dedddae12ac5104e-vs_replace.txt
// 3DMigoto: dedddae12ac5104e |    Unity headers extracted from Water.shader
//    Shader "Effects/Water" {
//      Properties {
//       _Color ("Main Color", Color) = (1,1,1,1)
//       _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
//       _RimColor ("Rim Color", Color) = (1,1,1,0.5)
//       _BumpMap ("Normalmap", 2D) = "bump" { }
//       _HeightMap ("_HeightMap (r)", 2D) = "white" { }
//       _Height ("_Height", Float) = 0.2
//       _OffsetXHeightMap ("_OffsetXHeightMap", Range(0,1)) = 0
//       _OffsetYHeightMap ("_OffsetYHeightMap", Range(0,1)) = 0
//       _FPOW ("FPOW Fresnel", Float) = 5
//       _R0 ("R0 Fresnel", Float) = 0.05
//       _Cutoff ("Emission strength", Range(0,1)) = 0.5
//       _BumpAmt ("Distortion", Float) = 10
//      }
//      SubShader 1/1 {
//        Tags { "QUEUE"="Transparent" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" }
//        GrabPass {
//          Name "BASE"
//          Tags { "LIGHTMODE"="Always" }
//         }
//        Pass 1/1 {
//          Tags { "QUEUE"="Transparent" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" }
//          ZWrite Off
//          Blend SrcAlpha OneMinusSrcAlpha
//          Offset -1, -1
//          GpuProgramID 4629
//          Program "vp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 1
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from Water.shader.decompressed:
//   API d3d11
//   Shader model vs_4_0
//   undeciphered1: 35 0 0
//   undeciphered2: 1 1 3 1 0
//   undeciphered3: 143 5 0 0 2 1 1 2 3 4 7 8
//   ConstBuffer "$Globals" 240
//   Float 192 [_Height]
//   Float 196 [_OffsetXHeightMap]
//   Float 200 [_OffsetYHeightMap]
//   Vector 208 [_BumpMap_ST]
//   Vector 224 [_Height_ST]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 64 [_WorldSpaceCameraPos] 3
//   ConstBuffer "UnityPerDraw" 352
//   Matrix 0 [glstate_matrix_mvp]
//   Matrix 256 [_World2Object]
//   SetTexture 0 [_HeightMap] 2D 0
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityPerDraw" 2
//
// 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.30 on Wed Oct 26 06:15:55 2016
Texture2D<float4> t0 : register(t0);

SamplerState s0_s : register(s0);

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

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

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




// 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,
  float4 v1 : TANGENT0,
  float3 v2 : NORMAL0,
  float4 v3 : TEXCOORD0,
  float4 v4 : TEXCOORD1,
  float4 v5 : TEXCOORD2,
  float4 v6 : TEXCOORD3,
  float4 v7 : COLOR0,
  out float4 o0 : SV_Position0,
  out float2 o1 : TEXCOORD1,
  out float2 p1 : TEXCOORD2,
  out float4 o2 : TEXCOORD3,
  out float4 o3 : TEXCOORD4,
  out float3 o4 : TEXCOORD5,
  out float4 o5 : COLOR0,
  out float4 o6 : TEXCOORD6,
  out float3 o7 : TEXCOORD7)
{
  float4 r0,r1;
  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 ../.. --auto-fix-vertex-halo --fix-unity-reflection --fix-unity-frustum-world --only-autofixed --fxc /home/rshan/fxc.exe dedddae12ac5104e-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.xy = cb0[12].yz + v3.xy;
  r0.xyzw = t0.SampleLevel(s0_s, r0.xy, 0).xyzw;
  r0.yzw = cb0[12].xxx * v2.xyz;
  r0.xyz = r0.yzw * r0.xxx + v0.xyz;
  r1.xyzw = cb2[1].xyzw * r0.yyyy;
  r1.xyzw = cb2[0].xyzw * r0.xxxx + r1.xyzw;
  r1.xyzw = cb2[2].xyzw * r0.zzzz + r1.xyzw;
  o0.xyzw = cb2[3].xyzw * v0.wwww + r1.xyzw;
  o1.xy = v3.xy * cb0[13].xy + cb0[13].zw;
  p1.xy = v3.xy * cb0[14].xy + cb0[14].zw;
  r1.xyzw = cb2[1].xyzw * v0.yyyy;
  r1.xyzw = cb2[0].xyzw * v0.xxxx + r1.xyzw;
  r1.xyzw = cb2[2].xyzw * v0.zzzz + r1.xyzw;
  r1.xyzw = cb2[3].xyzw * v0.wwww + r1.xyzw;
  r1.xy = r1.xy * float2(1,-1) + r1.ww;
  o2.zw = r1.zw;
  o2.xy = float2(0.5,0.5) * r1.xy;
  r1.x = dot(v2.xyz, cb2[16].xyz);
  r1.y = dot(v2.xyz, cb2[17].xyz);
  r1.z = dot(v2.xyz, cb2[18].xyz);
  r0.w = dot(r1.xyz, r1.xyz);
  r0.w = rsqrt(r0.w);
  o3.xyz = r1.xyz * r0.www;
  r1.xyz = cb2[17].xyz * _WorldSpaceCameraPos.yyy;
  r1.xyz = cb2[16].xyz * _WorldSpaceCameraPos.xxx + r1.xyz;
  r1.xyz = cb2[18].xyz * _WorldSpaceCameraPos.zzz + r1.xyz;
  r1.xyz = cb2[19].xyz + r1.xyz;
  r0.xyz = r1.xyz + -r0.xyz;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r0.xyz = r0.xyz * r0.www;
  r1.xyz = v2.zxy * v1.yzx;
  r1.xyz = v2.yzx * v1.zxy + -r1.xyz;
  r1.xyz = v1.www * r1.xyz;
  o4.y = dot(r1.xyz, r0.xyz);
  o4.x = dot(v1.xyz, r0.xyz);
  o4.z = dot(v2.xyz, r0.xyz);
  o7.xyz = r0.xyz;
  o5.xyzw = v7.xyzw;
  o6.xyz = v2.xyz;
  return;
}

/****************************** COMPILE WARNINGS ******************************
X:\SteamLibrary\steamapps\common\Killing Room\ShaderFixes\dedddae12ac5104e-vs_replace.txt(124,14-15): warning X3578: Output value 'o3' is not completely initialized
X:\SteamLibrary\steamapps\common\Killing Room\ShaderFixes\dedddae12ac5104e-vs_replace.txt(127,14-15): warning X3578: Output value 'o6' is not completely initialized

****************************** COMPILE WARNINGS ******************************/
