//DMC5 depth of field 1.
// ---- Created with 3Dmigoto v1.3.15-re2_workaround on Fri Mar 15 16:18:48 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 dof : register(b1)
{
  float coc_bias : packoffset(c0);
  float coc_scale : packoffset(c0.y);
  float focal_plane_depth : packoffset(c0.z);
  float pcoc : packoffset(c0.w);
  float quad_reduction_threshold : packoffset(c1);
  float quater_resolution_threshold : packoffset(c1.y);
  float near_blur_scaler : packoffset(c1.z);
  float depth_adjuist_factor : packoffset(c1.w);
  float bokeh_intensity_threshold : packoffset(c2);
  float bokeh_shape_factor : packoffset(c2.y);
  float dof_single_pixel_radius : packoffset(c2.z);
  float dof_aspect : packoffset(c2.w);
}

SamplerState PointClamp_s : register(s0);
SamplerState BilinearClamp_s : register(s1);
Texture2D<float3> CoC : register(t0);
Texture2D<float4> Image : register(t1);
Texture2D<float4> HDRImage : register(t2);
Texture2D<float4> BlendImage : register(t3);
Texture2D<float3> Neighbor : register(t4);
Texture2D<float> DOFAImage : register(t5);


// 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,r2;
  uint4 bitmask, uiDest;
  float4 fDest;

  float4 iniparams11 = IniParams.Load(int2(11,0));
  
  r0.xy = float2(0.5,0.5) * screenInverseSize.xy;
  r0.xy = v0.xy * screenInverseSize.xy + r0.xy;
  r0.z = CoC.SampleLevel(PointClamp_s, r0.xy, 0).x;
  r0.w = Neighbor.SampleLevel(PointClamp_s, r0.xy, 0).y;
  r0.w = min(dof_single_pixel_radius, abs(r0.w));
  r1.x = DOFAImage.SampleLevel(BilinearClamp_s, r0.xy, 0).x;
  
  if (iniparams11.z==1)
  {
	r0.w=0;
	r0.z=0;
	r1.x=0;
  }
  
  r0.w = r0.w + -r0.z;
  r0.z = r1.x * r0.w + r0.z;
  r0.z = r0.z / pcoc;
  r0.z = saturate(0.5 * r0.z);
  r1.xy = (int2)v0.xy;
  r1.zw = float2(0,0);
  r1.xyz = HDRImage.Load(r1.xyz).xyz;
  r0.w = cmp(0 < r0.z);
  if (r0.w != 0) {
    r2.xyz = Image.SampleLevel(BilinearClamp_s, r0.xy, 0).xyz;
    r2.xyz = r2.xyz + -r1.xyz;
    r1.xyz = r0.zzz * r2.xyz + r1.xyz;
  }
  r0.xyzw = BlendImage.SampleLevel(PointClamp_s, r0.xy, 0).xyzw;
  o0.xyz = r1.xyz * r0.www + r0.xyz;
  o0.w = 0;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//   using 3Dmigoto v1.3.15-re2_workaround on Fri Mar 15 16:18:48 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 [unused]
//   float4 projElement[2];             // Offset:  160 Size:    32 [unused]
//   float4 projInvElements[2];         // Offset:  192 Size:    32 [unused]
//   row_major float4x4 viewProjInvMat; // Offset:  224 Size:    64 [unused]
//   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 dof
// {
//
//   float coc_bias;                    // Offset:    0 Size:     4 [unused]
//   float coc_scale;                   // Offset:    4 Size:     4 [unused]
//   float focal_plane_depth;           // Offset:    8 Size:     4 [unused]
//   float pcoc;                        // Offset:   12 Size:     4
//   float quad_reduction_threshold;    // Offset:   16 Size:     4 [unused]
//   float quater_resolution_threshold; // Offset:   20 Size:     4 [unused]
//   float near_blur_scaler;            // Offset:   24 Size:     4 [unused]
//   float depth_adjuist_factor;        // Offset:   28 Size:     4 [unused]
//   float bokeh_intensity_threshold;   // Offset:   32 Size:     4 [unused]
//   float bokeh_shape_factor;          // Offset:   36 Size:     4 [unused]
//   float dof_single_pixel_radius;     // Offset:   40 Size:     4
//   float dof_aspect;                  // Offset:   44 Size:     4 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// PointClamp                        sampler      NA          NA    0        1
// BilinearClamp                     sampler      NA          NA    1        1
// CoC                               texture  float3          2d    0        1
// Image                             texture  float4          2d    1        1
// HDRImage                          texture  float4          2d    2        1
// BlendImage                        texture  float4          2d    3        1
// Neighbor                          texture  float3          2d    4        1
// DOFAImage                         texture   float          2d    5        1
// SceneInfo                         cbuffer      NA          NA    0        1
// dof                               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[3], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_texture2d (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_input_ps_siv linear noperspective v0.xy, position
dcl_output o0.xyzw
dcl_temps 3
mul r0.xy, cb0[23].zwzz, l(0.500000, 0.500000, 0.000000, 0.000000)
mad r0.xy, v0.xyxx, cb0[23].zwzz, r0.xyxx
sample_l_indexable(texture2d)(float,float,float,float) r0.z, r0.xyxx, t0.yzxw, s0, l(0.000000)
sample_l_indexable(texture2d)(float,float,float,float) r0.w, r0.xyxx, t4.xzwy, s0, l(0.000000)
min r0.w, |r0.w|, cb1[2].z
sample_l_indexable(texture2d)(float,float,float,float) r1.x, r0.xyxx, t5.xyzw, s1, l(0.000000)
add r0.w, -r0.z, r0.w
mad r0.z, r1.x, r0.w, r0.z
div r0.z, r0.z, cb1[0].w
mul_sat r0.z, r0.z, l(0.500000)
ftoi r1.xy, v0.xyxx
mov r1.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r1.xyz, r1.xyzw, t2.xyzw
lt r0.w, l(0.000000), r0.z
if_nz r0.w
  sample_l_indexable(texture2d)(float,float,float,float) r2.xyz, r0.xyxx, t1.xyzw, s1, l(0.000000)
  add r2.xyz, -r1.xyzx, r2.xyzx
  mad r1.xyz, r0.zzzz, r2.xyzx, r1.xyzx
endif
sample_l_indexable(texture2d)(float,float,float,float) r0.xyzw, r0.xyxx, t3.xyzw, s0, l(0.000000)
mad o0.xyz, r1.xyzx, r0.wwww, r0.xyzx
mov o0.w, l(0)
ret
// Approximately 23 instruction slots used

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