//Daigo rain cutscene lighting.
// ---- Created with 3Dmigoto v1.3.16 on Sat Apr 10 21:04:44 2021
Texture2D<float4> t3 : register(t3);

Texture2DMS<float4> t2 : register(t2);

Texture2DMS<float4> t1 : register(t1);

Texture2DMS<float4> t0 : register(t0);

SamplerState s3_s : register(s3);

cbuffer cb9 : register(b9)
{
  float4 cb9[10];
}

cbuffer cb12 : register(b12)
{
  float4 cb12[7];
}


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


void main(
  float4 v0 : TEXCOORD0,
  float3 v1 : TEXCOORD1,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r4;
  uint4 bitmask, uiDest;
  float4 fDest;
  
  float4 stereo = StereoParams.Load(0);
  
  r0.xy = v0.xy / v0.zz;
  r0.xy = cb9[6].zw * r0.xy;
  r0.xy = (int2)r0.xy;
  r0.zw = float2(0,0);
  r1.xyz = t1.Load(r0.xy, 0).xyz;
  r1.w = t2.Load(r0.xy, 0).x;
  r1.xy = float2(4,4) * r1.xy;
  r2.x = dot(r1.xy, r1.xy);
  r2.zw = -r2.xx * float2(0.25,0.5) + float2(1,1);
  r2.z = max(0, r2.z);
  r2.z = sqrt(r2.z);
  r2.xy = r2.zz * r1.xy;
  r1.x = r1.w * 2 + -1;
  r1.y = f32tof16(r1.z);
  r1.y = (uint)r1.y >> 7;
  r1.y = (int)r1.y ^ 383;
  r1.y = (int)r1.y & 2;
  r0.x = t0.Load(r0.xy, 0).x;
  r0.x = cb9[0].x + r0.x;
  r0.x = -cb9[0].y / r0.x;
  r0.xyz = v1.xyz * r0.xxx;
  
  r0.x+=stereo.x*(r0.z+stereo.y*v1.z)/cb12[0].x;
  
  r0.xyz = r0.xyz / v1.zzz;
  r0.w = dot(cb9[1].xyz, r2.xyw);
  r3.xyz = -r2.xyw * r0.www + cb9[1].xyz;
  r1.z = cb9[0].z + -1;
  r1.z = cb9[0].w * r1.z;
  r4.xyz = r3.xyz * r1.zzz + r0.xyz;
  r1.z = cb9[0].w * cb9[0].z;
  r3.xyz = r3.xyz * r1.zzz + r0.xyz;
  r4.w = 1;
  r0.x = dot(cb9[7].xyzw, r4.xyzw);
  r0.y = dot(cb9[8].xyzw, r4.xyzw);
  r0.z = dot(cb9[9].xyzw, r4.xyzw);
  r3.w = 1;
  r4.x = dot(cb9[7].xyzw, r3.xyzw);
  r4.y = dot(cb9[8].xyzw, r3.xyzw);
  r4.z = dot(cb9[9].xyzw, r3.xyzw);
  r3.xyzw = cb9[2].yzzy * r0.xyyz;
  r0.y = t3.Sample(s3_s, r3.xy).w;
  r1.z = t3.Sample(s3_s, r3.zw).w;
  r0.x = t3.Sample(s3_s, r0.zx).w;
  r3.xyzw = cb9[2].yzzy * r4.xyyz;
  r0.z = t3.Sample(s3_s, r3.xy).w;
  r1.w = t3.Sample(s3_s, r3.zw).w;
  r2.z = t3.Sample(s3_s, r4.zx).w;
  if (r1.y != 0) {
    r1.y = max(0, r0.w);
    r3.x = max(0, -r0.w);
    r3.y = 1 + -abs(r0.w);
    r3.z = cb9[4].w * r3.y;
    r3.z = cb9[4].z * r1.y + r3.z;
    r3.z = cb9[6].y * r3.x + r3.z;
    r1.y = r3.y + r1.y;
    r1.y = r1.y + r3.x;
    r1.y = r3.z / r1.y;
    r3.x = cmp(r1.y < 0);
    if (r3.x != 0) discard;
    r1.y = min(1, r1.y);
    r3.x = cb9[3].w + -cb9[3].y;
    r3.x = r1.x * r3.x + cb9[3].y;
    r1.y = cb9[5].w * r1.y;
    r3.x = -1 + r3.x;
    o0.xyz = r1.yyy * r3.xxx + float3(1,1,1);
    o0.w = 1;
    return;
  } else {
    r3.x = dot(cb9[7].xyz, r2.xyw);
    r3.y = dot(cb9[8].xyz, r2.xyw);
    r3.z = dot(cb9[9].xyz, r2.xyw);
    r2.xyw = r3.xyz * r3.xyz;
    r2.xyw = float3(0.100000001,1,0.100000001) * r2.xyw;
    r1.y = dot(r2.xyw, float3(1,1,1));
    r1.y = 1 / r1.y;
    r2.xyw = r2.xyw * r1.yyy;
    r1.y = r2.x * r1.z;
    r0.y = r0.y * r2.w + r1.y;
    r0.x = r0.x * r2.y + r0.y;
    r0.y = r2.x * r1.w;
    r0.y = r0.z * r2.w + r0.y;
    r0.y = r2.z * r2.y + r0.y;
    r0.x = r0.x + -r0.y;
    r0.x = cb9[0].z * r0.x + r0.y;
    r0.y = max(0, r0.w);
    r0.z = max(0, -r0.w);
    r0.w = 1 + -abs(r0.w);
    r1.y = cb9[4].w * r0.w;
    r1.y = cb9[4].z * r0.y + r1.y;
    r1.y = cb9[6].y * r0.z + r1.y;
    r0.y = r0.y + r0.w;
    r0.y = r0.y + r0.z;
    r0.y = r1.y / r0.y;
    r0.x = cb9[5].z * r0.x;
    r0.z = 1 + -r0.y;
    r0.x = r0.x * r0.z + r0.y;
    r0.y = cmp(r0.x < 0);
    if (r0.y != 0) discard;
    r0.x = min(1, r0.x);
    r0.yz = cb9[3].zw + -cb9[3].xy;
    r0.yz = r1.xx * r0.yz + cb9[3].xy;
    r0.z = r0.z + -r0.y;
    r0.x = r0.x * r0.z + r0.y;
    r0.x = -1 + r0.x;
    o0.xyz = cb9[6].xxx * r0.xxx + float3(1,1,1);
    o0.w = 1;
    return;
  }
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) D3D Shader Disassembler
//
//   using 3Dmigoto v1.3.16 on Sat Apr 10 21:04:44 2021
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD                 0   xyz         0     NONE   float   xyz
// TEXCOORD                 1   xyz         1     NONE   float   xyz
//
//
// 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 cb9[10], immediateIndexed
dcl_sampler s3, mode_default
dcl_resource_texture2dms(0) (float,float,float,float) t0
dcl_resource_texture2dms(0) (float,float,float,float) t1
dcl_resource_texture2dms(0) (float,float,float,float) t2
dcl_resource_texture2d (float,float,float,float) t3
dcl_input_ps linear v0.xyz
dcl_input_ps linear v1.xyz
dcl_output o0.xyzw
dcl_temps 5
div r0.xy, v0.xyxx, v0.zzzz
mul r0.xy, r0.xyxx, cb9[6].zwzz
ftoi r0.xy, r0.xyxx
mov r0.zw, l(0,0,0,0)
ldms_indexable(texture2dms)(float,float,float,float) r1.xyz, r0.xyww, t1.xyzw, l(0)
ldms_indexable(texture2dms)(float,float,float,float) r1.w, r0.xyww, t2.yzwx, l(0)
mul r1.xy, r1.xyxx, l(4.000000, 4.000000, 0.000000, 0.000000)
dp2 r2.x, r1.xyxx, r1.xyxx
mad r2.zw, -r2.xxxx, l(0.000000, 0.000000, 0.250000, 0.500000), l(0.000000, 0.000000, 1.000000, 1.000000)
max r2.z, r2.z, l(0.000000)
sqrt r2.z, r2.z
mul r2.xy, r1.xyxx, r2.zzzz
mad r1.x, r1.w, l(2.000000), l(-1.000000)
f32tof16 r1.y, r1.z
ushr r1.y, r1.y, l(7)
xor r1.y, r1.y, l(383)
and r1.y, r1.y, l(2)
ldms_indexable(texture2dms)(float,float,float,float) r0.x, r0.xyzw, t0.xyzw, l(0)
add r0.x, r0.x, cb9[0].x
div r0.x, -cb9[0].y, r0.x
mul r0.xyz, r0.xxxx, v1.xyzx
div r0.xyz, r0.xyzx, v1.zzzz
dp3 r0.w, cb9[1].xyzx, r2.xywx
mad r3.xyz, -r2.xywx, r0.wwww, cb9[1].xyzx
add r1.z, l(-1.000000), cb9[0].z
mul r1.z, r1.z, cb9[0].w
mad r4.xyz, r3.xyzx, r1.zzzz, r0.xyzx
mul r1.z, cb9[0].z, cb9[0].w
mad r3.xyz, r3.xyzx, r1.zzzz, r0.xyzx
mov r4.w, l(1.000000)
dp4 r0.x, cb9[7].xyzw, r4.xyzw
dp4 r0.y, cb9[8].xyzw, r4.xyzw
dp4 r0.z, cb9[9].xyzw, r4.xyzw
mov r3.w, l(1.000000)
dp4 r4.x, cb9[7].xyzw, r3.xyzw
dp4 r4.y, cb9[8].xyzw, r3.xyzw
dp4 r4.z, cb9[9].xyzw, r3.xyzw
mul r3.xyzw, r0.xyyz, cb9[2].yzzy
sample_indexable(texture2d)(float,float,float,float) r0.y, r3.xyxx, t3.xwyz, s3
sample_indexable(texture2d)(float,float,float,float) r1.z, r3.zwzz, t3.xywz, s3
sample_indexable(texture2d)(float,float,float,float) r0.x, r0.zxzz, t3.wxyz, s3
mul r3.xyzw, r4.xyyz, cb9[2].yzzy
sample_indexable(texture2d)(float,float,float,float) r0.z, r3.xyxx, t3.xywz, s3
sample_indexable(texture2d)(float,float,float,float) r1.w, r3.zwzz, t3.xyzw, s3
sample_indexable(texture2d)(float,float,float,float) r2.z, r4.zxzz, t3.xywz, s3
if_nz r1.y
  max r1.y, r0.w, l(0.000000)
  max r3.x, -r0.w, l(0.000000)
  add r3.y, -|r0.w|, l(1.000000)
  mul r3.z, r3.y, cb9[4].w
  mad r3.z, cb9[4].z, r1.y, r3.z
  mad r3.z, cb9[6].y, r3.x, r3.z
  add r1.y, r1.y, r3.y
  add r1.y, r3.x, r1.y
  div r1.y, r3.z, r1.y
  lt r3.x, r1.y, l(0.000000)
  discard_nz r3.x
  min r1.y, r1.y, l(1.000000)
  add r3.x, -cb9[3].y, cb9[3].w
  mad r3.x, r1.x, r3.x, cb9[3].y
  mul r1.y, r1.y, cb9[5].w
  add r3.x, r3.x, l(-1.000000)
  mad o0.xyz, r1.yyyy, r3.xxxx, l(1.000000, 1.000000, 1.000000, 0.000000)
  mov o0.w, l(1.000000)
  ret
else
  dp3 r3.x, cb9[7].xyzx, r2.xywx
  dp3 r3.y, cb9[8].xyzx, r2.xywx
  dp3 r3.z, cb9[9].xyzx, r2.xywx
  mul r2.xyw, r3.xyxz, r3.xyxz
  mul r2.xyw, r2.xyxw, l(0.100000, 1.000000, 0.000000, 0.100000)
  dp3 r1.y, r2.xywx, l(1.000000, 1.000000, 1.000000, 0.000000)
  div r1.y, l(1.000000, 1.000000, 1.000000, 1.000000), r1.y
  mul r2.xyw, r1.yyyy, r2.xyxw
  mul r1.y, r1.z, r2.x
  mad r0.y, r0.y, r2.w, r1.y
  mad r0.x, r0.x, r2.y, r0.y
  mul r0.y, r1.w, r2.x
  mad r0.y, r0.z, r2.w, r0.y
  mad r0.y, r2.z, r2.y, r0.y
  add r0.x, -r0.y, r0.x
  mad r0.x, cb9[0].z, r0.x, r0.y
  max r0.y, r0.w, l(0.000000)
  max r0.z, -r0.w, l(0.000000)
  add r0.w, -|r0.w|, l(1.000000)
  mul r1.y, r0.w, cb9[4].w
  mad r1.y, cb9[4].z, r0.y, r1.y
  mad r1.y, cb9[6].y, r0.z, r1.y
  add r0.y, r0.w, r0.y
  add r0.y, r0.z, r0.y
  div r0.y, r1.y, r0.y
  mul r0.x, r0.x, cb9[5].z
  add r0.z, -r0.y, l(1.000000)
  mad r0.x, r0.x, r0.z, r0.y
  lt r0.y, r0.x, l(0.000000)
  discard_nz r0.y
  min r0.x, r0.x, l(1.000000)
  add r0.yz, -cb9[3].xxyx, cb9[3].zzwz
  mad r0.yz, r1.xxxx, r0.yyzy, cb9[3].xxyx
  add r0.z, -r0.y, r0.z
  mad r0.x, r0.x, r0.z, r0.y
  add r0.x, r0.x, l(-1.000000)
  mad o0.xyz, cb9[6].xxxx, r0.xxxx, l(1.000000, 1.000000, 1.000000, 0.000000)
  mov o0.w, l(1.000000)
  ret
endif
ret
// Approximately 0 instruction slots used

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