// ---- Created with 3Dmigoto v1.3.11 on Tue Sep 04 18:07:16 2018

cbuffer _Globals : register(b0)
{
  float4 VPtoRTScaleBias : packoffset(c0);
  float4 ShroudTextureInfo : packoffset(c1);
  float3 RegionTextureInfo : packoffset(c2);
  float Region : packoffset(c2.w);
  float2 WorldPositionOffset : packoffset(c3);
}

cbuffer PerView : register(b12)
{
  row_major float4x4 global_View : packoffset(c0);
  row_major float4x4 global_Projection : packoffset(c4);
  row_major float4x4 global_ViewProjection : packoffset(c8);
  float4 global_ViewPos : packoffset(c12);
  float4 global_ViewInfo : packoffset(c13);
  float4 global_ScaleAndBias : packoffset(c14);
}

SamplerState PointWrapSampler_s : register(s0);
SamplerState LinearClampSampler_s : register(s1);
SamplerState PointClampSampler_s : register(s2);
Texture2D<float4> Base : register(t0);
Texture2D<float4> LinearDepth : register(t1);
Texture2D<float4> Base3 : register(t2);
Texture2D<float4> Base6 : register(t3);


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

void main(
  float4 v0 : SV_Position0,
  float2 v1 : TexCoord0,
  float3 v2 : TexCoord1,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xyz = Base.Sample(LinearClampSampler_s, v1.xy).xyz;
  r0.w = LinearDepth.Sample(PointWrapSampler_s, v1.xy).x;
  r1.x = cmp(r0.w < 1);
  if (r1.x != 0) {
    //r1.xy = r0.ww * v2.xz + global_ViewPos.xz;

float4 s = StereoParams.Load(0);
float4 r20, r25;
r20.xyz = r0.www * v2.xyz + global_ViewPos.xyz;
r20.w = 1.0;
r25 = mul(global_ViewProjection, r20);  
r25.x -= s.x * (r25.w - s.y); 
r20 = mul(inverse(global_ViewProjection), r25);
r1.xy = r20.xz;

    r0.w = cmp(0 < ShroudTextureInfo.w);
    if (r0.w != 0) {
      r1.zw = -WorldPositionOffset.xy + r1.xy;
      r1.zw = r1.zw / ShroudTextureInfo.zz;
      r1.zw = r1.zw / ShroudTextureInfo.xy;
      r0.w = Base3.SampleLevel(LinearClampSampler_s, r1.zw, 0).x;
      r0.xyz = r0.xyz * r0.www;
    }
    r1.xy = -WorldPositionOffset.xy + r1.xy;
    r1.xy = r1.xy / RegionTextureInfo.zz;
    r1.xy = r1.xy / RegionTextureInfo.xy;
    r0.w = Base6.SampleLevel(PointClampSampler_s, r1.xy, 0).x;
    r0.w = r0.w * 255 + -Region;
    r0.w = min(1, abs(r0.w));
    r0.w = 1 + -r0.w;
    r1.xyz = r0.xyz * r0.www;
  } else {
    r0.w = 1 + -ShroudTextureInfo.w;
    r1.xyz = r0.xyz * r0.www;
  }
  o0.xyz = r1.xyz;
  o0.w = 1;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Original ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
// Buffer Definitions: 
//
// cbuffer $Globals
// {
//
//   float4 VPtoRTScaleBias;            // Offset:    0 Size:    16 [unused]
//   float4 ShroudTextureInfo;          // Offset:   16 Size:    16
//   float3 RegionTextureInfo;          // Offset:   32 Size:    12
//   float Region;                      // Offset:   44 Size:     4
//   float2 WorldPositionOffset;        // Offset:   48 Size:     8
//
// }
//
// cbuffer PerView
// {
//
//   row_major float4x4 global_View;    // Offset:    0 Size:    64 [unused]
//   row_major float4x4 global_Projection;// Offset:   64 Size:    64 [unused]
//   row_major float4x4 global_ViewProjection;// Offset:  128 Size:    64 [unused]
//   float4 global_ViewPos;             // Offset:  192 Size:    16
//   float4 global_ViewInfo;            // Offset:  208 Size:    16 [unused]
//   float4 global_ScaleAndBias;        // Offset:  224 Size:    16 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// PointWrapSampler                  sampler      NA          NA    0        1
// LinearClampSampler                sampler      NA          NA    1        1
// PointClampSampler                 sampler      NA          NA    2        1
// Base                              texture  float4          2d    0        1
// LinearDepth                       texture  float4          2d    1        1
// Base3                             texture  float4          2d    2        1
// Base6                             texture  float4          2d    3        1
// $Globals                          cbuffer      NA          NA    0        1
// PerView                           cbuffer      NA          NA   12        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   float       
// TexCoord                 0   xy          1     NONE   float   xy  
// TexCoord                 1   xyz         2     NONE   float   x z 
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[4], immediateIndexed
dcl_constantbuffer cb12[13], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_sampler s2, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_texture2d (float,float,float,float) t2
dcl_resource_texture2d (float,float,float,float) t3
dcl_input_ps linear v1.xy
dcl_input_ps linear v2.xz
dcl_output o0.xyzw
dcl_temps 2
sample_indexable(texture2d)(float,float,float,float) r0.xyz, v1.xyxx, t0.xyzw, s1
sample_indexable(texture2d)(float,float,float,float) r0.w, v1.xyxx, t1.yzwx, s0
lt r1.x, r0.w, l(1.000000)
if_nz r1.x
  mad r1.xy, r0.wwww, v2.xzxx, cb12[12].xzxx
  lt r0.w, l(0.000000), cb0[1].w
  if_nz r0.w
    add r1.zw, r1.xxxy, -cb0[3].xxxy
    div r1.zw, r1.zzzw, cb0[1].zzzz
    div r1.zw, r1.zzzw, cb0[1].xxxy
    sample_l_indexable(texture2d)(float,float,float,float) r0.w, r1.zwzz, t2.yzwx, s1, l(0.000000)
    mul r0.xyz, r0.wwww, r0.xyzx
  endif 
  add r1.xy, r1.xyxx, -cb0[3].xyxx
  div r1.xy, r1.xyxx, cb0[2].zzzz
  div r1.xy, r1.xyxx, cb0[2].xyxx
  sample_l_indexable(texture2d)(float,float,float,float) r0.w, r1.xyxx, t3.yzwx, s2, l(0.000000)
  mad r0.w, r0.w, l(255.000000), -cb0[2].w
  min r0.w, |r0.w|, l(1.000000)
  add r0.w, -r0.w, l(1.000000)
  mul r1.xyz, r0.wwww, r0.xyzx
else 
  add r0.w, -cb0[1].w, l(1.000000)
  mul r1.xyz, r0.wwww, r0.xyzx
endif 
mov o0.xyz, r1.xyzx
mov o0.w, l(1.000000)
ret 
// Approximately 28 instruction slots used

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