// hlsltool.py -I ../.. --fix-unity-reflection --only-autofixed --fxc /home/Ryan/fxc.exe 9384e2fa85afde66-ps_replace.txt
// 3DMigoto: 9384e2fa85afde66 |    Unity headers extracted from SpecGrayscaleSkinedDIllumSF.shader
//    Shader "Shader Forge/SpecGrayscaleDIllumSF" {
//      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) = (1,1,1,1)
//       _HighSpecMultiplayerN ("HighSpecMultiplayerN", Range(0,6)) = 1
//       _SpecMetallic ("SpecMetallic", Range(0,1)) = 0
//       _Translucent ("Translucent", Color) = (1,0,0,1)
//       _TranslucentIntens ("TranslucentIntens", Range(0,6)) = 1
//       _TranslucentText ("TranslucentText", 2D) = "black" { }
//       _TranslucentRange ("TranslucentRange", Range(-5,5)) = 0
//       _IllumFlowTexture ("IllumFlowTexture", 2D) = "white" { }
//       _IllumFlowPower ("IllumFlowPower", Range(0,3)) = 0.187384
//       _TimeScale ("TimeScale", Float) = 1
//       _IllumShift ("IllumShift", Float) = 0.8
//      }
//      Fallback "Diffuse"
//      SubShader 1/1 {
//        Tags { "RenderType"="Opaque" }
//        Pass 1/2 {
//          Name "FORWARD"
//          Tags { "LIGHTMODE"="ForwardBase" "SHADOWSUPPORT"="true" "RenderType"="Opaque" }
//          GpuProgramID 60326
//          Program "fp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 49
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from SpecGrayscaleSkinedDIllumSF.shader.decompressed:
//   API d3d11
//   Shader model ps_4_0
//   undeciphered1: 129 7 5
//   Keywords { "DIRECTIONAL" "SHADOWS_OFF" "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "DYNAMICLIGHTMAP_OFF" }
//   undeciphered2: 1 9 4 9 0
//   undeciphered3: 0 0
//   ConstBuffer "$Globals" 432
//   Vector 48 [unity_ColorSpaceLuminance]
//   Vector 96 [_LightColor0]
//   Vector 128 [_TimeEditor]
//   Float 144 [_GlossLow]
//   Vector 160 [_Diffuse_ST]
//   Vector 176 [_LowSpecColor]
//   Vector 192 [_NormalMap_ST]
//   Vector 208 [_CubeColor]
//   Vector 224 [_Shining_ST]
//   Vector 240 [_DiffColor]
//   Vector 256 [_HighSpecColor]
//   Float 272 [_GlossHigh]
//   Vector 288 [_IllumText_ST]
//   Vector 304 [_IllumColor]
//   Float 320 [_HighSpecMultiplayerN]
//   Vector 336 [_Translucent]
//   Float 352 [_TranslucentIntens]
//   Vector 368 [_TranslucentText_ST]
//   Float 384 [_SpecMetallic]
//   Float 388 [_TranslucentRange]
//   Vector 400 [_IllumFlowTexture_ST]
//   Float 416 [_IllumFlowPower]
//   Float 420 [_TimeScale]
//   Float 424 [_IllumShift]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 0 [_Time]
//   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 [_Shining] 2D 5
//   SetTexture 2 [_Diffuse] 2D 3
//   SetTexture 3 [_TranslucentText] 2D 7
//   SetTexture 4 [_IllumText] 2D 6
//   SetTexture 5 [_IllumFlowTexture] 2D 8
//   SetTexture 6 [_Cubemap] CUBE 2
//   SetTexture 7 [unity_SpecCube0] CUBE 0
//   SetTexture 8 [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:40:08 2016
TextureCube<float4> t8 : register(t8);

TextureCube<float4> t7 : register(t7);

TextureCube<float4> t6 : register(t6);

Texture2D<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 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 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[27];
}




// 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 : TEXCOORD10,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10;
  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 9384e2fa85afde66-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[12].xy + cb0[12].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;
  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 = v1.xy * cb0[14].xy + cb0[14].zw;
  r4.xyzw = t1.Sample(s5_s, r4.xy).xyzw;
  r0.w = r4.x * cb0[17].x + cb0[9].x;
  r1.w = r0.w * 10 + 1;
  r1.w = exp2(r1.w);
  r0.w = 1 + -r0.w;
  r3.w = 1;
  r5.x = dot(cb2[38].xyzw, r3.xyzw);
  r5.y = dot(cb2[39].xyzw, r3.xyzw);
  r5.z = dot(cb2[40].xyzw, r3.xyzw);
  r5.xyz = v7.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) {
    r6.xyz = cb3[0].xyz + -v3.xyz;
    r6.xyz = r6.xyz / r3.xyz;
    r7.xyz = cb3[1].xyz + -v3.xyz;
    r7.xyz = r7.xyz / r3.xyz;
    r8.xyz = cmp(float3(0,0,0) < r3.xyz);
    r6.xyz = r8.xyz ? r6.xyz : r7.xyz;
    r2.w = min(r6.x, r6.y);
    r2.w = min(r2.w, r6.z);
    r6.xyz = -cb3[2].xyz + v3.xyz;
    r6.xyz = r3.xyz * r2.www + r6.xyz;
  } else {
    r6.xyz = r3.xyz;
  }
  r2.w = -r0.w * 0.699999988 + 1.70000005;
  r0.w = r2.w * r0.w;
  r0.w = 6 * r0.w;
  r6.xyzw = t7.SampleLevel(s0_s, r6.xyz, r0.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) {
      r8.xyz = cb3[4].xyz + -v3.xyz;
      r8.xyz = r8.xyz / r3.xyz;
      r9.xyz = cb3[5].xyz + -v3.xyz;
      r9.xyz = r9.xyz / r3.xyz;
      r10.xyz = cmp(float3(0,0,0) < r3.xyz);
      r8.xyz = r10.xyz ? r8.xyz : r9.xyz;
      r3.w = min(r8.x, r8.y);
      r3.w = min(r3.w, r8.z);
      r8.xyz = -cb3[6].xyz + v3.xyz;
      r8.xyz = r3.xyz * r3.www + r8.xyz;
    } else {
      r8.xyz = r3.xyz;
    }
    r8.xyzw = t8.SampleLevel(s1_s, r8.xyz, r0.w).xyzw;
    r0.w = log2(r8.w);
    r0.w = cb3[7].y * r0.w;
    r0.w = exp2(r0.w);
    r0.w = cb3[7].x * r0.w;
    r8.xyz = r0.www * r8.xyz;
    r6.xyz = r2.www * r6.xyz + -r8.xyz;
    r7.xyz = cb3[1].www * r6.xyz + r8.xyz;
  }
  r6.xy = v1.xy * cb0[10].xy + cb0[10].zw;
  r6.xyzw = t2.Sample(s3_s, r6.xy).xyzw;
  r8.xyz = cb0[15].xyz * r6.xyz;
  r9.xyz = r6.xyz * cb0[15].xyz + float3(-0.5,-0.5,-0.5);
  r9.xyz = cb0[24].xxx * r9.xyz + float3(0.5,0.5,0.5);
  r10.xyz = cb0[16].xyz * r4.xyz;
  r10.xyz = r10.xyz * cb0[20].xxx + cb0[11].xyz;
  r10.xyz = r10.xyz * r9.xyz;
  r0.w = dot(r1.xyz, r3.xyz);
  r0.w = max(0, r0.w);
  r0.w = log2(r0.w);
  r0.w = r1.w * r0.w;
  r0.w = exp2(r0.w);
  r1.xyz = r10.xyz * r7.xyz;
  r1.xyz = r0.www * r10.xyz + r1.xyz;
  r0.w = dot(r3.xyz, r2.xyz);
  r2.xy = v1.xy * cb0[23].xy + cb0[23].zw;
  r2.xyzw = t3.Sample(s7_s, r2.xy).xyzw;
  r2.xyz = cb0[21].xyz * r2.xyz;
  r2.xyz = cb0[22].xxx * r2.xyz;
  r1.w = 1.44269502 * cb0[24].y;
  r1.w = exp2(r1.w);
  r2.w = log2(r0.w);
  r1.w = r2.w * r1.w;
  r1.w = exp2(r1.w);
  r1.w = 1 + -r1.w;
  r2.xyz = r2.xyz * r1.www;
  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 = r0.www * r2.xyz + r3.xyz;
  r2.xyz = max(float3(0,0,0), r2.xyz);
  r2.xyz = r2.xyz * cb0[6].xyz + r5.xyz;
  r3.xy = v1.xy * cb0[18].xy + cb0[18].zw;
  r3.xyzw = t4.Sample(s6_s, r3.xy).xyzw;
  r3.xy = cb1[0].yw + cb0[8].yw;
  r0.w = cb0[26].y * r3.y;
  r3.xy = r3.xx * cb0[26].yy + v1.xy;
  r3.xy = r3.xy * cb0[25].xy + cb0[25].zw;
  r5.xyzw = t5.Sample(s8_s, r3.xy).xyzw;
  r7.xyzw = t6.Sample(s2_s, r0.xyz).xyzw;
  r0.xyz = cb0[13].xyz * r7.xyz;
  r0.xyz = r0.xyz * r4.xyz;
  r3.xyz = cb0[19].xyz * r3.www;
  r3.xyz = r6.xyz * r3.xyz;
  r0.w = sin(r0.w);
  r0.w = cb0[26].z + r0.w;
  r0.w = r0.w / cb0[26].z;
  r4.xyz = r5.xyz * r0.www;
  r4.xyz = cb0[26].xxx * r4.xyz;
  r3.xyz = abs(r4.xyz) * r3.xyz;
  r0.xyz = r0.xyz * r9.xyz + r3.xyz;
  r1.xyz = r2.xyz * r8.xyz + r1.xyz;
  o0.xyz = r1.xyz + r0.xyz;
  o0.w = 1;
  return;
}
