// hlsltool.py -I ../.. --fix-unity-reflection --only-autofixed --fxc /home/Ryan/fxc.exe 3ff323c8ea68f85a-ps_replace.txt
// 3DMigoto: 3ff323c8ea68f85a |    Unity headers extracted from SpecGrayscaleAdvReflSkinedGGSF.shader
//    Shader "Shader Forge/Spec/SpecGrayscaleAdvReflSkinedGGSF" {
//      Properties {
//       _Diffuse ("Diffuse", 2D) = "white" { }
//       _DiffColor ("DiffColor", Color) = (1,1,1,1)
//       _NormalMap ("NormalMap", 2D) = "bump" { }
//       _Shining ("Shining", 2D) = "black" { }
//       _Cubemap ("Cubemap", CUBE) = "_Skybox" { }
//       _CubeColor ("CubeColor", Color) = (0.5,0.5,0.5,1)
//       _GlossHigh ("GlossHigh", Range(0,1)) = 0.71696
//       _HighSpecColor ("HighSpecColor", Color) = (1,1,1,1)
//       _GlossLow ("GlossLow", Range(0,1)) = 0.166634
//       _LowSpecColor ("LowSpecColor", Color) = (0.0735294,0.0735294,0.0735294,1)
//       _IllumText ("IllumText", 2D) = "white" { }
//       _IllumColor ("IllumColor", Color) = (0,0,0,1)
//       _HighSpecMultiplayerN ("HighSpecMultiplayerN", Range(0,6)) = 1
//       _CubemapBlured ("CubemapBlured", CUBE) = "_Skybox" { }
//       _RoughContrast ("RoughContrast", Float) = 1
//       _MetCubeMultiplayer ("MetCubeMultiplayer", Float) = 4
//       _MetallnessMap ("MetallnessMap", 2D) = "white" { }
//       _MetallnessMultiplayer ("MetallnessMultiplayer", Float) = 0
//       _Translucent ("Translucent", Color) = (1,0,0,1)
//       _TranslucentIntens ("TranslucentIntens", Range(0,60)) = 1.07692
//       _TranslucentText ("TranslucentText", 2D) = "black" { }
//       _TranslucentRange ("TranslucentRange", Range(-5,5)) = 0
//       _IllumIntens ("IllumIntens", Float) = 1
//       _Saturation ("Saturation", Float) = 1
//       _Contrast ("Contrast", Float) = 2
//       _NetGGValue ("NetGGValue", Float) = 0
//      }
//      Fallback "Diffuse"
//      SubShader 1/1 {
//        Tags { "RenderType"="Opaque" }
//        Pass 1/2 {
//          Name "FORWARD"
//          Tags { "LIGHTMODE"="ForwardBase" "SHADOWSUPPORT"="true" "RenderType"="Opaque" }
//          GpuProgramID 8909
//          Program "fp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 55
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from SpecGrayscaleAdvReflSkinedGGSF.shader.decompressed:
//   API d3d11
//   Shader model ps_4_0
//   undeciphered1: 159 8 5
//   Keywords { "DIRECTIONAL" "SHADOWS_SCREEN" "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "DYNAMICLIGHTMAP_OFF" "FOG_LINEAR" }
//   undeciphered2: 1 10 5 10 0
//   undeciphered3: 0 0
//   ConstBuffer "$Globals" 400
//   Vector 48 [unity_ColorSpaceLuminance]
//   Vector 96 [_LightColor0]
//   Float 128 [_GlossLow]
//   Vector 144 [_Diffuse_ST]
//   Vector 160 [_LowSpecColor]
//   Vector 176 [_NormalMap_ST]
//   Vector 192 [_CubeColor]
//   Vector 208 [_Shining_ST]
//   Vector 224 [_DiffColor]
//   Vector 240 [_HighSpecColor]
//   Float 256 [_GlossHigh]
//   Vector 272 [_IllumText_ST]
//   Vector 288 [_IllumColor]
//   Float 304 [_HighSpecMultiplayerN]
//   Float 308 [_RoughContrast]
//   Float 312 [_MetCubeMultiplayer]
//   Vector 320 [_MetallnessMap_ST]
//   Float 336 [_MetallnessMultiplayer]
//   Vector 352 [_Translucent]
//   Float 368 [_TranslucentIntens]
//   Float 372 [_TranslucentRange]
//   Float 376 [_IllumIntens]
//   Float 380 [_Saturation]
//   Float 384 [_Contrast]
//   Float 388 [_NetGGValue]
//   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 "UnityFog" 32
//   Vector 0 [unity_FogColor]
//   Vector 16 [unity_FogParams]
//   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 5
//   SetTexture 1 [_ShadowMapTexture] 2D 2
//   SetTexture 2 [_Shining] 2D 6
//   SetTexture 3 [_Diffuse] 2D 4
//   SetTexture 4 [_MetallnessMap] 2D 9
//   SetTexture 5 [_CubemapBlured] CUBE 8
//   SetTexture 6 [_Cubemap] CUBE 3
//   SetTexture 7 [_IllumText] 2D 7
//   SetTexture 8 [unity_SpecCube0] CUBE 0
//   SetTexture 9 [unity_SpecCube1] CUBE 1
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityLighting" 2
//   BindCB "UnityFog" 3
//   BindCB "UnityReflectionProbes" 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.30 on Thu Aug 18 03:39:03 2016
TextureCube<float4> t9 : register(t9);

TextureCube<float4> t8 : register(t8);

Texture2D<float4> t7 : register(t7);

TextureCube<float4> t6 : register(t6);

TextureCube<float4> t5 : register(t5);

Texture2D<float4> t4 : register(t4);

Texture2D<float4> t3 : register(t3);

Texture2D<float4> t2 : register(t2);

Texture2D<float4> t1 : register(t1);

Texture2D<float4> t0 : register(t0);

SamplerState s9_s : register(s9);

SamplerState s8_s : register(s8);

SamplerState s7_s : register(s7);

SamplerState s6_s : register(s6);

SamplerState s5_s : register(s5);

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 cb4 : register(b4)
{
  float4 cb4[8];
}

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

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

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

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




// 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,
  float2 v2 : TEXCOORD2,
  float w2 : TEXCOORD9,
  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,r12;
  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 3ff323c8ea68f85a-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[11].xy + cb0[11].zw;
  r3.xyzw = t0.Sample(s5_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;
  r0.xyz = r1.www * r0.xyz + r3.xyz;
  r1.w = dot(r0.xyz, r0.xyz);
  r1.w = rsqrt(r1.w);
  r3.xyz = r1.www * r0.xyz;
  r0.x = dot(-r2.xyz, r3.xyz);
  r0.x = r0.x + r0.x;
  r0.xyz = r3.xyz * -r0.xxx + -r2.xyz;
  r1.w = dot(cb2[0].xyz, cb2[0].xyz);
  r1.w = rsqrt(r1.w);
  r2.xyz = cb2[0].xyz * r1.www;
  r1.xyz = r1.xyz * r0.www + r2.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 = t1.Sample(s2_s, r4.xy).xyzw;
  r4.xyz = cb0[6].xyz * r4.xxx;
  r5.xy = v1.xy * cb0[13].xy + cb0[13].zw;
  r5.xyzw = t2.Sample(s6_s, r5.xy).xyzw;
  r0.w = r5.x * cb0[16].x + cb0[8].x;
  r1.w = r0.w * 10 + 1;
  r1.w = exp2(r1.w);
  r0.w = 1 + -r0.w;
  r3.w = 1;
  r6.x = dot(cb2[38].xyzw, r3.xyzw);
  r6.y = dot(cb2[39].xyzw, r3.xyzw);
  r6.z = dot(cb2[40].xyzw, r3.xyzw);
  r6.xyz = v8.xyz + r6.xyz;
  r6.xyz = max(float3(0,0,0), r6.xyz);
  r2.w = cmp(cb0[3].w == 0.000000);
  r7.xyz = log2(r6.xyz);
  r7.xyz = float3(0.416666657,0.416666657,0.416666657) * r7.xyz;
  r7.xyz = exp2(r7.xyz);
  r7.xyz = r7.xyz * float3(1.05499995,1.05499995,1.05499995) + float3(-0.0549999997,-0.0549999997,-0.0549999997);
  r7.xyz = max(float3(0,0,0), r7.xyz);
  r6.xyz = r2.www ? r7.xyz : r6.xyz;
  r2.w = cmp(0 < cb4[2].w);
  if (r2.w != 0) {
    r2.w = dot(r0.xyz, r0.xyz);
    r2.w = rsqrt(r2.w);
    r7.xyz = r2.www * r0.xyz;
    r8.xyz = cb4[0].xyz + -v3.xyz;
    r8.xyz = r8.xyz / r7.xyz;
    r9.xyz = cb4[1].xyz + -v3.xyz;
    r9.xyz = r9.xyz / r7.xyz;
    r10.xyz = cmp(float3(0,0,0) < r7.xyz);
    r8.xyz = r10.xyz ? r8.xyz : r9.xyz;
    r2.w = min(r8.x, r8.y);
    r2.w = min(r2.w, r8.z);
    r8.xyz = -cb4[2].xyz + v3.xyz;
    r7.xyz = r7.xyz * r2.www + r8.xyz;
  } else {
    r7.xyz = r0.xyz;
  }
  r2.w = -r0.w * 0.699999988 + 1.70000005;
  r0.w = r2.w * r0.w;
  r0.w = 6 * r0.w;
  r7.xyzw = t8.SampleLevel(s0_s, r7.xyz, r0.w).xyzw;
  r2.w = log2(r7.w);
  r2.w = cb4[3].y * r2.w;
  r2.w = exp2(r2.w);
  r2.w = cb4[3].x * r2.w;
  r8.xyz = r2.www * r7.xyz;
  r3.w = cmp(cb4[1].w < 0.999989986);
  if (r3.w != 0) {
    r3.w = cmp(0 < cb4[6].w);
    if (r3.w != 0) {
      r3.w = dot(r0.xyz, r0.xyz);
      r3.w = rsqrt(r3.w);
      r9.xyz = r3.www * r0.xyz;
      r10.xyz = cb4[4].xyz + -v3.xyz;
      r10.xyz = r10.xyz / r9.xyz;
      r11.xyz = cb4[5].xyz + -v3.xyz;
      r11.xyz = r11.xyz / r9.xyz;
      r12.xyz = cmp(float3(0,0,0) < r9.xyz);
      r10.xyz = r12.xyz ? r10.xyz : r11.xyz;
      r3.w = min(r10.x, r10.y);
      r3.w = min(r3.w, r10.z);
      r10.xyz = -cb4[6].xyz + v3.xyz;
      r9.xyz = r9.xyz * r3.www + r10.xyz;
    } else {
      r9.xyz = r0.xyz;
    }
    r9.xyzw = t9.SampleLevel(s1_s, r9.xyz, r0.w).xyzw;
    r0.w = log2(r9.w);
    r0.w = cb4[7].y * r0.w;
    r0.w = exp2(r0.w);
    r0.w = cb4[7].x * r0.w;
    r9.xyz = r0.www * r9.xyz;
    r7.xyz = r2.www * r7.xyz + -r9.xyz;
    r8.xyz = cb4[1].www * r7.xyz + r9.xyz;
  }
  r7.xyz = cb0[15].xyz * r5.xyz;
  r7.xyz = r7.xyz * cb0[19].xxx + cb0[10].xyz;
  r9.xy = v1.xy * cb0[9].xy + cb0[9].zw;
  r9.xyzw = t3.Sample(s4_s, r9.xy).xyzw;
  r10.xy = v1.xy * cb0[20].xy + cb0[20].zw;
  r10.xyzw = t4.Sample(s9_s, r10.xy).xyzw;
  r0.w = cb0[21].x * r10.x;
  r10.xyz = r9.xyz * r7.xyz + -r7.xyz;
  r7.xyz = r0.www * r10.xyz + r7.xyz;
  r1.x = dot(r1.xyz, r3.xyz);
  r1.x = max(0, r1.x);
  r1.x = log2(r1.x);
  r1.x = r1.w * r1.x;
  r1.x = exp2(r1.x);
  r1.yzw = r8.xyz * r7.xyz;
  r1.xyz = r1.xxx * r7.xyz + r1.yzw;
  r1.w = dot(r3.xyz, r2.xyz);
  r2.xyz = cb0[23].xxx * cb0[22].xyz;
  r2.w = 1.44269502 * cb0[23].y;
  r2.w = exp2(r2.w);
  r3.x = log2(abs(r1.w));
  r2.w = r3.x * r2.w;
  r2.w = exp2(r2.w);
  r2.w = 1 + -r2.w;
  r3.xyz = r2.xyz * r2.www;
  r3.w = dot(r3.xyz, float3(0.300000012,0.589999974,0.109999999));
  r2.xyz = -r2.xyz * r2.www + r3.www;
  r2.xyz = cb0[23].www * r2.xyz;
  r2.xyz = cb0[24].yyy * r2.xyz + r3.xyz;
  r3.xyz = float3(0.5,0.5,0.5) * r2.xyz;
  r2.xyz = -r2.xyz * float3(0.5,0.5,0.5) + float3(1,1,1);
  r2.xyz = r1.www * r2.xyz + r3.xyz;
  r2.xyz = max(float3(0,0,0), r2.xyz);
  r3.xyz = cb0[14].xyz * r9.xyz;
  r7.xyzw = t5.Sample(s8_s, r0.xyz).xyzw;
  r7.xyz = cb0[12].xyz * r7.xyz;
  r8.xyzw = t6.Sample(s3_s, r0.xyz).xyzw;
  r0.xyz = log2(r5.xyz);
  r0.xyz = cb0[19].yyy * r0.xyz;
  r0.xyz = exp2(r0.xyz);
  r0.xyz = saturate(cb0[19].yyy * r0.xyz);
  r8.xyz = cb0[12].xyz * r8.xyz + -r7.xyz;
  r0.xyz = r0.xyz * r8.xyz + r7.xyz;
  r7.xyz = cb0[19].zzz * r0.xyz;
  r7.xyz = r7.xyz * r3.xyz + -r3.xyz;
  r7.xyz = r0.www * r7.xyz + r3.xyz;
  r1.w = dot(r7.xyz, float3(0.300000012,0.589999974,0.109999999));
  r1.w = r1.w + -r7.x;
  r1.w = cb0[23].w * r1.w + r7.x;
  r1.w = cb0[24].x * r1.w;
  r1.w = log2(r1.w);
  r1.w = cb0[24].x * r1.w;
  r1.w = exp2(r1.w);
  r1.w = min(1, r1.w);
  r8.xyz = r1.www + -r7.xyz;
  r7.xyz = cb0[24].yyy * r8.xyz + r7.xyz;
  r2.xyz = r2.xyz * r4.xyz + r6.xyz;
  r0.xyz = r0.xyz * r5.xyz;
  r4.xy = v1.xy * cb0[17].xy + cb0[17].zw;
  r4.xyzw = t7.Sample(s7_s, r4.xy).xyzw;
  r3.xyz = r0.xyz * r3.xyz;
  r3.xyz = r3.xyz * cb0[19].zzz + -r0.xyz;
  r0.xyz = r0.www * r3.xyz + r0.xyz;
  r3.xyz = cb0[18].xyz * r4.www;
  r3.xyz = r9.xyz * r3.xyz;
  r0.xyz = r3.xyz * cb0[23].zzz + r0.xyz;
  r0.w = dot(r0.xyz, float3(0.300000012,0.589999974,0.109999999));
  r3.xyz = r0.www + -r0.xyz;
  r3.xyz = cb0[23].www * r3.xyz;
  r0.xyz = cb0[24].yyy * r3.xyz + r0.xyz;
  r1.xyz = r2.xyz * r7.xyz + r1.xyz;
  r0.xyz = r1.xyz + r0.xyz;
  r0.w = saturate(w2.x * cb3[1].z + cb3[1].w);
  r0.xyz = -cb3[0].xyz + r0.xyz;
  o0.xyz = r0.www * r0.xyz + cb3[0].xyz;
  o0.w = 1;
  return;
}
