Blender V5.3
eevee_depth_of_field_bokeh_lut.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
12#pragma once
13
17
19
20struct Resources {
21 [[uniform(0)]] const DepthOfFieldData &dof_buf;
22
26};
27
28[[compute, local_size(DOF_BOKEH_LUT_SIZE, DOF_BOKEH_LUT_SIZE)]]
29void comp_main([[resource_table]] Resources &srt, [[global_invocation_id]] const uint3 global_id)
30{
31 float2 gather_uv = ((float2(global_id.xy) + 0.5f) / float(DOF_BOKEH_LUT_SIZE));
32 /* Center uv in range [-1..1]. */
33 gather_uv = gather_uv * 2.0f - 1.0f;
34
35 float2 slight_focus_texel = float2(global_id.xy) - float(dof_max_slight_focus_radius);
36
37 float radius = length(gather_uv);
38
39 if (srt.dof_buf.bokeh_blades > 0.0f) {
40 /* NOTE: atan(y,x) has output range [-M_PI..M_PI], so add 2pi to avoid negative angles. */
41 float theta = atan(gather_uv.y, gather_uv.x) + M_TAU;
42
43 radius /= circle_to_polygon_radius(srt.dof_buf.bokeh_blades,
44 theta - srt.dof_buf.bokeh_rotation);
45
46 float theta_new = circle_to_polygon_angle(srt.dof_buf.bokeh_blades, theta);
47 float r_new = circle_to_polygon_radius(srt.dof_buf.bokeh_blades, theta_new);
48
49 theta_new -= srt.dof_buf.bokeh_rotation;
50
51 gather_uv = r_new * float2(-cos(theta_new), sin(theta_new));
52
53 {
54 /* Slight focus distance */
55 slight_focus_texel *= srt.dof_buf.bokeh_anisotropic_scale_inv;
56 /* Note that `atan(y,x)` is unused for `x = 0` or `y = 0`. */
57 float theta = atan(slight_focus_texel.y + 1e-8f, -slight_focus_texel.x + 1e-8f) + M_TAU;
58 slight_focus_texel /= circle_to_polygon_radius(srt.dof_buf.bokeh_blades,
59 theta + srt.dof_buf.bokeh_rotation);
60 }
61 }
62 else {
63 gather_uv *= safe_rcp(length(gather_uv));
64 }
65
66 int2 texel = int2(global_id.xy);
67 /* For gather store the normalized UV. */
68 imageStoreFast(srt.out_gather_lut_img, texel, gather_uv.xyxy);
69 /* For scatter store distance. LUT will be scaled by COC. */
70 imageStoreFast(srt.out_scatter_lut_img, texel, float4(radius));
71 /* For slight focus gather store pixel perfect distance. */
72 imageStore(srt.out_resolve_lut_img, texel, float4(length(slight_focus_texel)));
73}
74
75} // namespace eevee::dof::bokeh_lut
76
#define M_TAU
PipelineCompute eevee_depth_of_field_bokeh_lut(eevee::dof::bokeh_lut::comp_main)
#define dof_max_slight_focus_radius
#define uniform(slot)
#define image(slot, qualifiers, format)
#define resource_table
#define global_invocation_id
#define compute
#define local_size(...)
#define atan
#define sin
#define cos
float length(VecOp< float, D >) RET
ImageBase< float, 2 > image2D
#define imageStoreFast
IMG_TEMPLATE void imageStore(T &, IntCoord, DataVec)
float safe_rcp(float a)
void comp_main(Resources &srt, const uint3 global_id)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
float x
float y