// hlsltool.py -I ../112 --auto-fix-vertex-halo --fix-unity-reflection --only-autofixed --no-validate --ignore-other-errors 1fafc39d28c0a9e4-vs_replace.txt
// 3DMigoto: 1fafc39d28c0a9e4 |    Unity headers extracted from DistanceCloud.shader
//    Shader "uSky/DistanceCloud" {
//      Properties {
//       Attenuation ("Attenuation", Range(0,5)) = 0.6
//       StepSize ("Step size", Range(0.001,0.02)) = 0.004
//       AlphaSaturation ("Alpha saturation", Range(1,10)) = 2
//       SunColorMultiplier ("Sun Color multiplier", Range(0,8)) = 4
//       SkyColorMultiplier ("Sky Color multiplier", Range(0,8)) = 1.5
//       CloudSampler ("Texture (R)", 2D) = "white" { }
//       Exposure ("Exposure", Range(0,1)) = 1
//       Mask ("Opacity mask (G)", Range(0,1)) = 0
//       RotateSpeed ("Rotate speed", Range(-1,1)) = 0
//      }
//      Fallback Off
//      SubShader 1/1 {
//        Tags { "QUEUE"="Geometry+501" "RenderType"="Background" }
//        Pass 1/1 {
//          Name "BASE"
//          Tags { "QUEUE"="Geometry+501" "RenderType"="Background" }
//          ZWrite Off
//          Blend SrcAlpha OneMinusSrcAlpha
//          GpuProgramID 49316
//          Program "vp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 1
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from DistanceCloud.shader.decompressed:
//   API d3d11
//   Shader model vs_4_0
//   undeciphered1: 201509030 29 0 0
//   undeciphered2: 1 0 3 0 0
//   undeciphered3: 139 4 0 0 1 2 3 4 7 8
//   ConstBuffer "$Globals" 240
//   Vector 96 [_SunDir] 3
//   Vector 112 [_MoonDir] 3
//   Vector 128 [_SkyMultiplier] 3
//   Float 140 [RotateSpeed]
//   Float 148 [StepSize]
//   Vector 208 [CloudSampler_ST]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 0 [_Time]
//   Vector 48 [unity_DeltaTime]
//   Vector 64 [_WorldSpaceCameraPos] 3
//   Vector 80 [_ProjectionParams]
//   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:25:21 2017
cbuffer cb2 : register(b2)
{
  float4 cb2[22];
}

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

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




// 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 : TANGENT0,
  float3 v2 : NORMAL0,
  float4 v3 : TEXCOORD0,
  float2 v4 : TEXCOORD1,
  out float4 o0 : SV_POSITION0,
  out float2 o1 : TEXCOORD0,
  out float2 p1 : TEXCOORD1)
{
  float4 r0,r1,r2,r3,r4,r5;
  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 1fafc39d28c0a9e4-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.y = v0.y;
  r0.w = cb0[8].w * cb1[0].y + cb1[3].z;
  r1.xy = float2(0.0174533334,-0.0174533334) * r0.ww;
  sincos(r1.x, r1.x, r2.x);
  sincos(r1.y, r3.x, r4.x);
  r5.x = -r1.x;
  r5.y = r2.x;
  r5.z = r1.x;
  r0.z = dot(r5.zy, v0.xz);
  r0.x = dot(r5.yx, v0.xz);
  r0.xyz = r0.xyz * cb1[5].zzz + _WorldSpaceCameraPos.xyz;
  r1.xyzw = cb2[1].xyww * r0.yyyy;
  r1.xyzw = cb2[0].xyww * r0.xxxx + r1.xyzw;
  r0.xyzw = cb2[2].xyww * r0.zzzz + r1.xyzw;
  o0.xyzw = cb2[3].xyww + r0.xyzw;
  r0.x = dot(v2.xyz, v2.xyz);
  r0.x = rsqrt(r0.x);
  r0.xyz = v2.zxy * r0.xxx;
  r0.w = dot(v1.xyz, v1.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = v1.yzx * r0.www;
  r2.xyz = r1.xyz * r0.xyz;
  r0.xyz = r0.zxy * r1.yzx + -r2.xyz;
  r0.xyz = v1.www * r0.xyz;
  r1.x = -r3.x;
  r1.y = r4.x;
  r1.z = r3.x;
  r0.w = saturate(-0.100000001 + cb0[8].z);
  r2.xyz = cb0[7].xyz + -cb0[6].xyz;
  r2.xyz = r0.www * r2.xyz + cb0[6].xyz;
  r3.x = dot(r1.yx, r2.xz);
  r3.z = dot(r1.zy, r2.xz);
  r3.y = r2.y;
  r0.w = dot(r0.xyz, r3.xyz);
  r0.z = dot(v1.xyz, r3.xyz);
  p1.xy = cb0[9].yy * r0.zw;
  o1.xy = v3.xy * cb0[13].xy + cb0[13].zw;
  return;
}
  