19#ifndef DOF_SLIGHT_FOCUS_DENSITY
20# define DOF_SLIGHT_FOCUS_DENSITY 2
24#define debug_gather_perf false
25#define debug_scatter_perf false
26#define debug_resolve_perf false
28#define no_smooth_intersection false
29#define no_gather_occlusion false
30#define no_gather_mipmaps false
31#define no_gather_random false
32#define no_gather_filtering false
33#define no_scatter_occlusion false
34#define no_scatter_pass false
35#define no_foreground_pass false
36#define no_background_pass false
37#define no_slight_focus_pass false
38#define no_focus_pass false
39#define no_hole_fill_pass false
42#define dof_layer_threshold (4.0f)
44#define dof_layer_offset_fg (0.5f + 1.0f)
46#define dof_layer_offset (0.5f + 0.5f)
48#define dof_max_slight_focus_radius DOF_MAX_SLIGHT_FOCUS_RADIUS
63 float luma = (color.g * 2.0f) + (color.r + color.b);
65 constexpr float exposure = 1.0f;
66 return 1.0f / (luma * exposure + 4.0f);
72 float selected_coc = cocs.
x;
73 if (
abs(cocs.
y) >
abs(selected_coc)) {
74 selected_coc = cocs.
y;
76 if (
abs(cocs.
z) >
abs(selected_coc)) {
77 selected_coc = cocs.
z;
79 if (
abs(cocs.
w) >
abs(selected_coc)) {
80 selected_coc = cocs.
w;
90 constexpr float scale = 4.0f;
100 for (
int i = 0; i < 4; i++) {
108 DepthOfFieldData dof_data,
114 if (is_panoramic(dof_data.camera_type)) {
121 return coc_radius_from_camera_depth(dof_data, depth);
135 float(is_foreground ? (coc <= 0.5f) : (coc > -0.5f));
141 return saturate(((is_foreground) ? -coc : coc) - threshold);
158 constexpr float min_coc = 1.0f;
159 coc =
max(min_coc,
abs(coc));
160 return (
M_PI * min_coc * min_coc) / (
M_PI * coc * coc);
169 constexpr float min_coc = 1.0f;
171 return (
M_PI * min_coc * min_coc) / (
M_PI * coc * coc);
197 tile.fg_min_coc = 0.0f;
201 tile.bg_max_coc = 0.0f;
209 tile.fg_min_coc = -fg.
x;
210 tile.fg_max_coc = -fg.
y;
211 tile.fg_max_intersectable_coc = -fg.
z;
212 tile.bg_min_coc = bg.
x;
213 tile.bg_max_coc = bg.
y;
214 tile.bg_min_intersectable_coc = bg.
z;
220 out_fg.
x = -
tile.fg_min_coc;
221 out_fg.
y = -
tile.fg_max_coc;
222 out_fg.
z = -
tile.fg_max_intersectable_coc;
223 out_bg.
x =
tile.bg_min_coc;
224 out_bg.
y =
tile.bg_max_coc;
225 out_bg.
z =
tile.bg_min_intersectable_coc;
243 imageStore(tiles_fg_img, texel_out, out_fg.xyzz);
244 imageStore(tiles_bg_img, texel_out, out_bg.xyzz);
248 float min_absolute_coc,
249 const bool is_foreground,
250 const bool is_resolve)
253 (is_foreground) ? -min_absolute_coc : min_absolute_coc, is_foreground, is_resolve);
254 if (min_weight < 1.0f) {
262 return (max_absolute_coc - min_absolute_coc) < (DOF_FAST_GATHER_COC_ERROR * max_absolute_coc);
292 predict.
do_focus = !fg_fully_opaque;
322 if (sample_id < ring_distance) {
323 offset.
x = ring_distance;
324 offset.
y = sample_id;
326 else if (sample_id < ring_distance * 3) {
327 offset.
x = ring_distance - sample_id + ring_distance;
328 offset.
y = ring_distance;
331 offset.
x = -ring_distance;
332 offset.
y = ring_distance - sample_id + 3 * ring_distance;
void dof_coc_tile_store(image2D tiles_fg_img, image2D tiles_bg_img, int2 texel_out, CocTile tile_data)
#define dof_layer_offset_fg
void dof_coc_tile_pack(CocTile tile, float3 &out_fg, float3 &out_bg)
float dof_coc_select(float4 cocs)
float4 dof_bilateral_color_weights(float4 colors[4])
float dof_sample_weight(float coc)
bool dof_do_fast_gather(float max_absolute_coc, float min_absolute_coc, const bool is_foreground, const bool is_resolve)
CocTile dof_coc_tile_unpack(float3 fg, float3 bg)
CocTilePrediction dof_coc_tile_prediction_get(CocTile tile, const bool is_resolve)
#define dof_layer_threshold
float4 dof_bilateral_coc_weights(float4 cocs)
float dof_hdr_color_weight(float4 color)
const uint2 quad_offsets_u[4]
int2 dof_square_ring_sample_offset(int ring_distance, int sample_id)
float dof_layer_weight(float coc, const bool is_foreground, const bool is_resolve)
CocTile dof_coc_tile_load(image2D tiles_fg_img, image2D tiles_bg_img, int2 texel)
static constexpr float dof_tile_large_coc
const float2 quad_offsets[4]
CocTile dof_coc_tile_init()
float dof_coc_from_depth(const draw::View &views, DepthOfFieldData dof_data, float2 uv, float depth)
constexpr T clamp(T, U, U) RET
float length(VecOp< float, D >) RET
IMG_TEMPLATE DataVec imageLoad(const T &, IntCoord) RET
ImageBase< float, 2 > image2D
IMG_TEMPLATE SizeVec imageSize(const T &) RET
IMG_TEMPLATE void imageStore(T &, IntCoord, DataVec)
float3x3 scale(float3x3 mat, float2 scale)
const ccl_global KernelWorkTile * tile
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
float fg_max_intersectable_coc
float bg_min_intersectable_coc
float depth_screen_to_view(float ss_depth) const
float3 point_screen_to_view(float3 ssP) const