// hlsltool.py -I ../.. --fix-unity-reflection --only-autofixed --fxc /home/Ryan/fxc.exe 3887df69ab661e67-ps_replace.txt
// 3DMigoto: 3887df69ab661e67 |    Unity headers extracted from SpecGrayscaleSkinedDIllumRandPulsSF.shader
//    Shader "Shader Forge/Spec/SpecGrayscaleDIllumRandPushSF" {
//      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
//       _PushMap1 ("PushMap1", 2D) = "white" { }
//       _PushMap2 ("PushMap2", 2D) = "black" { }
//       _PushFactor ("PushFactor", Float) = 0.1
//       _TimeFactor ("TimeFactor", Float) = 4
//       _FresnelRange ("FresnelRange", Range(1,3)) = 3
//       _FresnelColor ("FresnelColor", Color) = (1,1,1,1)
//       _NoiseSpeed ("NoiseSpeed", Float) = 1
//       _NMrotationSpeed ("NMrotationSpeed", Float) = 0.1
//      }
//      Fallback "Diffuse"
//      SubShader 1/1 {
//        Tags { "RenderType"="Opaque" }
//        Pass 2/3 {
//          Name "FORWARD_DELTA"
//          Tags { "LIGHTMODE"="ForwardAdd" "SHADOWSUPPORT"="true" "RenderType"="Opaque" }
//          Blend One One
//          GpuProgramID 106725
//          Program "fp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 231
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from SpecGrayscaleSkinedDIllumRandPulsSF.shader.decompressed:
//   API d3d11
//   Shader model ps_4_0
//   undeciphered1: 68 4 0
//   Keywords { "DIRECTIONAL" "SHADOWS_OFF" "LIGHTMAP_OFF" "DIRLIGHTMAP_OFF" "DYNAMICLIGHTMAP_OFF" }
//   undeciphered2: 1 4 3 4 0
//   undeciphered3: 0 0
//   ConstBuffer "$Globals" 512
//   Vector 96 [_LightColor0]
//   Vector 128 [_TimeEditor]
//   Float 144 [_GlossLow]
//   Vector 160 [_Diffuse_ST]
//   Vector 176 [_LowSpecColor]
//   Vector 192 [_NormalMap_ST]
//   Vector 224 [_Shining_ST]
//   Vector 240 [_DiffColor]
//   Vector 256 [_HighSpecColor]
//   Float 272 [_GlossHigh]
//   Float 320 [_HighSpecMultiplayerN]
//   Vector 336 [_Translucent]
//   Float 352 [_TranslucentIntens]
//   Vector 368 [_TranslucentText_ST]
//   Float 384 [_SpecMetallic]
//   Float 388 [_TranslucentRange]
//   Float 500 [_NMrotationSpeed]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 0 [_Time]
//   Vector 64 [_WorldSpaceCameraPos] 3
//   ConstBuffer "UnityLighting" 720
//   Vector 0 [_WorldSpaceLightPos0]
//   SetTexture 0 [_NormalMap] 2D 1
//   SetTexture 1 [_Shining] 2D 2
//   SetTexture 2 [_Diffuse] 2D 0
//   SetTexture 3 [_TranslucentText] 2D 3
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityLighting" 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 Thu Aug 18 03:40:05 2016
Texture2D<float4> t3 : register(t3);

Texture2D<float4> t2 : register(t2);

Texture2D<float4> t1 : register(t1);

Texture2D<float4> t0 : register(t0);

SamplerState s3_s : register(s3);

SamplerState s2_s : register(s2);

SamplerState s1_s : register(s1);

SamplerState s0_s : register(s0);

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

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

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




// 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,
  float3 v6 : TEXCOORD6,
  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 3887df69ab661e67-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 = cb1[0].y + cb0[8].y;
  r0.x = cb0[31].y * r0.x;
  sincos(r0.x, r0.x, r1.x);
  r2.z = r0.x;
  r2.y = r1.x;
  r2.x = -r0.x;
  r0.xy = float2(-0.5,-0.5) + v1.xy;
  r1.x = dot(r0.xy, r2.yz);
  r1.y = dot(r0.xy, r2.xy);
  r0.xy = float2(0.5,0.5) + r1.xy;
  r0.xy = r0.xy * cb0[12].xy + cb0[12].zw;
  r0.xyzw = t0.Sample(s1_s, r0.xy).xyzw;
  r0.xy = r0.wy * float2(2,2) + float2(-1,-1);
  r1.xyz = v6.xyz * r0.yyy;
  r1.xyz = r0.xxx * v5.xyz + r1.xyz;
  r0.x = dot(r0.xy, r0.xy);
  r0.x = min(1, r0.x);
  r0.x = 1 + -r0.x;
  r0.x = sqrt(r0.x);
  r0.y = dot(v4.xyz, v4.xyz);
  r0.y = rsqrt(r0.y);
  r0.yzw = v4.xyz * r0.yyy;
  r0.xyz = r0.xxx * r0.yzw + r1.xyz;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r0.xyz = r0.xyz * r0.www;
  r1.xyz = cb2[0].www * -v3.xyz + cb2[0].xyz;
  r0.w = dot(r1.xyz, r1.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = r1.xyz * r0.www;
  r0.w = dot(r0.xyz, r1.xyz);
  r1.w = log2(r0.w);
  r2.x = 1.44269502 * cb0[24].y;
  r2.x = exp2(r2.x);
  r1.w = r2.x * r1.w;
  r1.w = exp2(r1.w);
  r1.w = 1 + -r1.w;
  r2.xy = v1.xy * cb0[23].xy + cb0[23].zw;
  r2.xyzw = t3.Sample(s3_s, r2.xy).xyzw;
  r2.xyz = cb0[21].xyz * r2.xyz;
  r2.xyz = cb0[22].xxx * r2.xyz;
  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 = cb0[6].xyz * r2.xyz;
  r3.xyz = _WorldSpaceCameraPos.xyz + -v3.xyz;
  r0.w = dot(r3.xyz, r3.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = r3.xyz * r0.www + r1.xyz;
  r0.w = dot(r1.xyz, r1.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = r1.xyz * r0.www;
  r0.x = dot(r1.xyz, r0.xyz);
  r0.x = max(0, r0.x);
  r0.x = log2(r0.x);
  r0.yz = v1.xy * cb0[14].xy + cb0[14].zw;
  r1.xyzw = t1.Sample(s2_s, r0.yz).xyzw;
  r0.y = r1.x * cb0[17].x + cb0[9].x;
  r1.xyz = cb0[16].xyz * r1.xyz;
  r1.xyz = r1.xyz * cb0[20].xxx + cb0[11].xyz;
  r0.y = r0.y * 10 + 1;
  r0.y = exp2(r0.y);
  r0.x = r0.y * r0.x;
  r0.x = exp2(r0.x);
  r0.xyz = cb0[6].xyz * r0.xxx;
  r3.xy = v1.xy * cb0[10].xy + cb0[10].zw;
  r3.xyzw = t2.Sample(s0_s, r3.xy).xyzw;
  r4.xyz = r3.xyz * cb0[15].xyz + float3(-0.5,-0.5,-0.5);
  r3.xyz = cb0[15].xyz * r3.xyz;
  r4.xyz = cb0[24].xxx * r4.xyz + float3(0.5,0.5,0.5);
  r1.xyz = r4.xyz * r1.xyz;
  r0.xyz = r1.xyz * r0.xyz;
  o0.xyz = r2.xyz * r3.xyz + r0.xyz;
  o0.w = 0;
  return;
}
