// ---- Created with 3Dmigoto v1.3.6 on Mon Sep 03 18:05:12 2018

cbuffer _Globals : register(b0)
{
  float2 Params : packoffset(c0);
  float4 PositionTransition : packoffset(c1);
  float4 SizeRadius : packoffset(c2);
  float4 ProbeProperties : packoffset(c3);
  float4x4 InvWorldTransform : packoffset(c4);
  float FadeValue : packoffset(c8);
  float4 VPtoRTScaleBias : packoffset(c9);
  row_major float3x3 invViewMatrix : packoffset(c10);
}

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 LinearSampler_s : register(s0);
Texture2D<float4> Exposure : register(t0);
TextureCube<float4> IBL_Diffuse_RGB : register(t1);
TextureCube<float4> IBL_Specular_RGB : register(t2);
Texture2D<float4> LUT : register(t3);
Texture2D<float4> LinearDepth : register(t4);
Texture2D<float4> GBuffer1 : register(t5);
Texture2D<float4> GBuffer2 : register(t6);
Texture2D<float4> GBuffer3 : register(t7);


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


void main(
  float4 v0 : SV_Position0,
  float2 v1 : TexCoord0,
  float3 v2 : TexCoord1,
  out float4 o0 : SV_Target0,
  out float4 o1 : SV_Target1)
{
  float4 r0,r1,r2,r3,r4,r5,r6;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xy = (int2)v0.xy;
  r0.zw = float2(0,0);
  r1.xy = GBuffer1.Load(r0.xyw).xy;
  r2.xyzw = GBuffer3.Load(r0.xyw).xyzw;
  r3.z = LinearDepth.Load(r0.xyw).x;
  r1.xy = r1.xy * float2(3.55539989,3.55539989) + float2(-1.77769995,-1.77769995);
  r1.z = 1;
  r1.z = dot(r1.xyz, r1.xyz);
  r1.z = 2 / r1.z;
  r4.xy = r1.zz * r1.xy;
  r4.z = -1 + r1.z;
  r1.x = 255 * r2.w;
  r1.x = round(r1.x);
  r1.x = (uint)r1.x;
  if (2 == 0) r1.x = 0; else if (2+1 < 32) {   r1.x = (uint)r1.x << (32-(2 + 1)); r1.x = (uint)r1.x >> (32-2);  } else r1.x = (uint)r1.x >> 1;
  r1.y = cmp(r3.z != 1.000000);
  r1.x = cmp((int)r1.x != 1);
  r1.x = r1.x ? r1.y : 0;
  r5.x = dot(invViewMatrix._m00_m01_m02, r4.xyz);
  r5.y = dot(invViewMatrix._m10_m11_m12, r4.xyz);
  r5.z = dot(invViewMatrix._m20_m21_m22, r4.xyz);
  r1.yzw = IBL_Diffuse_RGB.Sample(LinearSampler_s, r5.xyz).xyz;
  if (r1.x != 0) {
    r0.xyz = GBuffer2.Load(r0.xyz).xyz;
    r4.z = max(0.0900000036, r2.x);
    r0.w = r2.y * r2.y;
    r0.w = 0.159999996 * r0.w;
    r6.xy = -VPtoRTScaleBias.zw * global_ViewInfo.zw + v0.xy;
    r6.z = global_ViewInfo.w + -r6.y;
    r2.xy = r6.xz / global_ViewInfo.zw;
    r3.xy = r2.xy * float2(2,2) + float2(-1,-1);
    r2.xyw = v2.xyz * r3.xyz;
    r3.xyz = global_View._m10_m11_m12 * r2.yyy;
    r3.xyz = r2.xxx * global_View._m00_m01_m02 + r3.xyz;
    r2.xyw = r2.www * global_View._m20_m21_m22 + r3.xyz;
    r2.xyw = global_ViewPos.xyz + r2.xyw;
    r2.xyw = global_ViewPos.xyz + -r2.xyw;
    r1.x = dot(r2.xyw, r2.xyw);
    r1.x = rsqrt(r1.x);
    r2.xyw = r2.xyw * r1.xxx;
    r1.x = 1 + -r2.z;
    r3.xyz = r1.xxx * r0.xyz;
    r4.y = dot(r5.xyz, r2.xyw);
    r3.w = FadeValue * ProbeProperties.z;
    r1.yzw = r3.www * r1.yzw;
    r1.yzw = float3(100,100,100) * r1.yzw;
    r4.w = LUT.SampleLevel(LinearSampler_s, r4.yz, 0).z;
    r1.yzw = r4.www * r1.yzw;
    r1.yzw = r3.xyz * r1.yzw;
    r0.xyz = r2.zzz * r0.xyz;
    r0.xyz = r1.xxx * r0.www + r0.xyz;
    r0.w = dot(-r2.xyw, r5.xyz);
    r0.w = r0.w + r0.w;
    r2.xyz = r5.xyz * -r0.www + -r2.xyw;
    r4.x = max(0.001953125, r4.y);
    r0.w = ProbeProperties.y * r4.z;
    r2.xyz = IBL_Specular_RGB.SampleLevel(LinearSampler_s, r2.xyz, r0.w).xyz;
    r2.xyz = r2.xyz * r3.www;
    r3.xy = LUT.SampleLevel(LinearSampler_s, r4.xz, 0).xy;
    r2.xyz = float3(100,100,100) * r2.xyz;
    r0.xyz = r0.xyz * r3.xxx + r3.yyy;
    r0.xyz = r2.xyz * r0.xyz;
    r0.w = Exposure.Load(float4(0,0,0,0)).x;
    r1.x = cmp(r0.w == 0.000000);
    r0.w = r1.x ? 0.00999999978 : r0.w;
    r1.xyz = r1.yzw * r0.www;
    r0.xyz = r0.xyz * r0.www;
  } else {
    r0.xyz = float3(0,0,0);
    r1.xyz = float3(0,0,0);
  }
  o0.xyz = r0.xyz;
  o0.w = 0;
  o1.xyz = r1.xyz;
  o1.w = 0;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Original ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//
// Buffer Definitions: 
//
// cbuffer $Globals
// {
//
//   float2 Params;                     // Offset:    0 Size:     8 [unused]
//   float4 PositionTransition;         // Offset:   16 Size:    16 [unused]
//   float4 SizeRadius;                 // Offset:   32 Size:    16 [unused]
//   float4 ProbeProperties;            // Offset:   48 Size:    16
//   float4x4 InvWorldTransform;        // Offset:   64 Size:    64 [unused]
//   float FadeValue;                   // Offset:  128 Size:     4
//   float4 VPtoRTScaleBias;            // Offset:  144 Size:    16
//   row_major float3x3 invViewMatrix;  // Offset:  160 Size:    44
//
// }
//
// cbuffer PerView
// {
//
//   row_major float4x4 global_View;    // Offset:    0 Size:    64
//   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
//   float4 global_ScaleAndBias;        // Offset:  224 Size:    16 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// LinearSampler                     sampler      NA          NA    0        1
// Exposure                          texture  float4          2d    0        1
// IBL_Diffuse_RGB                   texture  float4        cube    1        1
// IBL_Specular_RGB                  texture  float4        cube    2        1
// LUT                               texture  float4          2d    3        1
// LinearDepth                       texture  float4          2d    4        1
// GBuffer1                          texture  float4          2d    5        1
// GBuffer2                          texture  float4          2d    6        1
// GBuffer3                          texture  float4          2d    7        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   xy  
// TexCoord                 0   xy          1     NONE   float       
// TexCoord                 1   xyz         2     NONE   float   xyz 
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
// SV_Target                1   xyzw        1   TARGET   float   xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[13], immediateIndexed
dcl_constantbuffer cb12[14], immediateIndexed
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texturecube (float,float,float,float) t1
dcl_resource_texturecube (float,float,float,float) t2
dcl_resource_texture2d (float,float,float,float) t3
dcl_resource_texture2d (float,float,float,float) t4
dcl_resource_texture2d (float,float,float,float) t5
dcl_resource_texture2d (float,float,float,float) t6
dcl_resource_texture2d (float,float,float,float) t7
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_input_ps linear v2.xyz
dcl_output o0.xyzw
dcl_output o1.xyzw
dcl_temps 7
ftoi r0.xy, v0.xyxx
mov r0.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r1.xy, r0.xyww, t5.xyzw
ld_indexable(texture2d)(float,float,float,float) r2.xyzw, r0.xyww, t7.xyzw
ld_indexable(texture2d)(float,float,float,float) r3.z, r0.xyww, t4.yzxw
mad r1.xy, r1.xyxx, l(3.555400, 3.555400, 0.000000, 0.000000), l(-1.777700, -1.777700, 0.000000, 0.000000)
mov r1.z, l(1.000000)
dp3 r1.z, r1.xyzx, r1.xyzx
div r1.z, l(2.000000), r1.z
mul r4.xy, r1.xyxx, r1.zzzz
add r4.z, r1.z, l(-1.000000)
mul r1.x, r2.w, l(255.000000)
round_ne r1.x, r1.x
ftou r1.x, r1.x
ubfe r1.x, l(2), l(1), r1.x
ne r1.y, r3.z, l(1.000000)
ine r1.x, r1.x, l(1)
and r1.x, r1.x, r1.y
dp3 r5.x, cb0[10].xyzx, r4.xyzx
dp3 r5.y, cb0[11].xyzx, r4.xyzx
dp3 r5.z, cb0[12].xyzx, r4.xyzx
sample_indexable(texturecube)(float,float,float,float) r1.yzw, r5.xyzx, t1.wxyz, s0
if_nz r1.x
  ld_indexable(texture2d)(float,float,float,float) r0.xyz, r0.xyzw, t6.xyzw
  max r4.z, r2.x, l(0.090000)
  mul r0.w, r2.y, r2.y
  mul r0.w, r0.w, l(0.160000)
  mad r6.xy, -cb0[9].zwzz, cb12[13].zwzz, v0.xyxx
  add r6.z, -r6.y, cb12[13].w
  div r2.xy, r6.xzxx, cb12[13].zwzz
  mad r3.xy, r2.xyxx, l(2.000000, 2.000000, 0.000000, 0.000000), l(-1.000000, -1.000000, 0.000000, 0.000000)
  mul r2.xyw, r3.xyxz, v2.xyxz
  mul r3.xyz, r2.yyyy, cb12[1].xyzx
  mad r3.xyz, r2.xxxx, cb12[0].xyzx, r3.xyzx
  mad r2.xyw, r2.wwww, cb12[2].xyxz, r3.xyxz
  add r2.xyw, r2.xyxw, cb12[12].xyxz
  add r2.xyw, -r2.xyxw, cb12[12].xyxz
  dp3 r1.x, r2.xywx, r2.xywx
  rsq r1.x, r1.x
  mul r2.xyw, r1.xxxx, r2.xyxw
  add r1.x, -r2.z, l(1.000000)
  mul r3.xyz, r0.xyzx, r1.xxxx
  dp3 r4.y, r5.xyzx, r2.xywx
  mul r3.w, cb0[3].z, cb0[8].x
  mul r1.yzw, r1.yyzw, r3.wwww
  mul r1.yzw, r1.yyzw, l(0.000000, 100.000000, 100.000000, 100.000000)
  sample_l_indexable(texture2d)(float,float,float,float) r4.w, r4.yzyy, t3.xywz, s0, l(0.000000)
  mul r1.yzw, r1.yyzw, r4.wwww
  mul r1.yzw, r1.yyzw, r3.xxyz
  mul r0.xyz, r0.xyzx, r2.zzzz
  mad r0.xyz, r1.xxxx, r0.wwww, r0.xyzx
  dp3 r0.w, -r2.xywx, r5.xyzx
  add r0.w, r0.w, r0.w
  mad r2.xyz, r5.xyzx, -r0.wwww, -r2.xywx
  max r4.x, r4.y, l(0.001953)
  mul r0.w, r4.z, cb0[3].y
  sample_l_indexable(texturecube)(float,float,float,float) r2.xyz, r2.xyzx, t2.xyzw, s0, r0.w
  mul r2.xyz, r3.wwww, r2.xyzx
  sample_l_indexable(texture2d)(float,float,float,float) r3.xy, r4.xzxx, t3.xyzw, s0, l(0.000000)
  mul r2.xyz, r2.xyzx, l(100.000000, 100.000000, 100.000000, 0.000000)
  mad r0.xyz, r0.xyzx, r3.xxxx, r3.yyyy
  mul r0.xyz, r0.xyzx, r2.xyzx
  ld_indexable(texture2d)(float,float,float,float) r0.w, l(0, 0, 0, 0), t0.yzwx
  eq r1.x, r0.w, l(0.000000)
  movc r0.w, r1.x, l(0.010000), r0.w
  mul r1.xyz, r0.wwww, r1.yzwy
  mul r0.xyz, r0.wwww, r0.xyzx
else 
  mov r0.xyz, l(0,0,0,0)
  mov r1.xyz, l(0,0,0,0)
endif 
mov o0.xyz, r0.xyzx
mov o0.w, l(0)
mov o1.xyz, r1.xyzx
mov o1.w, l(0)
ret 
// Approximately 76 instruction slots used

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


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HLSL errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E:\Spiele\Divinity Original Sin 2 Definitive Edition\DefEd\bin\ShaderCache\c8e1b098670ba693-ps_replace.txt(115,12-41): warning X3206: 'Load': implicit truncation of vector type
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
