57 if (uint(inst_id) >= srt.dof_buf.scatter_max_rect) {
59 out_position =
float4(0.0f);
63 ScatterRect rect = srt.scatter_list_buf[inst_id];
65 v_out.color_and_coc1 = rect.color_and_coc[0];
66 v_out.color_and_coc2 = rect.color_and_coc[1];
67 v_out.color_and_coc3 = rect.color_and_coc[2];
68 v_out.color_and_coc4 = rect.color_and_coc[3];
70 float2 uv =
float2(vert_id & 1, vert_id >> 1) * 2.0f - 1.0f;
71 uv = uv * rect.half_extent;
73 out_position =
float4(uv + rect.offset, 0.0f, 1.0f);
75 out_position.xy = (out_position.xy /
float2(
textureSize(srt.occlusion_tx, 0).xy)) * 2.0f - 1.0f;
77 if (srt.use_bokeh_lut) {
79 v_out.distance_scale = (
float(DOF_BOKEH_LUT_SIZE) /
float(DOF_BOKEH_LUT_SIZE - 1));
80 float2 uv_div = 1.0f / (v_out.distance_scale *
abs(rect.half_extent));
81 v_out.rect_uv1 = ((uv +
quad_offsets[0]) * uv_div) * 0.5f + 0.5f;
82 v_out.rect_uv2 = ((uv +
quad_offsets[1]) * uv_div) * 0.5f + 0.5f;
83 v_out.rect_uv3 = ((uv +
quad_offsets[2]) * uv_div) * 0.5f + 0.5f;
84 v_out.rect_uv4 = ((uv +
quad_offsets[3]) * uv_div) * 0.5f + 0.5f;
89 v_out.distance_scale = 1.0f;
108 v_out.color_and_coc2.w,
109 v_out.color_and_coc3.w,
110 v_out.color_and_coc4.w);
112 if (srt.use_bokeh_lut) {
114 texture(srt.bokeh_lut_tx, v_out.rect_uv2).r,
115 texture(srt.bokeh_lut_tx, v_out.rect_uv3).r,
116 texture(srt.bokeh_lut_tx, v_out.rect_uv4).r);
124 shapes *= v_out.distance_scale;
140 constexpr float correction_fac = 1.0f - DOF_FAST_GATHER_COC_ERROR;
142 float mean = occlusion_data.
x;
143 float variance = occlusion_data.
y;
144 shapes *= variance *
safe_rcp(variance +
square(
max(coc4 * correction_fac - mean, 0.0f)));
147 frag_out.color = (v_out.color_and_coc1 * shapes[0] + v_out.color_and_coc2 * shapes[1] +
148 v_out.color_and_coc3 * shapes[2] + v_out.color_and_coc4 * shapes[3]);
150 frag_out.color.a = 0.0f;
153 frag_out.color.rgb =
average(frag_out.color.rgb) *
float3(1.0f, 0.0f, 0.0f);