//Overworld map PS.
// ---- Created with 3Dmigoto v1.3.16 on Sat Feb 20 21:49:35 2021

cbuffer _Globals : register(b0)
{
  float4 fadeInCenter : packoffset(c0);
  float fadeInRadiusStart : packoffset(c1);
  float fadeInRadiusEnd : packoffset(c1.y);
  row_major float4x4 mP2W : packoffset(c2);
  float colorGradingScale : packoffset(c6);
}

SamplerState __smpsDepth_s : register(s0);
SamplerState __smpsHDRLut_s : register(s1);
SamplerState __smpsJapanMap_s : register(s2);
Texture2D<float4> sDepth : register(t0);
Texture3D<float4> sHDRLut : register(t1);
Texture2D<float4> sJapanMap : register(t2);


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


void main(
  float4 v0 : SV_Position0,
  float4 v1 : TEXCOORD0,
  float2 v2 : TEXCOORD1,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r10;
  uint4 bitmask, uiDest;
  float4 fDest;
  
  float4 stereo = StereoParams.Load(0);
  
  r0.x = sDepth.Sample(__smpsDepth_s, v2.xy).x;
  r0.y = cmp(r0.x == 1.000000);
  if (r0.y != 0) discard;
  
  r10.yzw = mP2W._m10_m12_m13 * v1.yyy;
  r10.yzw = v1.xxx * mP2W._m00_m02_m03 + r10.yzw;
  r10.xyz = r0.xxx * mP2W._m20_m22_m23 + r10.yzw;
  r10.xyz = mP2W._m30_m32_m33 + r10.xyz;
  
  v1.x+=stereo.x*(stereo.y*r10.z-1);
  
  r0.yzw = mP2W._m10_m12_m13 * v1.yyy;
  r0.yzw = v1.xxx * mP2W._m00_m02_m03 + r0.yzw;
  r0.xyz = r0.xxx * mP2W._m20_m22_m23 + r0.yzw;
  r0.xyz = mP2W._m30_m32_m33 + r0.xyz;
  r0.xy = r0.xy / r0.zz;
  r0.zw = -fadeInCenter.xz + r0.xy;
  r0.z = dot(r0.zw, r0.zw);
  r0.z = sqrt(r0.z);
  r0.w = cmp(fadeInRadiusStart < r0.z);
  r0.xy = float2(2.60416673e-005,5.20833346e-005) * r0.xy;
  r1.xyz = sJapanMap.Sample(__smpsJapanMap_s, r0.xy).xyz;
  if (r0.w != 0) {
    r0.x = fadeInRadiusEnd + -fadeInRadiusStart;
    r0.y = -fadeInRadiusStart + r0.z;
    r0.x = 1 / r0.x;
    r0.x = saturate(r0.y * r0.x);
    r0.y = r0.x * -2 + 3;
    r0.x = r0.x * r0.x;
    o0.w = r0.y * r0.x;
  } else {
    r1.xyz = float3(0,0,0);
    o0.w = 0;
  }
  r0.xyz = r1.xyz * float3(5.55555677,5.55555677,5.55555677) + float3(0.0479959995,0.0479959995,0.0479959995);
  r0.xyz = log2(r0.xyz);
  r0.xyz = saturate(r0.xyz * float3(0.0734997839,0.0734997839,0.0734997839) + float3(0.386036009,0.386036009,0.386036009));
  r0.xyz = sHDRLut.Sample(__smpsHDRLut_s, r0.xyz).xyz;
  r0.w = 1 + -colorGradingScale;
  r0.xyz = colorGradingScale * r0.xyz;
  o0.xyz = r1.xyz * r0.www + r0.xyz;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//   using 3Dmigoto v1.3.16 on Sat Feb 20 21:49:35 2021
//
//
// Buffer Definitions:
//
// cbuffer $Globals
// {
//
//   float4 fadeInCenter;               // Offset:    0 Size:    16
//   float fadeInRadiusStart;           // Offset:   16 Size:     4
//   float fadeInRadiusEnd;             // Offset:   20 Size:     4
//   row_major float4x4 mP2W;           // Offset:   32 Size:    64
//   float colorGradingScale;           // Offset:   96 Size:     4
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// __smpsDepth                       sampler      NA          NA    0        1
// __smpsHDRLut                      sampler      NA          NA    1        1
// __smpsJapanMap                    sampler      NA          NA    2        1
// sDepth                            texture  float4          2d    0        1
// sHDRLut                           texture  float4          3d    1        1
// sJapanMap                         texture  float4          2d    2        1
// $Globals                          cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   float
// TEXCOORD                 0   xyzw        1     NONE   float   xy
// TEXCOORD                 1   xy          2     NONE   float   xy
//
//
// 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[7], 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_texture3d (float,float,float,float) t1
dcl_resource_texture2d (float,float,float,float) t2
dcl_input_ps linear v1.xy
dcl_input_ps linear v2.xy
dcl_output o0.xyzw
dcl_temps 2
sample_indexable(texture2d)(float,float,float,float) r0.x, v2.xyxx, t0.xyzw, s0
eq r0.y, r0.x, l(1.000000)
discard_nz r0.y
mul r0.yzw, v1.yyyy, cb0[3].xxzw
mad r0.yzw, v1.xxxx, cb0[2].xxzw, r0.yyzw
mad r0.xyz, r0.xxxx, cb0[4].xzwx, r0.yzwy
add r0.xyz, r0.xyzx, cb0[5].xzwx
div r0.xy, r0.xyxx, r0.zzzz
add r0.zw, r0.xxxy, -cb0[0].xxxz
dp2 r0.z, r0.zwzz, r0.zwzz
sqrt r0.z, r0.z
lt r0.w, cb0[1].x, r0.z
mul r0.xy, r0.xyxx, l(0.0000260416673, 0.0000520833346, 0.000000, 0.000000)
sample_indexable(texture2d)(float,float,float,float) r1.xyz, r0.xyxx, t2.xyzw, s2
if_nz r0.w
  add r0.x, -cb0[1].x, cb0[1].y
  add r0.y, r0.z, -cb0[1].x
  div r0.x, l(1.000000, 1.000000, 1.000000, 1.000000), r0.x
  mul_sat r0.x, r0.x, r0.y
  mad r0.y, r0.x, l(-2.000000), l(3.000000)
  mul r0.x, r0.x, r0.x
  mul o0.w, r0.x, r0.y
else
  mov r1.xyz, l(0,0,0,0)
  mov o0.w, l(0)
endif
mad r0.xyz, r1.xyzx, l(5.555557, 5.555557, 5.555557, 0.000000), l(0.047996, 0.047996, 0.047996, 0.000000)
log r0.xyz, r0.xyzx
mad_sat r0.xyz, r0.xyzx, l(0.0734997839, 0.0734997839, 0.0734997839, 0.000000), l(0.386036, 0.386036, 0.386036, 0.000000)
sample_indexable(texture3d)(float,float,float,float) r0.xyz, r0.xyzx, t1.xyzw, s1
add r0.w, -cb0[6].x, l(1.000000)
mul r0.xyz, r0.xyzx, cb0[6].xxxx
mad o0.xyz, r1.xyzx, r0.wwww, r0.xyzx
ret
// Approximately 34 instruction slots used

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