// Smoke
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[17];
}


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,
  float3 v3 : TEXCOORD2,
  out float4 o0 : SV_Target0,
  float fov : TEXCOORD3)
  
{
  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 ../.. --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 = v1.xy / v1.ww;
  r0.xy = r0.zw * r0.xy + -cb4[0].zw;
  r1.xyzw = t0.Sample(s0_s, r0.zw).xyzw;
  r0.z = cb1[7].x * r1.x + cb1[7].y;
  r0.z = 1 / r0.z;
  r1.xy = r0.zz * r0.xy;
  r1.z = -cb1[5].z * r0.z;
  r0.xyz = float3(1,1,-1) * r1.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;
}
  
  r1.xyz = cb2[19].xyz * r0.yyy;
  r0.xyw = cb2[18].xyz * r0.xxx + r1.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;
}
  
  r1.xyz = cb3[17].xyz * r0.yyy;
  r1.xyz = cb3[16].xyz * r0.xxx + r1.xyz;
  r1.xyz = cb3[18].xyz * r0.zzz + r1.xyz;
  
  
  
  r1.xyz = cb3[19].xyz + r1.xyz;
  
  r2.xyz = cb3[17].xyz * cb1[4].yyy;
  r2.xyz = cb3[16].xyz * cb1[4].xxx + r2.xyz;
  r2.xyz = cb3[18].xyz * cb1[4].zzz + r2.xyz;
  r2.xyz = cb3[19].xyz + r2.xyz;
    
  
  r1.xyz = -r2.xyz + r1.xyz;
  r0.w = dot(r1.xyz, r1.xyz);
  r1.w = rsqrt(r0.w);
  r0.w = sqrt(r0.w);
  r1.xyz = r1.xyz * r1.www;
  r3.xyz = float3(1,1,1) / r1.xyz;
  r4.xyz = float3(-0.5,-0.5,-0.5) + -r2.xyz;
  r4.xyz = r4.xyz * r3.xyz;
  r5.xyz = float3(0.5,0.5,0.5) + -r2.xyz;
  r3.xyz = r5.xyz * r3.xyz;
  r5.xyz = min(r3.xyz, r4.xyz);
  r3.xyz = max(r3.xyz, r4.xyz);
  r1.w = max(r5.x, r5.y);
  r4.x = max(r1.w, r5.z);
  r1.w = min(r3.x, r3.y);
  r4.y = min(r1.w, r3.z);
  r1.w = r4.y + -r4.x;
  r3.xy = max(float2(0,0), r4.xy);
  r1.w = cmp(r1.w < 0);
  if (r1.w != 0) discard;
  r1.w = -r3.x + r0.w;
  r0.w = cmp(r0.w < r3.y);
  r1.w = cmp(r1.w < 0);
  if (r1.w != 0) discard;
  r3.yzw = r3.yyy * r1.xyz + r2.xyz;
  r1.xyz = r3.xxx * r1.xyz + r2.xyz;
  r2.xyz = cb3[13].xyz * r3.zzz;
  r2.xyz = cb3[12].xyz * r3.yyy + r2.xyz;
  r2.xyz = cb3[14].xyz * r3.www + r2.xyz;
  r2.xyz = cb3[15].xyz + r2.xyz;
  r0.xyz = r0.www ? r0.xyz : r2.xyz;
  r2.xyz = cb0[12].xyz * r0.yyy;
  r0.xyw = cb0[11].xyz * r0.xxx + r2.xyz;
  r0.xyz = cb0[13].xyz * r0.zzz + r0.xyw;
  r0.xyz = cb0[14].xyz + r0.xyz;
  r0.w = r0.y * cb0[16].x + 0.5;
  r2.xyz = cb3[13].xyz * r1.yyy;
  r1.xyw = cb3[12].xyz * r1.xxx + r2.xyz;
  r1.xyz = cb3[14].xyz * r1.zzz + r1.xyw;
  r1.xyz = cb3[15].xyz + r1.xyz;
  r1.yw = cb0[12].xz * r1.yy;
  r1.xy = cb0[11].xz * r1.xx + r1.yw;
  r1.xy = cb0[13].xz * r1.zz + r1.xy;
  r1.xz = cb0[14].xz + r1.xy;
  r1.y = r0.w * cb0[16].x + 0.5;
  r1.xzw = -r1.xyz + r0.xwz;
  r0.w = dot(r1.xzw, r1.xzw);
  r1.x = sqrt(r0.w);
  r0.w = rsqrt(r0.w);
  r0.w = r1.z * r0.w;
  r1.x = -r0.w * r1.x + -r1.y;
  r1.y = 1 + -r1.y;
  r1.y = max(9.99999975e-005, r1.y);
  r1.y = log2(r1.y);
  r1.x = 1 + r1.x;
  r1.x = max(9.99999975e-005, r1.x);
  r1.x = log2(r1.x);
  r1.z = 1 + cb0[7].z;
  r1.xy = r1.zz * r1.xy;
  r1.x = exp2(r1.x);
  r0.w = r1.z * r0.w;
  r1.y = exp2(r1.y);
  r1.x = r1.y + -r1.x;
  r0.w = r1.x / r0.w;
  r0.w = cb0[7].x * r0.w;
  r1.xyzw = cb1[0].xxxx * cb0[9].yzxz;
  r1.xyzw = -r1.xyzw * cb0[9].wwww + r0.yzxz;
  r2.xyzw = cb0[15].zwyw * r1.xyzw;
  r0.xy = cb0[15].yz * r1.zx;
  r1.xyzw = t1.Sample(s1_s, r0.xy).xyzw;
  r3.xyzw = t1.Sample(s1_s, r2.xy).xyzw;
  r2.xyzw = t1.Sample(s1_s, r2.zw).xyzw;
  r0.x = r3.x + r2.x;
  r0.x = r0.x + r1.x;
  r0.x = r0.x * r0.w;
  r0.x = r0.x * 0.333333343 + -r0.w;
  r0.x = saturate(cb0[15].x * r0.x + r0.w);
  r0.x = log2(r0.x);
  r0.x = cb0[7].y * r0.x;
  o0.w = exp2(r0.x);
  o0.xyz = cb0[8].xyz;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) D3D Shader Disassembler
//
//   using 3Dmigoto v1.3.12 on Thu Dec 06 14:58:23 2018
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float
// TEXCOORD                 0   xyzw        1     NONE   float   xy w
// TEXCOORD                 1   xyzw        2     NONE   float
// TEXCOORD                 2   xyz         3     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[17], 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 v1.xyw
dcl_output o0.xyzw
dcl_temps 6
add r0.xy, cb4[0].zwzz, cb4[0].zwzz
div r0.zw, v1.xxxy, v1.wwww
mad r0.xy, r0.zwzz, r0.xyxx, -cb4[0].zwzz
sample r1.xyzw, r0.zwzz, t0.xyzw, s0
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 r1.xy, r0.xyxx, r0.zzzz
mul r1.z, r0.z, -cb1[5].z
mul r0.xyz, r1.xyzx, l(1.000000, 1.000000, -1.000000, 0.000000)
mul r1.xyz, r0.yyyy, cb2[19].xyzx
mad r0.xyw, cb2[18].xyxz, r0.xxxx, r1.xyxz
mad r0.xyz, cb2[20].xyzx, r0.zzzz, r0.xywx
add r0.xyz, r0.xyzx, cb2[21].xyzx
mul r1.xyz, r0.yyyy, cb3[17].xyzx
mad r1.xyz, cb3[16].xyzx, r0.xxxx, r1.xyzx
mad r1.xyz, cb3[18].xyzx, r0.zzzz, r1.xyzx
add r1.xyz, r1.xyzx, cb3[19].xyzx
mul r2.xyz, cb1[4].yyyy, cb3[17].xyzx
mad r2.xyz, cb3[16].xyzx, cb1[4].xxxx, r2.xyzx
mad r2.xyz, cb3[18].xyzx, cb1[4].zzzz, r2.xyzx
add r2.xyz, r2.xyzx, cb3[19].xyzx
add r1.xyz, r1.xyzx, -r2.xyzx
dp3 r0.w, r1.xyzx, r1.xyzx
rsq r1.w, r0.w
sqrt r0.w, r0.w
mul r1.xyz, r1.wwww, r1.xyzx
div r3.xyz, l(1.000000, 1.000000, 1.000000, 1.000000), r1.xyzx
add r4.xyz, -r2.xyzx, l(-0.500000, -0.500000, -0.500000, 0.000000)
mul r4.xyz, r3.xyzx, r4.xyzx
add r5.xyz, -r2.xyzx, l(0.500000, 0.500000, 0.500000, 0.000000)
mul r3.xyz, r3.xyzx, r5.xyzx
min r5.xyz, r4.xyzx, r3.xyzx
max r3.xyz, r4.xyzx, r3.xyzx
max r1.w, r5.y, r5.x
max r4.x, r5.z, r1.w
min r1.w, r3.y, r3.x
min r4.y, r3.z, r1.w
add r1.w, -r4.x, r4.y
max r3.xy, r4.xyxx, l(0.000000, 0.000000, 0.000000, 0.000000)
lt r1.w, r1.w, l(0.000000)
discard_nz r1.w
add r1.w, r0.w, -r3.x
lt r0.w, r0.w, r3.y
lt r1.w, r1.w, l(0.000000)
discard_nz r1.w
mad r3.yzw, r3.yyyy, r1.xxyz, r2.xxyz
mad r1.xyz, r3.xxxx, r1.xyzx, r2.xyzx
mul r2.xyz, r3.zzzz, cb3[13].xyzx
mad r2.xyz, cb3[12].xyzx, r3.yyyy, r2.xyzx
mad r2.xyz, cb3[14].xyzx, r3.wwww, r2.xyzx
add r2.xyz, r2.xyzx, cb3[15].xyzx
movc r0.xyz, r0.wwww, r0.xyzx, r2.xyzx
mul r2.xyz, r0.yyyy, cb0[12].xyzx
mad r0.xyw, cb0[11].xyxz, r0.xxxx, r2.xyxz
mad r0.xyz, cb0[13].xyzx, r0.zzzz, r0.xywx
add r0.xyz, r0.xyzx, cb0[14].xyzx
mad r0.w, r0.y, cb0[16].x, l(0.500000)
mul r2.xyz, r1.yyyy, cb3[13].xyzx
mad r1.xyw, cb3[12].xyxz, r1.xxxx, r2.xyxz
mad r1.xyz, cb3[14].xyzx, r1.zzzz, r1.xywx
add r1.xyz, r1.xyzx, cb3[15].xyzx
mul r1.yw, r1.yyyy, cb0[12].xxxz
mad r1.xy, cb0[11].xzxx, r1.xxxx, r1.ywyy
mad r1.xy, cb0[13].xzxx, r1.zzzz, r1.xyxx
add r1.xz, r1.xxyx, cb0[14].xxzx
mad r1.y, r0.w, cb0[16].x, l(0.500000)
add r1.xzw, r0.xxwz, -r1.xxyz
dp3 r0.w, r1.xzwx, r1.xzwx
sqrt r1.x, r0.w
rsq r0.w, r0.w
mul r0.w, r0.w, r1.z
mad r1.x, -r0.w, r1.x, -r1.y
add r1.y, -r1.y, l(1.000000)
max r1.y, r1.y, l(0.000100)
log r1.y, r1.y
add r1.x, r1.x, l(1.000000)
max r1.x, r1.x, l(0.000100)
log r1.x, r1.x
add r1.z, cb0[7].z, l(1.000000)
mul r1.xy, r1.xyxx, r1.zzzz
exp r1.x, r1.x
mul r0.w, r0.w, r1.z
exp r1.y, r1.y
add r1.x, -r1.x, r1.y
div r0.w, r1.x, r0.w
mul r0.w, r0.w, cb0[7].x
mul r1.xyzw, cb0[9].yzxz, cb1[0].xxxx
mad r1.xyzw, -r1.xyzw, cb0[9].wwww, r0.yzxz
mul r2.xyzw, r1.xyzw, cb0[15].zwyw
mul r0.xy, r1.zxzz, cb0[15].yzyy
sample r1.xyzw, r0.xyxx, t1.xyzw, s1
sample r3.xyzw, r2.xyxx, t1.xyzw, s1
sample r2.xyzw, r2.zwzz, t1.xyzw, s1
add r0.x, r2.x, r3.x
add r0.x, r1.x, r0.x
mul r0.x, r0.w, r0.x
mad r0.x, r0.x, l(0.333333343), -r0.w
mad_sat r0.x, cb0[15].x, r0.x, r0.w
log r0.x, r0.x
mul r0.x, r0.x, cb0[7].y
exp o0.w, r0.x
mov o0.xyz, cb0[8].xyzx
ret
// Approximately 0 instruction slots used

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