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