// Markers Decals
Texture2D<float4> t1 : register(t1);

Texture2D<float4> t0 : register(t0);

SamplerState s1_s : register(s1);

SamplerState s0_s : register(s0);

cbuffer cb4 : register(b4)
{
  float4 cb4[1];
}

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

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

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

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

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
}


// 3Dmigoto declarations
#define cmp -
Texture1D<float4> IniParams : register(t120);
Texture2D<float4> StereoParams : register(t125);
#include <matrix.hlsl>

void main(
  float4 v0 : SV_POSITION0,
  float4 v1 : TEXCOORD0,
  float4 v2 : TEXCOORD1,
  float4 v3 : TEXCOORD2,
  float4 v4 : TEXCOORD3,
  out float4 o0 : SV_Target0,
  float fov : TEXCOORD4)
{
  float4 r0,r1,r2;
  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-lighting-ps --only-autofixed --fxc /home/dss/fxc.exe 0d229bee69d6470f-ps_replace.txt
matrix _CameraToWorld = matrix(cb2[18], cb2[19], cb2[20], cb2[21]);
float4 _WorldSpaceCameraPos = cb1[4];
if (fov) {
  _WorldSpaceCameraPos.xyz -= mul(float4(-separation * convergence * fov, 0, 0, 0), _CameraToWorld).xyz;
} else {
  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.xy = cb4[0].zw + cb4[0].zw;
  r0.zw = v2.xy / v2.ww;
  r0.xy = r0.zw * r0.xy + -cb4[0].zw;
  r1.xyzw = t0.Sample(s0_s, r0.zw).xyzw;
  r2.xyzw = t1.Sample(s1_s, r0.zw).xyzw;
  r1.yzw = r2.xyz * float3(2,2,2) + float3(-1,-1,-1);
  r0.z = cb1[7].x * r1.x + cb1[7].y;
  r0.z = 1 / r0.z;
  r2.xy = r0.zz * r0.xy;
  r2.z = -cb1[5].z * r0.z;
  r0.xyz = float3(1,1,-1) * r2.xyz;
  
  float depth = r0.z;

// Unity light/shadow fix (pixel shader stage) inserted with DarkStarSword's hlsltool.py:
// hlsltool.py -I ../.. --fix-unity-lighting-ps --only-autofixed --fxc /home/dss/fxc.exe 0d229bee69d6470f-ps_replace.txt
if (fov) {
  r0.x -= separation * (depth - convergence) * fov;
}
  
  
  r2.xyz = cb2[19].xyz * r0.yyy;
  r0.xyw = cb2[18].xyz * r0.xxx + r2.xyz;
  r0.xyz = cb2[20].xyz * r0.zzz + r0.xyw;
  r0.xyz = cb2[21].xyz + r0.xyz;
  
  // Fallback adjustment if the FOV was not passed from the VS:
if (!fov) {
  float4 clip_space_adj = float4(separation * (depth - 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);
  r0.xyz -= world_space_adj.xyz;
}
  
  r2.xyz = cb3[17].xyz * r0.yyy;
  r0.xyw = cb3[16].xyz * r0.xxx + r2.xyz;
  r0.xyz = cb3[18].xyz * r0.zzz + r0.xyw;
  r0.xyz = cb3[19].xyz + r0.xyz;
  r0.xyz = float3(0.5,0.5,0.5) + -abs(r0.xyz);
  r0.xyz = cmp(r0.xyz < float3(0,0,0));
  r0.x = (int)r0.y | (int)r0.x;
  r0.x = (int)r0.z | (int)r0.x;
  if (r0.x != 0) discard;
  r0.x = dot(r1.yzw, r1.yzw);
  r0.x = rsqrt(r0.x);
  r0.xyz = r1.yzw * r0.xxx;
  r0.x = dot(r0.xyz, v3.xyz);
  r0.x = -cb0[18].y + r0.x;
  r0.x = cmp(r0.x < 0);
  
  if (r0.x != 0) discard;
  o0.xyzw = float4(0,0,0,0);
  
  
  
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) D3D Shader Disassembler
//
//   using 3Dmigoto v1.3.12 on Thu Dec 06 15:26:52 2018
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float
// TEXCOORD                 0   xyzw        1     NONE   float
// TEXCOORD                 1   xyzw        2     NONE   float   xy w
// TEXCOORD                 2   xyz         3     NONE   float   xyz
// TEXCOORD                 3   xyzw        4     NONE   float
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_4_0
dcl_constantbuffer cb0[19], immediateIndexed
dcl_constantbuffer cb1[8], immediateIndexed
dcl_constantbuffer cb2[22], immediateIndexed
dcl_constantbuffer cb3[20], immediateIndexed
dcl_constantbuffer cb4[1], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_input_ps linear v2.xyw
dcl_input_ps linear v3.xyz
dcl_output o0.xyzw
dcl_temps 3
add r0.xy, cb4[0].zwzz, cb4[0].zwzz
div r0.zw, v2.xxxy, v2.wwww
mad r0.xy, r0.zwzz, r0.xyxx, -cb4[0].zwzz
sample r1.xyzw, r0.zwzz, t0.xyzw, s0
sample r2.xyzw, r0.zwzz, t1.xyzw, s1
mad r1.yzw, r2.xxyz, l(0.000000, 2.000000, 2.000000, 2.000000), l(0.000000, -1.000000, -1.000000, -1.000000)
mad r0.z, cb1[7].x, r1.x, cb1[7].y
div r0.z, l(1.000000, 1.000000, 1.000000, 1.000000), r0.z
mul r2.xy, r0.xyxx, r0.zzzz
mul r2.z, r0.z, -cb1[5].z
mul r0.xyz, r2.xyzx, l(1.000000, 1.000000, -1.000000, 0.000000)
mul r2.xyz, r0.yyyy, cb2[19].xyzx
mad r0.xyw, cb2[18].xyxz, r0.xxxx, r2.xyxz
mad r0.xyz, cb2[20].xyzx, r0.zzzz, r0.xywx
add r0.xyz, r0.xyzx, cb2[21].xyzx
mul r2.xyz, r0.yyyy, cb3[17].xyzx
mad r0.xyw, cb3[16].xyxz, r0.xxxx, r2.xyxz
mad r0.xyz, cb3[18].xyzx, r0.zzzz, r0.xywx
add r0.xyz, r0.xyzx, cb3[19].xyzx
add r0.xyz, -|r0.xyzx|, l(0.500000, 0.500000, 0.500000, 0.000000)
lt r0.xyz, r0.xyzx, l(0.000000, 0.000000, 0.000000, 0.000000)
or r0.x, r0.y, r0.x
or r0.x, r0.z, r0.x
discard_nz r0.x
dp3 r0.x, r1.yzwy, r1.yzwy
rsq r0.x, r0.x
mul r0.xyz, r0.xxxx, r1.yzwy
dp3 r0.x, r0.xyzx, v3.xyzx
add r0.x, r0.x, -cb0[18].y
lt r0.x, r0.x, l(0.000000)
discard_nz r0.x
mov o0.xyzw, l(0,0,0,0)
ret
// Approximately 0 instruction slots used

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
