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