// hlsltool.py -I ../.. --fix-unity-reflection --only-autofixed --fxc /home/Ryan/fxc.exe 953e6322a2d44355-ps_replace.txt
// 3DMigoto: 953e6322a2d44355 |    Unity headers extracted from TransparentWind.shader
//    Shader "Shader Forge/TransparentWindSF" {
//      Properties {
//       _WindDirection ("WindDirection", Vector) = (1,0,0,0)
//       _LowBorder ("LowBorder", Float) = 0.1
//       _HighBorder ("HighBorder", Float) = 100
//       _Smoothness ("Smoothness", Range(0.2,3)) = 2
//       _DiffuseMap ("DiffuseMap", 2D) = "white" { }
//       _DiffColor ("DiffColor", Color) = (1,1,1,1)
//       _CutoutRange ("CutoutRange", Range(-0.55,0.55)) = 0.282051
//       _SpecColor ("SpecColor", Color) = (0.176471,0.176471,0.176471,1)
//       _GlossRange ("GlossRange", Range(0,1)) = 0.538462
//       _NormalMap ("NormalMap", 2D) = "bump" { }
//      [HideInInspector]  _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
//      }
//      Fallback "Diffuse"
//      SubShader 1/1 {
//        Tags { "QUEUE"="AlphaTest" "RenderType"="TransparentCutout" }
//        Pass 2/3 {
//          Name "FORWARD_DELTA"
//          Tags { "LIGHTMODE"="ForwardAdd" "QUEUE"="AlphaTest" "SHADOWSUPPORT"="true" "RenderType"="TransparentCutout" }
//          Cull Off
//          Blend One One
//          GpuProgramID 105885
//          Program "fp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 247
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from TransparentWind.shader.decompressed:
//   API d3d11
//   Shader model ps_4_0
//   undeciphered1: 59 5 0
//   Keywords { "POINT_COOKIE" "SHADOWS_CUBE" "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "DYNAMICLIGHTMAP_OFF" }
//   undeciphered2: 1 5 4 5 0
//   undeciphered3: 0 0
//   ConstBuffer "$Globals" 304
//   Vector 160 [_LightColor0]
//   Vector 176 [_SpecColor]
//   Vector 240 [_DiffuseMap_ST]
//   Vector 256 [_DiffColor]
//   Float 272 [_CutoutRange]
//   Float 276 [_GlossRange]
//   Vector 288 [_NormalMap_ST]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 64 [_WorldSpaceCameraPos] 3
//   ConstBuffer "UnityLighting" 720
//   Vector 0 [_WorldSpaceLightPos0]
//   Vector 16 [_LightPositionRange]
//   ConstBuffer "UnityShadows" 416
//   Vector 384 [_LightShadowData]
//   SetTexture 0 [_NormalMap] 2D 4
//   SetTexture 1 [_DiffuseMap] 2D 3
//   SetTexture 2 [_LightTextureB0] 2D 2
//   SetTexture 3 [_LightTexture0] CUBE 1
//   SetTexture 4 [_ShadowMapTexture] CUBE 0
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityLighting" 2
//   BindCB "UnityShadows" 3
//
// 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 Thu Aug 18 03:39:39 2016
TextureCube<float4> t4 : register(t4);

TextureCube<float4> t3 : register(t3);

Texture2D<float4> t2 : register(t2);

Texture2D<float4> t1 : register(t1);

Texture2D<float4> t0 : register(t0);

SamplerState s4_s : register(s4);

SamplerState s3_s : register(s3);

SamplerState s2_s : register(s2);

SamplerState s1_s : register(s1);

SamplerState s0_s : register(s0);

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

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

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

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




// 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 : SV_POSITION0,
  float2 v1 : TEXCOORD0,
  float2 w1 : TEXCOORD1,
  float4 v2 : TEXCOORD2,
  float4 v3 : TEXCOORD3,
  float4 v4 : TEXCOORD4,
  float4 v5 : TEXCOORD5,
  float4 v6 : TEXCOORD6,
  float4 v7 : TEXCOORD7,
  float3 v8 : TEXCOORD8,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r4;
  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 ../.. --fix-unity-reflection --only-autofixed --fxc /home/Ryan/fxc.exe 953e6322a2d44355-ps_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 = v1.xy * cb0[15].xy + cb0[15].zw;
  r0.xyzw = t1.Sample(s3_s, r0.xy).xyzw;
  r0.w = cb0[17].x + r0.w;
  r0.xyz = cb0[16].xyz * r0.xyz;
  r0.w = -0.5 + r0.w;
  r0.w = cmp(r0.w < 0);
  if (r0.w != 0) discard;
  r1.xy = v1.xy * cb0[18].xy + cb0[18].zw;
  r1.xyzw = t0.Sample(s4_s, r1.xy).xyzw;
  r1.xy = r1.wy * float2(2,2) + float2(-1,-1);
  r2.xyz = v6.xyz * r1.yyy;
  r2.xyz = r1.xxx * v5.xyz + r2.xyz;
  r0.w = dot(r1.xy, r1.xy);
  r0.w = min(1, r0.w);
  r0.w = 1 + -r0.w;
  r0.w = sqrt(r0.w);
  r1.x = dot(v4.xyz, v4.xyz);
  r1.x = rsqrt(r1.x);
  r1.xyz = v4.xyz * r1.xxx;
  r2.xyz = r0.www * r1.xyz + r2.xyz;
  r0.w = dot(r2.xyz, r2.xyz);
  r0.w = rsqrt(r0.w);
  r2.xyz = r2.xyz * r0.www;
  r3.xyz = _WorldSpaceCameraPos.xyz + -v3.xyz;
  r0.w = dot(r3.xyz, r3.xyz);
  r0.w = rsqrt(r0.w);
  r4.xyz = r3.xyz * r0.www;
  r1.x = dot(r4.xyz, r1.xyz);
  r1.y = cmp(0 < r1.x);
  r1.x = cmp(r1.x < 0);
  r1.x = (int)-r1.y + (int)r1.x;
  r1.x = (int)r1.x;
  r1.xyz = r2.xyz * r1.xxx;
  r2.xyz = cb2[0].www * -v3.xyz + cb2[0].xyz;
  r1.w = dot(r2.xyz, r2.xyz);
  r1.w = rsqrt(r1.w);
  r2.xyz = r2.xyz * r1.www;
  r3.xyz = r3.xyz * r0.www + r2.xyz;
  r0.w = dot(r1.xyz, r2.xyz);
  r0.w = max(0, r0.w);
  r1.w = dot(r3.xyz, r3.xyz);
  r1.w = rsqrt(r1.w);
  r2.xyz = r3.xyz * r1.www;
  r1.x = dot(r2.xyz, r1.xyz);
  r1.x = max(0, r1.x);
  r1.x = log2(r1.x);
  r1.y = cb0[17].y * 10 + 1;
  r1.y = exp2(r1.y);
  r1.x = r1.y * r1.x;
  r1.x = exp2(r1.x);
  r1.y = dot(v8.xyz, v8.xyz);
  r1.y = sqrt(r1.y);
  r1.y = cb2[1].w * r1.y;
  r1.y = 0.970000029 * r1.y;
  r2.xyzw = t4.Sample(s0_s, v8.xyz).xyzw;
  r1.y = cmp(r2.x < r1.y);
  r1.y = r1.y ? cb3[24].x : 1;
  r1.z = dot(v7.xyz, v7.xyz);
  r2.xyzw = t2.Sample(s2_s, r1.zz).xyzw;
  r3.xyzw = t3.Sample(s1_s, v7.xyz).xyzw;
  r1.z = r3.w * r2.x;
  r1.y = r1.z * r1.y;
  r1.yzw = cb0[10].xyz * r1.yyy;
  r2.xyz = r1.yzw * r1.xxx;
  r1.xyz = r1.yzw * r0.www;
  r2.xyz = cb0[11].xyz * r2.xyz;
  o0.xyz = r1.xyz * r0.xyz + r2.xyz;
  o0.w = 0;
  return;
}
