Blender V5.0
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 const ViewLayerEEVEE &view_layer_eevee = inst_.view_layer->eevee;
41
42 data_.distance = view_layer_eevee.ambient_occlusion_distance;
43 data_.gi_distance = (sce_eevee.fast_gi_distance > 0.0f) ? sce_eevee.fast_gi_distance : 1e16f;
44 /* AO node uses its own number of samples. */
45 data_.lod_factor_ao = 1.0f / (1.0f + sce_eevee.fast_gi_quality * 4.0f);
46 data_.lod_factor = (4.0f / sce_eevee.fast_gi_step_count) /
47 (1.0f + sce_eevee.fast_gi_quality * 4.0f);
48 data_.angle_bias = 1.0 / max_ff(1e-8f, 1.0 - sce_eevee.fast_gi_bias);
49 data_.thickness_near = sce_eevee.fast_gi_thickness_near;
50 data_.thickness_far = sce_eevee.fast_gi_thickness_far;
51 /* Size is multiplied by 2 because it is applied in NDC [-1..1] range. */
52 data_.pixel_size = float2(2.0f) / float2(inst_.film.render_extent_get());
53
54 ray_count_ = sce_eevee.fast_gi_ray_count;
55 step_count_ = sce_eevee.fast_gi_step_count;
56}
57
59{
60 if (!render_pass_enabled_) {
61 return;
62 }
63
64 render_pass_ps_.init();
65 gpu::Shader *sh = inst_.shaders.static_shader_get(AMBIENT_OCCLUSION_PASS);
66 render_pass_ps_.specialize_constant(sh, "ao_slice_count", ray_count_);
67 render_pass_ps_.specialize_constant(sh, "ao_step_count", step_count_);
68 render_pass_ps_.shader_set(sh);
69
70 render_pass_ps_.bind_texture(RBUFS_UTILITY_TEX_SLOT, &inst_.pipelines.utility_tx);
71 render_pass_ps_.bind_resources(inst_.uniform_data);
72 render_pass_ps_.bind_resources(inst_.sampling);
73 render_pass_ps_.bind_resources(inst_.hiz_buffer.front);
74
75 render_pass_ps_.bind_image("in_normal_img", &inst_.render_buffers.rp_color_tx);
76 render_pass_ps_.push_constant("in_normal_img_layer_index", &inst_.render_buffers.data.normal_id);
77 render_pass_ps_.bind_image("out_ao_img", &inst_.render_buffers.rp_value_tx);
78 render_pass_ps_.push_constant("out_ao_img_layer_index",
79 &inst_.render_buffers.data.ambient_occlusion_id);
80
82 render_pass_ps_.dispatch(
83 math::divide_ceil(inst_.film.render_extent_get(), int2(AMBIENT_OCCLUSION_PASS_TILE_SIZE)));
84}
85
87{
88 if (!render_pass_enabled_) {
89 return;
90 }
91
92 inst_.hiz_buffer.update();
93 inst_.manager->submit(render_pass_ps_, view);
94}
95
96} // namespace blender::eevee
MINLINE float max_ff(float a, float b)
@ EEVEE_RENDER_PASS_AO
static AppView * view
@ GPU_BARRIER_TEXTURE_FETCH
Definition GPU_state.hh:37
@ GPU_BARRIER_SHADER_IMAGE_ACCESS
Definition GPU_state.hh:35
#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
float fast_gi_thickness_near
float fast_gi_thickness_far
float ambient_occlusion_distance