Blender V5.3
eevee_ambient_occlusion.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
25
27#include "eevee_instance.hh"
28
29namespace blender::eevee {
30
31/* -------------------------------------------------------------------- */
34
36{
37 render_pass_enabled_ = inst_.film.enabled_passes_get() & EEVEE_RENDER_PASS_AO;
38
39 const SceneEEVEE &sce_eevee = inst_.scene->eevee;
40
41 /* AO node uses its own number of samples. */
42 data_.lod_factor_ao = 1.0f / (1.0f + sce_eevee.fast_gi_quality * 4.0f);
43 /* Scale up to LOD 5 at the end of the ray. */
44 data_.lod_factor = (1.0f - sce_eevee.fast_gi_quality) * 0.2f;
45 data_.angle_bias = 1.0 / max_ff(1e-8f, 1.0 - sce_eevee.fast_gi_bias);
46 data_.thickness_near = sce_eevee.fast_gi_thickness_near;
47 /* Size is multiplied by 2 because it is applied in NDC [-1..1] range. */
48 data_.pixel_size = float2(2.0f) / float2(inst_.film.render_extent_get());
49
50 ray_count_ = sce_eevee.fast_gi_ray_count;
51 step_count_ = sce_eevee.fast_gi_step_count;
52
53 dummy_tx_.ensure_2d(gpu::TextureFormat::SFLOAT_16, int2(1), GPU_TEXTURE_USAGE_SHADER_READ);
54}
55
57{
58 const SceneEEVEE &sce_eevee = inst_.scene->eevee;
59 const ViewLayerEEVEE &view_layer_eevee = inst_.view_layer->eevee;
60 /* Needs camera to be synced first. */
61 float max_distance = inst_.camera.bound_radius() * 2.0f;
62
63 data_.distance = (view_layer_eevee.ambient_occlusion_distance > 0.0f) ?
64 view_layer_eevee.ambient_occlusion_distance :
65 max_distance;
66 data_.gi_distance = (sce_eevee.fast_gi_distance > 0.0f) ? sce_eevee.fast_gi_distance :
67 max_distance;
68 if (!render_pass_enabled_) {
69 return;
70 }
71
72 render_pass_ps_.init();
73 gpu::Shader *sh = inst_.shaders.static_shader_get(AMBIENT_OCCLUSION_PASS);
74 render_pass_ps_.specialize_constant(sh, "ao_slice_count", ray_count_);
75 render_pass_ps_.specialize_constant(sh, "ao_step_count", step_count_);
76 render_pass_ps_.shader_set(sh);
77
78 render_pass_ps_.bind_texture(RBUFS_UTILITY_TEX_SLOT, &inst_.pipelines.utility_tx);
79 render_pass_ps_.bind_resources(inst_.uniform_data);
80 render_pass_ps_.bind_resources(inst_.sampling);
81 render_pass_ps_.bind_resources(inst_.hiz_buffer.front);
82
83 render_pass_ps_.bind_texture("dummy_tx", &dummy_tx_);
84 render_pass_ps_.bind_image("in_normal_img", &inst_.render_buffers.rp_color_tx);
85 render_pass_ps_.push_constant("in_normal_img_layer_index", &inst_.render_buffers.data.normal_id);
86 render_pass_ps_.bind_image("out_ao_img", &inst_.render_buffers.rp_value_tx);
87 render_pass_ps_.push_constant("out_ao_img_layer_index",
88 &inst_.render_buffers.data.ambient_occlusion_id);
89
91 render_pass_ps_.dispatch(
92 math::divide_ceil(inst_.film.render_extent_get(), int2(AMBIENT_OCCLUSION_PASS_TILE_SIZE)));
93}
94
96{
97 if (!render_pass_enabled_) {
98 return;
99 }
100
101 inst_.hiz_buffer.update();
102 inst_.manager->submit(render_pass_ps_, view);
103}
104
106
107} // namespace blender::eevee
#define RBUFS_UTILITY_TEX_SLOT
#define AMBIENT_OCCLUSION_PASS_TILE_SIZE
VecBase< T, Size > divide_ceil(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_BARRIER_TEXTURE_FETCH
Definition GPU_state.hh:40
@ GPU_BARRIER_SHADER_IMAGE_ACCESS
Definition GPU_state.hh:38
@ EEVEE_RENDER_PASS_AO
MINLINE float max_ff(float a, float b)