//DMC2 fish double image (Lucia story, mission 7).
// ---- Created with 3Dmigoto v1.3.7 on Sat Mar 31 12:03:42 2018

cbuffer PS_CONSTANT_BUFFER : register(b0)
{
  float4 vDiffuseTint : packoffset(c0);
  float4 vEyeDir : packoffset(c1);
  int alpha_test : packoffset(c2);
  int alpha_test_func : packoffset(c2.y);
  float alpha_ref : packoffset(c2.z);
}

SamplerState sampler_TexMain_s : register(s0);
Texture2D<float4> TexMain : register(t0);


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


void main(
  float4 v0 : SV_POSITION0,
  float4 v1 : COLOR0,
  float4 v2 : TEXCOORD0,
  float4 v3 : TEXCOORD1,
  float4 v4 : TEXCOORD2,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1;
  uint4 bitmask, uiDest;
  float4 fDest;

  float4 stereo = StereoParams.Load(0);
  v2.x+=stereo.x*(1-stereo.y/v0.w)*0.5;
  
  r0.xy = v2.zw;
  r0.z = v3.x;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r0.xyz = r0.xyz * r0.www;
  r1.xyzw = vDiffuseTint.xyzw;
  r0.x = dot(vEyeDir.xyz, r0.xyz);
  r0.x = vEyeDir.w * r0.x;
  r0.xy = v2.xy + r0.xx;
  r0.xy = max(float2(0,0), r0.xy);
  r0.xy = min(float2(1,1), r0.xy);
  r0.xyzw = TexMain.Sample(sampler_TexMain_s, r0.xy).xyzw;
  r1.xyzw = min(float4(255,255,255,255), r1.xyzw);
  r0.xyzw = r1.xyzw * r0.xyzw;
  r0.xyzw = r0.wxyz / float4(128,128,128,128);
  r1.xyz = -v4.xyz;
  r0.yzw = r1.xyz + r0.yzw;
  r0.yzw = v4.www * r0.yzw;
  r0.yzw = v4.xyz + r0.yzw;
  r1.x = cmp(0 != alpha_test);
  if (r1.x != 0) {
    r1.x = alpha_test_func;
    r0.x = r0.x;
    r1.y = alpha_ref;
    r1.z = cmp((int)r1.x == 1);
    if (r1.z != 0) {
      r1.z = -1;
    } else {
      r1.w = cmp((int)r1.x == 2);
      if (r1.w != 0) {
        r1.w = cmp(r0.x < r1.y);
        if (r1.w != 0) {
          r1.z = 1;
        } else {
          r1.z = -1;
        }
      } else {
        r1.w = cmp((int)r1.x == 3);
        if (r1.w != 0) {
          r1.w = cmp(r0.x == r1.y);
          if (r1.w != 0) {
            r1.z = 1;
          } else {
            r1.z = -1;
          }
        } else {
          r1.w = cmp((int)r1.x == 4);
          if (r1.w != 0) {
            r1.w = cmp(r1.y >= r0.x);
            if (r1.w != 0) {
              r1.z = 1;
            } else {
              r1.z = -1;
            }
          } else {
            r1.w = cmp((int)r1.x == 5);
            if (r1.w != 0) {
              r1.w = cmp(r1.y < r0.x);
              if (r1.w != 0) {
                r1.z = 1;
              } else {
                r1.z = -1;
              }
            } else {
              r1.w = cmp((int)r1.x == 6);
              if (r1.w != 0) {
                r1.w = cmp(r0.x != r1.y);
                if (r1.w != 0) {
                  r1.z = 1;
                } else {
                  r1.z = -1;
                }
              } else {
                r1.x = cmp((int)r1.x == 7);
                if (r1.x != 0) {
                  r1.x = cmp(r0.x >= r1.y);
                  if (r1.x != 0) {
                    r1.z = 1;
                  } else {
                    r1.z = -1;
                  }
                } else {
                  r1.z = 1;
                }
              }
            }
          }
        }
      }
    }
    r1.z = r1.z;
    r1.x = (int)r1.z;
    r1.x = cmp(r1.x < 0);
    //r1.x = r1.x ? -1.#QNAN0 : 0;
    if (r1.x != 0) discard;
  }
  o0.xyz = r0.yzw;
  o0.w = r0.x;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//   using 3Dmigoto v1.3.7 on Sat Mar 31 12:03:42 2018
//
//
// Buffer Definitions:
//
// cbuffer PS_CONSTANT_BUFFER
// {
//
//   float4 vDiffuseTint;               // Offset:    0 Size:    16
//   float4 vEyeDir;                    // Offset:   16 Size:    16
//   int alpha_test;                    // Offset:   32 Size:     4
//   int alpha_test_func;               // Offset:   36 Size:     4
//   float alpha_ref;                   // Offset:   40 Size:     4
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// sampler_TexMain                   sampler      NA          NA    0        1
// TexMain                           texture  float4          2d    0        1
// PS_CONSTANT_BUFFER                cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float
// COLOR                    0   xyzw        1     NONE   float
// TEXCOORD                 0   xyzw        2     NONE   float   xyzw
// TEXCOORD                 1   xyzw        3     NONE   float   x
// TEXCOORD                 2   xyzw        4     NONE   float   xyzw
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed | skipOptimization
dcl_constantbuffer cb0[3], immediateIndexed
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps linear v2.xyzw
dcl_input_ps linear v3.x
dcl_input_ps linear v4.xyzw
dcl_output o0.xyzw
dcl_temps 2
//
// Initial variable locations:
//   v0.x <- vi.Pos.x; v0.y <- vi.Pos.y; v0.z <- vi.Pos.z; v0.w <- vi.Pos.w;
//   v1.x <- vi.Color.x; v1.y <- vi.Color.y; v1.z <- vi.Color.z; v1.w <- vi.Color.w;
//   v2.x <- vi.TexCoords_or_ScreenPos__NormalXY.x; v2.y <- vi.TexCoords_or_ScreenPos__NormalXY.y; v2.z <- vi.TexCoords_or_ScreenPos__NormalXY.z; v2.w <- vi.TexCoords_or_ScreenPos__NormalXY.w;
//   v3.x <- vi.NormalZ__ObjPosXYZ.x; v3.y <- vi.NormalZ__ObjPosXYZ.y; v3.z <- vi.NormalZ__ObjPosXYZ.z; v3.w <- vi.NormalZ__ObjPosXYZ.w;
//   v4.x <- vi.FogColors__Amount.x; v4.y <- vi.FogColors__Amount.y; v4.z <- vi.FogColors__Amount.z; v4.w <- vi.FogColors__Amount.w;
//   o0.x <- <main return value>.x; o0.y <- <main return value>.y; o0.z <- <main return value>.z; o0.w <- <main return value>.w
//
#line 23 "C:\dev\dmc\dmc2\code\dmc2\source\common\Shaders\hlsl\PS\P00000002.hlsl"
mov r0.xy, v2.zwzz
mov r0.z, v3.x
dp3 r0.w, r0.xyzx, r0.xyzx
rsq r0.w, r0.w
mul r0.xyz, r0.wwww, r0.xyzx  // r0.x <- normal.x; r0.y <- normal.y; r0.z <- normal.z

#line 29
mov r1.xyzw, cb0[0].xyzw  // r1.x <- fragmentColor.x; r1.y <- fragmentColor.y; r1.z <- fragmentColor.z; r1.w <- fragmentColor.w
dp3 r0.x, cb0[1].xyzx, r0.xyzx
mul r0.x, r0.x, cb0[1].w  // r0.x <- d
add r0.xy, r0.xxxx, v2.xyxx
max r0.xy, r0.xyxx, l(0.000000, 0.000000, 0.000000, 0.000000)
min r0.xy, r0.xyxx, l(1.000000, 1.000000, 0.000000, 0.000000)  // r0.x <- uv.x; r0.y <- uv.y
sample_indexable(texture2d)(float,float,float,float) r0.xyzw, r0.xyxx, t0.xyzw, s0  // r0.x <- textureColor.x; r0.y <- textureColor.y; r0.z <- textureColor.z; r0.w <- textureColor.w

#line 39
min r1.xyzw, r1.xyzw, l(255.000000, 255.000000, 255.000000, 255.000000)

#line 42
mul r0.xyzw, r0.xyzw, r1.xyzw
div r0.xyzw, r0.wxyz, l(128.000000, 128.000000, 128.000000, 128.000000)  // r0.x <- finalColor.w; r0.y <- finalColor.x; r0.z <- finalColor.y; r0.w <- finalColor.z

#line 45
mov r1.xyz, -v4.xyzx
add r0.yzw, r0.yyzw, r1.xxyz
mul r0.yzw, r0.yyzw, v4.wwww
add r0.yzw, r0.yyzw, v4.xxyz  // r0.y <- finalColor.x; r0.z <- finalColor.y; r0.w <- finalColor.z
ine r1.x, l(0, 0, 0, 0), cb0[2].x
if_nz r1.x
  nop
  mov r1.x, cb0[2].y
  mov r0.x, r0.x
  mov r1.y, cb0[2].z

#line 106 "C:\dev\dmc\dmc2\code\dmc2\source\common\Shaders\hlsl\Shared.fxh"
  ieq r1.z, r1.x, l(1)
  if_nz r1.z
    mov r1.z, l(-1)  // r1.z <- <AlphaTestFunc return value>
  else
    ieq r1.w, r1.x, l(2)
    if_nz r1.w
      lt r1.w, r0.x, r1.y
      if_nz r1.w
        mov r1.z, l(1)  // r1.z <- <AlphaTestFunc return value>
      else

#line 119
        mov r1.z, l(-1)  // r1.z <- <AlphaTestFunc return value>
      endif
    else
      ieq r1.w, r1.x, l(3)
      if_nz r1.w
        eq r1.w, r0.x, r1.y
        if_nz r1.w
          mov r1.z, l(1)  // r1.z <- <AlphaTestFunc return value>
        else

#line 131
          mov r1.z, l(-1)  // r1.z <- <AlphaTestFunc return value>
        endif
      else
        ieq r1.w, r1.x, l(4)
        if_nz r1.w
          ge r1.w, r1.y, r0.x
          if_nz r1.w
            mov r1.z, l(1)  // r1.z <- <AlphaTestFunc return value>
          else

#line 143
            mov r1.z, l(-1)  // r1.z <- <AlphaTestFunc return value>
          endif
        else
          ieq r1.w, r1.x, l(5)
          if_nz r1.w
            lt r1.w, r1.y, r0.x
            if_nz r1.w
              mov r1.z, l(1)  // r1.z <- <AlphaTestFunc return value>
            else

#line 155
              mov r1.z, l(-1)  // r1.z <- <AlphaTestFunc return value>
            endif
          else
            ieq r1.w, r1.x, l(6)
            if_nz r1.w
              ne r1.w, r0.x, r1.y
              if_nz r1.w
                mov r1.z, l(1)  // r1.z <- <AlphaTestFunc return value>
              else

#line 167
                mov r1.z, l(-1)  // r1.z <- <AlphaTestFunc return value>
              endif
            else
              ieq r1.x, r1.x, l(7)
              if_nz r1.x
                ge r1.x, r0.x, r1.y
                if_nz r1.x
                  mov r1.z, l(1)  // r1.z <- <AlphaTestFunc return value>
                else

#line 179
                  mov r1.z, l(-1)  // r1.z <- <AlphaTestFunc return value>
                endif
              else

#line 184
                mov r1.z, l(1)  // r1.z <- <AlphaTestFunc return value>
              endif
            endif
          endif
        endif
      endif
    endif
  endif

#line 49 "C:\dev\dmc\dmc2\code\dmc2\source\common\Shaders\hlsl\PS\P00000002.hlsl"
  mov r1.z, r1.z  // r1.z <- clipVal
  itof r1.x, r1.z
  lt r1.x, r1.x, l(0.000000)
  and r1.x, r1.x, l(-1)
  discard_nz r1.x
endif
mov o0.xyz, r0.yzwy
mov o0.w, r0.x
ret
// Approximately 100 instruction slots used

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