// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors d45e8ba7dbd39e55-vs_replace.txt
// 3DMigoto: d45e8ba7dbd39e55 |    Unity headers extracted from Stars.shader
//    Shader "Hidden/uSky/Stars" {
//      SubShader 1/1 {
//        Tags { "QUEUE"="Geometry+502" "IGNOREPROJECTOR"="true" "RenderType"="Background" }
//        Pass 1/1 {
//          Tags { "QUEUE"="Geometry+502" "IGNOREPROJECTOR"="true" "RenderType"="Background" }
//          ZWrite Off
//          Blend OneMinusDstAlpha OneMinusSrcAlpha
//          GpuProgramID 40843
//          Program "vp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 1
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from Stars.shader.decompressed:
//   API d3d11
//   Shader model vs_4_0
//   undeciphered1: 201509030 28 0 0
//   undeciphered2: 1 0 3 0 0
//   undeciphered3: 13 3 0 0 2 1 3 4
//   ConstBuffer "$Globals" 80
//   Float 0 [StarIntensity]
//   Matrix 16 [rotationMatrix]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 0 [_Time]
//   Vector 48 [unity_DeltaTime]
//   Vector 64 [_WorldSpaceCameraPos] 3
//   ConstBuffer "UnityPerDraw" 352
//   Matrix 0 [glstate_matrix_mvp]
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityPerDraw" 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.38 on Thu Feb 09 12:33:46 2017
cbuffer cb2 : register(b2)
{
  float4 cb2[22];
}

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

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




// 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 : POSITION0,
  float4 v1 : COLOR0,
  float2 v2 : TEXCOORD0,
  out float4 o0 : SV_POSITION0,
  out float4 o1 : COLOR0,
  out float2 o2 : TEXCOORD0)
{
  const float4 icb[] = { { 0.897908, -0.347609, 0, 0},
                              { 0.550299, 0.273587, 0, 0},
                              { 0.823886, 0.098853, 0, 0},
                              { 0.922739, -0.122109, 0, 0},
                              { 0.800630, -0.088957, 0, 0},
                              { 0.711673, 0.158864, 0, 0},
                              { 0.870538, 0.085485, 0, 0},
                              { 0.956022, -0.058115, 0, 0} };
  float4 r0,r1;
  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 ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors d45e8ba7dbd39e55-vs_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.xyz = cb0[2].xyz * v0.yyy;
  r0.xyz = cb0[1].xyz * v0.xxx + r0.xyz;
  r0.xyz = cb0[3].xyz * v0.zzz + r0.xyz;
  r0.xyz = _WorldSpaceCameraPos.yxz + r0.yxz;
  r1.xyzw = cb2[1].xyzw * r0.xxxx;
  r1.xyzw = cb2[0].xyzw * r0.yyyy + r1.xyzw;
  r1.xyzw = cb2[2].xyzw * r0.zzzz + r1.xyzw;
  r0.x = saturate(r0.x);
  o0.xyzw = cb2[3].xyzw + r1.xyzw;
  r0.yz = float2(256,256) * v0.xy;
  r0.yz = frac(r0.yz);
  r0.z = 1 + r0.z;
  r0.w = cb1[0].x * 2 + cb1[3].z;
  r0.y = r0.z * r0.w + r0.y;
  r0.y = frac(r0.y);
  r0.y = 8 * r0.y;
  r0.z = frac(r0.y);
  r0.y = (int)r0.y;
  r0.z = 2.5 * r0.z;
  r0.y = r0.z * icb[r0.y+0].y + icb[r0.y+0].x;
  r0.z = v1.w * -3.94000006 + 6.5;
  r0.z = -1.44000006 + -r0.z;
  r0.z = 0.928771198 * r0.z;
  r0.z = exp2(r0.z);
  r1.w = r0.y * r0.z;
  r1.xyz = v1.xyz * r1.www;
  r1.xyzw = cb0[0].xxxx * r1.xyzw;
  o1.xyzw = r1.xyzw * r0.xxxx;
  r0.xy = float2(-0.5,-0.5) + v2.xy;
  o2.xy = float2(5,5) * r0.xy;
  return;
}
 