// hlsltool.py -I ../.. --fix-unity-reflection --only-autofixed --fxc /home/Ryan/fxc.exe b1e3287f25e5c939-ps_replace.txt
// 3DMigoto: b1e3287f25e5c939 |    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 1/3 {
//          Name "FORWARD"
//          Tags { "LIGHTMODE"="ForwardBase" "QUEUE"="AlphaTest" "SHADOWSUPPORT"="true" "RenderType"="TransparentCutout" }
//          Cull Off
//          GpuProgramID 13581
//          Program "fp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 51
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from TransparentWind.shader.decompressed:
//   API d3d11
//   Shader model ps_4_0
//   undeciphered1: 105 3 5
//   Keywords { "DIRECTIONAL" "SHADOWS_SCREEN" "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "DYNAMICLIGHTMAP_OFF" }
//   undeciphered2: 1 5 4 5 0
//   undeciphered3: 0 0
//   ConstBuffer "$Globals" 240
//   Vector 48 [unity_ColorSpaceLuminance]
//   Vector 96 [_LightColor0]
//   Vector 112 [_SpecColor]
//   Vector 176 [_DiffuseMap_ST]
//   Vector 192 [_DiffColor]
//   Float 208 [_CutoutRange]
//   Float 212 [_GlossRange]
//   Vector 224 [_NormalMap_ST]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 64 [_WorldSpaceCameraPos] 3
//   ConstBuffer "UnityLighting" 720
//   Vector 0 [_WorldSpaceLightPos0]
//   Vector 608 [unity_SHAr]
//   Vector 624 [unity_SHAg]
//   Vector 640 [unity_SHAb]
//   ConstBuffer "UnityReflectionProbes" 128
//   Vector 0 [unity_SpecCube0_BoxMax]
//   Vector 16 [unity_SpecCube0_BoxMin]
//   Vector 32 [unity_SpecCube0_ProbePosition]
//   Vector 48 [unity_SpecCube0_HDR]
//   Vector 64 [unity_SpecCube1_BoxMax]
//   Vector 80 [unity_SpecCube1_BoxMin]
//   Vector 96 [unity_SpecCube1_ProbePosition]
//   Vector 112 [unity_SpecCube1_HDR]
//   SetTexture 0 [_NormalMap] 2D 4
//   SetTexture 1 [_DiffuseMap] 2D 3
//   SetTexture 2 [_ShadowMapTexture] 2D 2
//   SetTexture 3 [unity_SpecCube0] CUBE 0
//   SetTexture 4 [unity_SpecCube1] CUBE 1
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityLighting" 2
//   BindCB "UnityReflectionProbes" 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:38 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[8];
}

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

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 : 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,
  float4 v8 : TEXCOORD10,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11;
  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 b1e3287f25e5c939-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.x = dot(v4.xyz, v4.xyz);
  r0.x = rsqrt(r0.x);
  r0.xyz = v4.xyz * r0.xxx;
  r1.xyz = _WorldSpaceCameraPos.xyz + -v3.xyz;
  r0.w = dot(r1.xyz, r1.xyz);
  r0.w = rsqrt(r0.w);
  r2.xyz = r1.xyz * r0.www;
  r3.xy = v1.xy * cb0[14].xy + cb0[14].zw;
  r3.xyzw = t0.Sample(s4_s, r3.xy).xyzw;
  r3.xy = r3.wy * float2(2,2) + float2(-1,-1);
  r1.w = dot(r3.xy, r3.xy);
  r1.w = min(1, r1.w);
  r1.w = 1 + -r1.w;
  r1.w = sqrt(r1.w);
  r3.yzw = v6.xyz * r3.yyy;
  r3.xyz = r3.xxx * v5.xyz + r3.yzw;
  r3.xyz = r1.www * r0.xyz + r3.xyz;
  r1.w = dot(r3.xyz, r3.xyz);
  r1.w = rsqrt(r1.w);
  r3.xyz = r3.xyz * r1.www;
  r0.x = dot(r2.xyz, r0.xyz);
  r0.y = cmp(0 < r0.x);
  r0.x = cmp(r0.x < 0);
  r0.x = (int)-r0.y + (int)r0.x;
  r0.x = (int)r0.x;
  r2.xyz = r3.xyz * r0.xxx;
  r0.xy = v1.xy * cb0[11].xy + cb0[11].zw;
  r3.xyzw = t1.Sample(s3_s, r0.xy).xyzw;
  r0.x = cb0[13].x + r3.w;
  r0.x = -0.5 + r0.x;
  r0.x = cmp(r0.x < 0);
  if (r0.x != 0) discard;
  r0.x = dot(cb2[0].xyz, cb2[0].xyz);
  r0.x = rsqrt(r0.x);
  r0.xyz = cb2[0].xyz * r0.xxx;
  r1.xyz = r1.xyz * r0.www + r0.xyz;
  r0.w = dot(r1.xyz, r1.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = r1.xyz * r0.www;
  r4.xy = v7.xy / v7.ww;
  r4.xyzw = t2.Sample(s2_s, r4.xy).xyzw;
  r4.xyz = cb0[6].xyz * r4.xxx;
  r0.w = cb0[13].y * 10 + 1;
  r0.w = exp2(r0.w);
  r1.w = 1 + -cb0[13].y;
  r2.w = 1;
  r5.x = dot(cb2[38].xyzw, r2.xyzw);
  r5.y = dot(cb2[39].xyzw, r2.xyzw);
  r5.z = dot(cb2[40].xyzw, r2.xyzw);
  r5.xyz = v8.xyz + r5.xyz;
  r5.xyz = max(float3(0,0,0), r5.xyz);
  r2.w = cmp(cb0[3].w == 0.000000);
  r6.xyz = log2(r5.xyz);
  r6.xyz = float3(0.416666657,0.416666657,0.416666657) * r6.xyz;
  r6.xyz = exp2(r6.xyz);
  r6.xyz = r6.xyz * float3(1.05499995,1.05499995,1.05499995) + float3(-0.0549999997,-0.0549999997,-0.0549999997);
  r6.xyz = max(float3(0,0,0), r6.xyz);
  r5.xyz = r2.www ? r6.xyz : r5.xyz;
  r2.w = cmp(0 < cb3[2].w);
  if (r2.w != 0) {
    r2.w = dot(r2.xyz, r2.xyz);
    r2.w = rsqrt(r2.w);
    r6.xyz = r2.xyz * r2.www;
    r7.xyz = cb3[0].xyz + -v3.xyz;
    r7.xyz = r7.xyz / r6.xyz;
    r8.xyz = cb3[1].xyz + -v3.xyz;
    r8.xyz = r8.xyz / r6.xyz;
    r9.xyz = cmp(float3(0,0,0) < r6.xyz);
    r7.xyz = r9.xyz ? r7.xyz : r8.xyz;
    r2.w = min(r7.x, r7.y);
    r2.w = min(r2.w, r7.z);
    r7.xyz = -cb3[2].xyz + v3.xyz;
    r6.xyz = r6.xyz * r2.www + r7.xyz;
  } else {
    r6.xyz = r2.xyz;
  }
  r2.w = -r1.w * 0.699999988 + 1.70000005;
  r1.w = r2.w * r1.w;
  r1.w = 6 * r1.w;
  r6.xyzw = t3.SampleLevel(s0_s, r6.xyz, r1.w).xyzw;
  r2.w = log2(r6.w);
  r2.w = cb3[3].y * r2.w;
  r2.w = exp2(r2.w);
  r2.w = cb3[3].x * r2.w;
  r7.xyz = r2.www * r6.xyz;
  r3.w = cmp(cb3[1].w < 0.999989986);
  if (r3.w != 0) {
    r3.w = cmp(0 < cb3[6].w);
    if (r3.w != 0) {
      r3.w = dot(r2.xyz, r2.xyz);
      r3.w = rsqrt(r3.w);
      r8.xyz = r3.www * r2.xyz;
      r9.xyz = cb3[4].xyz + -v3.xyz;
      r9.xyz = r9.xyz / r8.xyz;
      r10.xyz = cb3[5].xyz + -v3.xyz;
      r10.xyz = r10.xyz / r8.xyz;
      r11.xyz = cmp(float3(0,0,0) < r8.xyz);
      r9.xyz = r11.xyz ? r9.xyz : r10.xyz;
      r3.w = min(r9.x, r9.y);
      r3.w = min(r3.w, r9.z);
      r9.xyz = -cb3[6].xyz + v3.xyz;
      r8.xyz = r8.xyz * r3.www + r9.xyz;
    } else {
      r8.xyz = r2.xyz;
    }
    r8.xyzw = t4.SampleLevel(s1_s, r8.xyz, r1.w).xyzw;
    r1.w = log2(r8.w);
    r1.w = cb3[7].y * r1.w;
    r1.w = exp2(r1.w);
    r1.w = cb3[7].x * r1.w;
    r8.xyz = r1.www * r8.xyz;
    r6.xyz = r2.www * r6.xyz + -r8.xyz;
    r7.xyz = cb3[1].www * r6.xyz + r8.xyz;
  }
  r1.x = dot(r1.xyz, r2.xyz);
  r1.x = max(0, r1.x);
  r1.x = log2(r1.x);
  r0.w = r1.x * r0.w;
  r0.w = exp2(r0.w);
  r1.xyz = cb0[7].xyz * r7.xyz;
  r1.xyz = r0.www * cb0[7].xyz + r1.xyz;
  r0.x = dot(r2.xyz, r0.xyz);
  r0.x = max(0, r0.x);
  r0.yzw = cb0[12].xyz * r3.xyz;
  r2.xyz = r0.xxx * r4.xyz + r5.xyz;
  o0.xyz = r2.xyz * r0.yzw + r1.xyz;
  o0.w = 1;
  return;
}
