// hlsltool.py -I ../.. --fix-unity-reflection --only-autofixed --fxc /home/rshan/fxc.exe dc6bfb5f354a4649-ps_replace.txt
// 3DMigoto: dc6bfb5f354a4649 |    Unity headers extracted from Alloy Deferred Shading.shader
//    Shader "Hidden/Alloy/Deferred Shading" {
//      Properties {
//       _LightTexture0 ("", any) = "" { }
//       _LightTextureB0 ("", 2D) = "" { }
//       _ShadowMapTexture ("", any) = "" { }
//       _SrcBlend ("", Float) = 1
//       _DstBlend ("", Float) = 1
//      }
//      Fallback Off
//      SubShader 1/1 {
//        Pass 1/2 {
//          Tags { "SHADOWSUPPORT"="true" }
//          ZWrite Off
//          Blend [_SrcBlend] [_DstBlend]
//          GpuProgramID 2174
//          Program "fp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 99
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from Alloy Deferred Shading.shader.decompressed:
//   API d3d11
//   Shader model ps_4_0
//   undeciphered1: 132 4 0
//   Keywords { "SPOT" "SHADOWS_DEPTH" "SHADOWS_SOFT" "SHADOWS_NATIVE" "UNITY_HDR_ON" }
//   undeciphered2: 1 6 4 6 0
//   undeciphered3: 0 0
//   ConstBuffer "$Globals" 336
//   Vector 160 [_LightPos]
//   Vector 176 [_LightColor]
//   Vector 272 [_ShadowOffsets0]
//   Vector 288 [_ShadowOffsets1]
//   Vector 304 [_ShadowOffsets2]
//   Vector 320 [_ShadowOffsets3]
//   Matrix 208 [_LightMatrix0]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 64 [_WorldSpaceCameraPos] 3
//   Vector 80 [_ProjectionParams]
//   Vector 112 [_ZBufferParams]
//   ConstBuffer "UnityShadows" 416
//   Vector 384 [_LightShadowData]
//   Vector 400 [unity_ShadowFadeCenterAndType]
//   Matrix 128 [unity_World2Shadow0]
//   Matrix 192 [unity_World2Shadow1]
//   Matrix 256 [unity_World2Shadow2]
//   Matrix 320 [unity_World2Shadow3]
//   ConstBuffer "UnityPerCamera2" 64
//   Matrix 0 [_CameraToWorld]
//   SetTexture 0 [_CameraDepthTexture] 2D 0
//   SetTexture 1 [_CameraGBufferTexture0] 2D 3
//   SetTexture 2 [_CameraGBufferTexture1] 2D 4
//   SetTexture 3 [_CameraGBufferTexture2] 2D 5
//   SetTexture 4 [_LightTexture0] 2D 1
//   SetTexture 5 [_ShadowMapTexture] 2D 2
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityShadows" 2
//   BindCB "UnityPerCamera2" 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 Wed Oct 26 06:14:11 2016
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 s5_s : register(s5);

SamplerState s4_s : register(s4);

SamplerState s3_s : register(s3);

SamplerComparisonState s2_s : register(s2);

SamplerState s1_s : register(s1);

SamplerState s0_s : register(s0);

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

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

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

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




// 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,
  float4 v1 : TEXCOORD0,
  float3 v2 : TEXCOORD1,
  out float4 o0 : SV_Target0,
float fov : TEXCOORD2)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7,r8;
  uint4 bitmask, uiDest;
  float4 fDest;

float4 stereo = StereoParams.Load(0);
float4 params = IniParams.Load(0);
float separation = stereo.x, convergence = stereo.y, eye = stereo.z;



  r0.x = cb1[5].z / v2.z;
  r0.xyz = v2.xyz * r0.xxx;
  r1.xy = v1.xy / v1.ww;
  r2.xyzw = t0.Sample(s0_s, r1.xy).xyzw;
  r0.w = cb1[7].x * r2.x + cb1[7].y;
  r0.w = 1 / r0.w;
  r2.xyz = r0.xyz * r0.www;
r2.x-=separation*(r2.z-convergence)*fov;
  r3.xyz = cb3[1].xyz * r2.yyy;
  r2.xyw = cb3[0].xyz * r2.xxx + r3.xyz;
  r2.xyw = cb3[2].xyz * r2.zzz + r2.xyw;
  r2.xyw = cb3[3].xyz + r2.xyw;
  r3.xyz = cb1[4].xyz + -r2.xyw;
  r0.x = dot(r3.xyz, r3.xyz);
  r0.x = rsqrt(r0.x);
  r3.xyz = r3.xyz * r0.xxx;
  r4.xyzw = t3.Sample(s5_s, r1.xy).xyzw;
  r4.xyz = r4.xyz * float3(2,2,2) + float3(-1,-1,-1);
  r0.x = 1 + -r4.w;
  r0.x = 1 + -r0.x;
  r0.y = dot(r4.xyz, r4.xyz);
  r0.y = rsqrt(r0.y);
  r4.xyz = r4.xyz * r0.yyy;
  r0.y = dot(-r3.xyz, r4.xyz);
  r0.y = r0.y + r0.y;
  r5.xyz = r4.xyz * -r0.yyy + -r3.xyz;
  r6.xyz = cb0[10].xyz + -r2.xyw;
  r0.y = dot(r6.xyz, r5.xyz);
  r5.xyz = r0.yyy * r5.xyz + -r6.xyz;
  r0.y = dot(r5.xyz, r5.xyz);
  r0.y = rsqrt(r0.y);
  r1.z = rsqrt(cb0[10].w);
  r1.w = abs(cb0[11].w) * r1.z;
  r0.y = r1.w * r0.y;
  r0.y = min(1, r0.y);
  r5.xyz = r5.xyz * r0.yyy + r6.xyz;
  r0.y = dot(r5.xyz, r5.xyz);
  r0.y = rsqrt(r0.y);
  r7.xyz = r5.xyz * r0.yyy + r3.xyz;
  r5.xyz = r5.xyz * r0.yyy;
  r0.y = r1.w * r0.y;
  r1.w = saturate(dot(r4.xyz, r3.xyz));
  r3.x = dot(r7.xyz, r7.xyz);
  r3.x = rsqrt(r3.x);
  r3.xyz = r7.xyz * r3.xxx;
  r3.w = saturate(dot(r4.xyz, r3.xyz));
  r3.x = saturate(dot(r5.xyz, r3.xyz));
  r3.y = r3.w * r3.w;
  r5.xyzw = t2.Sample(s4_s, r1.xy).xyzw;
  r7.xyzw = t1.Sample(s3_s, r1.xy).xyzw;
  r8.xyzw = float4(1,1,1,1) + -r5.wxyz;
  r1.x = r8.x * 0.949999988 + 0.0500000007;
  r1.x = r1.x * r1.x;
  r1.y = r1.x * r1.x + -1;
  r1.y = r3.y * r1.y + 1;
  r1.y = r1.y * r1.y;
  r3.y = r1.x * r1.x;
  r1.y = r3.y / r1.y;
  r3.y = r3.x * r3.x;
  r3.z = 0.5 * r1.x;
  r3.w = r3.z * r3.z;
  r3.z = -r3.z * r3.z + 1;
  r3.z = r3.y * r3.z + r3.w;
  r3.y = dot(r3.yy, r8.xx);
  r3.y = -0.5 + r3.y;
  r3.z = 4 * r3.z;
  r1.y = r1.y / r3.z;
  r3.z = r3.x * -5.55472994 + -6.98316002;
  r3.x = r3.z * r3.x;
  r3.x = exp2(r3.x);
  r3.xzw = r3.xxx * r8.yzw + r5.xyz;
  r3.xzw = r3.xzw * r1.yyy;
  r0.y = r0.y * 0.5 + r1.x;
  r0.y = min(1, r0.y);
  r0.y = r1.x / r0.y;
  r0.y = r0.y * r0.y;
  r1.x = cmp(0 < cb0[11].w);
  r1.x = r1.x ? 1.000000 : 0;
  r0.y = r1.x * r0.y;
  r0.y = r7.w * r0.y;
  r3.xzw = r0.yyy * r3.xzw;
  r0.y = dot(r6.xyz, r6.xyz);
  r1.x = rsqrt(r0.y);
  r0.y = 1 + r0.y;
  r5.xyz = r6.xyz * r1.xxx;
  r1.x = r1.z * r1.x;
  r1.x = 1 / r1.x;
  r1.x = r1.x * r1.x;
  r1.x = -r1.x * r1.x + 1;
  r1.x = max(0, r1.x);
  r1.y = saturate(dot(r4.xyz, r5.xyz));
  r1.z = r1.y * -5.55472994 + -6.98316002;
  r1.z = r1.z * r1.y;
  r1.z = exp2(r1.z);
  r1.z = r1.z * r3.y + 1;
  r4.x = r1.w * -5.55472994 + -6.98316002;
  r1.w = r4.x * r1.w;
  r1.w = exp2(r1.w);
  r1.w = r1.w * r3.y + 1;
  r1.xz = r1.xz * r1.xw;
  r4.xyz = r7.xyz * r1.zzz;
  r3.xyz = r4.xyz * r0.xxx + r3.xzw;
  r4.xyz = -cb2[25].xyz + r2.xyw;
  r0.x = dot(r4.xyz, r4.xyz);
  r0.x = sqrt(r0.x);
  r0.x = -r0.z * r0.w + r0.x;
  r0.x = cb2[25].w * r0.x + r2.z;
  r0.x = saturate(r0.x * cb2[24].z + cb2[24].w);
  r4.xyzw = cb2[9].xyzw * r2.yyyy;
  r4.xyzw = cb2[8].xyzw * r2.xxxx + r4.xyzw;
  r4.xyzw = cb2[10].xyzw * r2.wwww + r4.xyzw;
  r4.xyzw = cb2[11].xyzw + r4.xyzw;
  r4.xyz = r4.xyz / r4.www;
  r5.xyz = cb0[17].xyz + r4.xyz;
  r5.x = t5.SampleCmpLevelZero(s2_s, r5.xy, r5.z).x;
  r6.xyz = cb0[18].xyz + r4.xyz;
  r5.y = t5.SampleCmpLevelZero(s2_s, r6.xy, r6.z).x;
  r6.xyz = cb0[19].xyz + r4.xyz;
  r4.xyz = cb0[20].xyz + r4.xyz;
  r5.w = t5.SampleCmpLevelZero(s2_s, r4.xy, r4.z).x;
  r5.z = t5.SampleCmpLevelZero(s2_s, r6.xy, r6.z).x;
  r0.z = 1 + -cb2[24].x;
  r4.xyzw = r5.xyzw * r0.zzzz + cb2[24].xxxx;
  r0.z = dot(r4.xyzw, float4(0.25,0.25,0.25,0.25));
  r0.x = saturate(r0.z + r0.x);
  r0.x = r0.x * r1.y;
  r1.yzw = cb0[14].xyw * r2.yyy;
  r1.yzw = cb0[13].xyw * r2.xxx + r1.yzw;
  r1.yzw = cb0[15].xyw * r2.www + r1.yzw;
  r1.yzw = cb0[16].xyw + r1.yzw;
  r0.z = cmp(r1.w < 0);
  r1.yz = r1.yz / r1.ww;
  r2.xyzw = t4.SampleBias(s1_s, r1.yz, -8).xyzw;
  r0.z = r0.z ? 1.000000 : 0;
  r0.z = r2.w * r0.z;
  r1.yzw = r2.xyz * r0.zzz;
  r1.yzw = cb0[11].xyz * r1.yzw;
  r0.yzw = r1.yzw / r0.yyy;
  r0.yzw = r0.yzw * r1.xxx;
  r0.xyz = r0.yzw * r0.xxx;
  r0.xyz = r0.xyz * r3.xyz;
  o0.xyz = min(float3(100,100,100), r0.xyz);
  o0.w = 0;
  return;
}
