//DMC5 skybox PS.
// ---- Created with 3Dmigoto v1.3.15 on Sat Mar 09 12:45:21 2019

cbuffer SceneInfo : register(b0)
{
  row_major float4x4 viewProjMat : packoffset(c0);
  row_major float3x4 transposeViewMat : packoffset(c4);
  row_major float3x4 transposeViewInvMat : packoffset(c7);
  float4 projElement[2] : packoffset(c10);
  float4 projInvElements[2] : packoffset(c12);
  row_major float4x4 viewProjInvMat : packoffset(c14);
  row_major float4x4 prevViewProjMat : packoffset(c18);
  float3 ZToLinear : packoffset(c22);
  float subdivisionLevel : packoffset(c22.w);
  float2 screenSize : packoffset(c23);
  float2 screenInverseSize : packoffset(c23.z);
  float2 cullingHelper : packoffset(c24);
  float cameraNearPlane : packoffset(c24.z);
  float cameraFarPlane : packoffset(c24.w);
  float4 viewFrustum[6] : packoffset(c25);
  float4 clipplane : packoffset(c31);
}

cbuffer CubemapSetting : register(b1)
{
  float IBLExposure : packoffset(c0);
  float IBLRotation : packoffset(c0.y);
  float IBLAddblendFactor : packoffset(c0.z);
  float IBLYAxisoffset : packoffset(c0.w);
  float2 IBL2DTrimmingScale : packoffset(c1);
  float2 IBL2DTrimmingOffset : packoffset(c1.z);
}

SamplerState BilinearClamp_s : register(s0);
Texture2D<float4> IBL2D : register(t0);
Texture2D<float3> IBLAdd2D : register(t1);


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


void main(
  float4 v0 : SV_POSITION0,
  out float4 o0 : SV_TARGET0)
{
  float4 r0,r1,r10,r11;
  uint4 bitmask, uiDest;
  float4 fDest;

  float4 stereo = StereoParams.Load(0);
  
  r0.xy = screenInverseSize.xy * v0.xy;
  r0.xy = r0.xy * float2(2,-2) + float2(-1,1);
  
  r11.xyzw = viewProjInvMat._m10_m11_m12_m13 * r0.yyyy;
  r10.xyzw = r0.xxxx * viewProjInvMat._m00_m01_m02_m03 + r11.xyzw;
  r10.xyzw = viewProjInvMat._m20_m21_m22_m23 * float4(0.00999999978,0.00999999978,0.00999999978,0.00999999978) + r10.xyzw;
  r10.xyzw = viewProjInvMat._m30_m31_m32_m33 + r10.xyzw;
  
  //r0.x-=stereo.x*(1-stereo.y*r10.w*0.00625);
  r0.x-=stereo.x;
  
  r1.xyzw = viewProjInvMat._m10_m11_m12_m13 * r0.yyyy;
  r0.xyzw = r0.xxxx * viewProjInvMat._m00_m01_m02_m03 + r1.xyzw;
  r0.xyzw = viewProjInvMat._m20_m21_m22_m23 * float4(0.00999999978,0.00999999978,0.00999999978,0.00999999978) + r0.xyzw;
  r0.xyzw = viewProjInvMat._m30_m31_m32_m33 + r0.xyzw;
  r0.xyz = r0.xyz / r0.www;
  r1.x = -transposeViewInvMat._m03;
  r1.y = -transposeViewInvMat._m13;
  r1.z = -transposeViewInvMat._m23;
  r0.xyz = r1.xyz + r0.xyz;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r0.xyz = r0.xzy * r0.www;
  r0.w = cmp(IBLYAxisoffset != 0.000000);
  if (r0.w != 0) {
    r0.w = dot(r0.xyz, r0.xyz);
    r1.x = IBLYAxisoffset * r0.z;
    r1.z = IBLYAxisoffset * IBLYAxisoffset + -10000;
    r1.z = r1.z * r0.w;
    r1.yz = float2(-2,4) * r1.xz;
    r1.y = r1.y * r1.y + -r1.z;
    r1.z = cmp(r1.y >= 0);
    if (r1.z != 0) {
      r1.y = sqrt(r1.y);
      r1.x = -r1.x * -2 + r1.y;
      r0.w = r0.w + r0.w;
      r0.w = r1.x / r0.w;
      r0.w = max(0, r0.w);
      r1.xz = float2(0,0);
      r1.y = IBLYAxisoffset;
      r1.xyz = r0.xzy * r0.www + -r1.xyz;
      r0.w = dot(r1.xyz, r1.xyz);
      r0.w = rsqrt(r0.w);
      r0.xyz = r1.xzy * r0.www;
    }
  }
  r0.w = min(abs(r0.y), abs(r0.x));
  r1.x = max(abs(r0.y), abs(r0.x));
  r1.x = 1 / r1.x;
  r0.w = r1.x * r0.w;
  r1.x = r0.w * r0.w;
  r1.y = r1.x * 0.0208350997 + -0.0851330012;
  r1.y = r1.x * r1.y + 0.180141002;
  r1.y = r1.x * r1.y + -0.330299497;
  r1.x = r1.x * r1.y + 0.999866009;
  r1.y = r1.x * r0.w;
  r1.z = cmp(abs(r0.x) < abs(r0.y));
  r1.y = r1.y * -2 + 1.57079637;
  r1.y = r1.z ? r1.y : 0;
  r0.w = r0.w * r1.x + r1.y;
  r1.x = cmp(r0.x < -r0.x);
  r1.x = r1.x ? -3.141593 : 0;
  r0.w = r1.x + r0.w;
  r1.x = min(r0.y, r0.x);
  r0.x = max(r0.y, r0.x);
  r0.y = cmp(r1.x < -r1.x);
  r0.x = cmp(r0.x >= -r0.x);
  r0.x = r0.x ? r0.y : 0;
  r0.x = r0.x ? -r0.w : r0.w;
  r0.x = r0.x * 0.159154937 + 0.5;
  r0.x = -IBLRotation + r0.x;
  r0.x = frac(r0.x);
  r0.y = 1 + -abs(r0.z);
  r0.y = sqrt(r0.y);
  r0.w = abs(r0.z) * -0.0187292993 + 0.0742610022;
  r0.w = r0.w * abs(r0.z) + -0.212114394;
  r0.w = r0.w * abs(r0.z) + 1.57072878;
  r1.x = r0.w * r0.y;
  r1.x = r1.x * -2 + 3.14159274;
  r0.z = cmp(r0.z < -r0.z);
  r0.z = r0.z ? r1.x : 0;
  r0.y = r0.w * r0.y + r0.z;
  r0.y = IBL2DTrimmingScale.y * r0.y;
  r1.x = IBL2DTrimmingScale.x * r0.x;
  r1.y = 0.318309873 * r0.y;
  r0.xy = saturate(IBL2DTrimmingOffset.xy + r1.xy);
  r1.xyz = IBLAdd2D.SampleLevel(BilinearClamp_s, r0.xy, 0).xyz;
  r0.xyz = IBL2D.SampleLevel(BilinearClamp_s, r0.xy, 0).xyz;
  r0.xyz = IBLExposure * r0.xyz;
  o0.xyz = r1.xyz * IBLAddblendFactor + r0.xyz;
  o0.w = 0;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//   using 3Dmigoto v1.3.15 on Sat Mar 09 12:45:21 2019
//
//
// Buffer Definitions:
//
// cbuffer SceneInfo
// {
//
//   row_major float4x4 viewProjMat;    // Offset:    0 Size:    64 [unused]
//   row_major float3x4 transposeViewMat;// Offset:   64 Size:    48 [unused]
//   row_major float3x4 transposeViewInvMat;// Offset:  112 Size:    48
//   float4 projElement[2];             // Offset:  160 Size:    32 [unused]
//   float4 projInvElements[2];         // Offset:  192 Size:    32 [unused]
//   row_major float4x4 viewProjInvMat; // Offset:  224 Size:    64
//   row_major float4x4 prevViewProjMat;// Offset:  288 Size:    64 [unused]
//   float3 ZToLinear;                  // Offset:  352 Size:    12 [unused]
//   float subdivisionLevel;            // Offset:  364 Size:     4 [unused]
//   float2 screenSize;                 // Offset:  368 Size:     8 [unused]
//   float2 screenInverseSize;          // Offset:  376 Size:     8
//   float2 cullingHelper;              // Offset:  384 Size:     8 [unused]
//   float cameraNearPlane;             // Offset:  392 Size:     4 [unused]
//   float cameraFarPlane;              // Offset:  396 Size:     4 [unused]
//   float4 viewFrustum[6];             // Offset:  400 Size:    96 [unused]
//   float4 clipplane;                  // Offset:  496 Size:    16 [unused]
//
// }
//
// cbuffer CubemapSetting
// {
//
//   float IBLExposure;                 // Offset:    0 Size:     4
//   float IBLRotation;                 // Offset:    4 Size:     4
//   float IBLAddblendFactor;           // Offset:    8 Size:     4
//   float IBLYAxisoffset;              // Offset:   12 Size:     4
//   float2 IBL2DTrimmingScale;         // Offset:   16 Size:     8
//   float2 IBL2DTrimmingOffset;        // Offset:   24 Size:     8
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// BilinearClamp                     sampler      NA          NA    0        1
// IBL2D                             texture  float4          2d    0        1
// IBLAdd2D                          texture  float3          2d    1        1
// SceneInfo                         cbuffer      NA          NA    0        1
// CubemapSetting                    cbuffer      NA          NA    1        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   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[24], immediateIndexed
dcl_constantbuffer cb1[2], immediateIndexed
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_output o0.xyzw
dcl_temps 2
mul r0.xy, v0.xyxx, cb0[23].zwzz
mad r0.xy, r0.xyxx, l(2.000000, -2.000000, 0.000000, 0.000000), l(-1.000000, 1.000000, 0.000000, 0.000000)
mul r1.xyzw, r0.yyyy, cb0[15].xyzw
mad r0.xyzw, r0.xxxx, cb0[14].xyzw, r1.xyzw
mad r0.xyzw, cb0[16].xyzw, l(0.010000, 0.010000, 0.010000, 0.010000), r0.xyzw
add r0.xyzw, r0.xyzw, cb0[17].xyzw
div r0.xyz, r0.xyzx, r0.wwww
mov r1.x, -cb0[7].w
mov r1.y, -cb0[8].w
mov r1.z, -cb0[9].w
add r0.xyz, r0.xyzx, r1.xyzx
dp3 r0.w, r0.xyzx, r0.xyzx
rsq r0.w, r0.w
mul r0.xyz, r0.wwww, r0.xzyx
ne r0.w, cb1[0].w, l(0.000000)
if_nz r0.w
  dp3 r0.w, r0.xyzx, r0.xyzx
  mul r1.x, r0.z, cb1[0].w
  mad r1.z, cb1[0].w, cb1[0].w, l(-10000.000000)
  mul r1.z, r0.w, r1.z
  mul r1.yz, r1.xxzx, l(0.000000, -2.000000, 4.000000, 0.000000)
  mad r1.y, r1.y, r1.y, -r1.z
  ge r1.z, r1.y, l(0.000000)
  if_nz r1.z
    sqrt r1.y, r1.y
    mad r1.x, -r1.x, l(-2.000000), r1.y
    add r0.w, r0.w, r0.w
    div r0.w, r1.x, r0.w
    max r0.w, r0.w, l(0.000000)
    mov r1.xz, l(0,0,0,0)
    mov r1.y, cb1[0].w
    mad r1.xyz, r0.xzyx, r0.wwww, -r1.xyzx
    dp3 r0.w, r1.xyzx, r1.xyzx
    rsq r0.w, r0.w
    mul r0.xyz, r0.wwww, r1.xzyx
  endif
endif
min r0.w, |r0.x|, |r0.y|
max r1.x, |r0.x|, |r0.y|
div r1.x, l(1.000000, 1.000000, 1.000000, 1.000000), r1.x
mul r0.w, r0.w, r1.x
mul r1.x, r0.w, r0.w
mad r1.y, r1.x, l(0.0208350997), l(-0.085133)
mad r1.y, r1.x, r1.y, l(0.180141)
mad r1.y, r1.x, r1.y, l(-0.330299497)
mad r1.x, r1.x, r1.y, l(0.999866)
mul r1.y, r0.w, r1.x
lt r1.z, |r0.x|, |r0.y|
mad r1.y, r1.y, l(-2.000000), l(1.57079637)
and r1.y, r1.z, r1.y
mad r0.w, r0.w, r1.x, r1.y
lt r1.x, r0.x, -r0.x
and r1.x, r1.x, l(0xc0490fdb)
add r0.w, r0.w, r1.x
min r1.x, r0.x, r0.y
max r0.x, r0.x, r0.y
lt r0.y, r1.x, -r1.x
ge r0.x, r0.x, -r0.x
and r0.x, r0.x, r0.y
movc r0.x, r0.x, -r0.w, r0.w
mad r0.x, r0.x, l(0.159154937), l(0.500000)
add r0.x, r0.x, -cb1[0].y
frc r0.x, r0.x
add r0.y, -|r0.z|, l(1.000000)
sqrt r0.y, r0.y
mad r0.w, |r0.z|, l(-0.0187292993), l(0.074261)
mad r0.w, r0.w, |r0.z|, l(-0.212114394)
mad r0.w, r0.w, |r0.z|, l(1.57072878)
mul r1.x, r0.y, r0.w
mad r1.x, r1.x, l(-2.000000), l(3.14159274)
lt r0.z, r0.z, -r0.z
and r0.z, r0.z, r1.x
mad r0.y, r0.w, r0.y, r0.z
mul r0.y, r0.y, cb1[1].y
mul r1.x, r0.x, cb1[1].x
mul r1.y, r0.y, l(0.318309873)
add_sat r0.xy, r1.xyxx, cb1[1].zwzz
sample_l_indexable(texture2d)(float,float,float,float) r1.xyz, r0.xyxx, t1.xyzw, s0, l(0.000000)
sample_l_indexable(texture2d)(float,float,float,float) r0.xyz, r0.xyxx, t0.xyzw, s0, l(0.000000)
mul r0.xyz, r0.xyzx, cb1[0].xxxx
mad o0.xyz, r1.xyzx, cb1[0].zzzz, r0.xyzx
mov o0.w, l(0)
ret
// Approximately 83 instruction slots used

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