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
27#include "eevee_instance.hh"
28
29#include "GPU_capabilities.hh"
30
31namespace blender::eevee {
32
33/* -------------------------------------------------------------------- */
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();
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
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",
81
83 render_pass_ps_.dispatch(
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
@ GPU_BARRIER_TEXTURE_FETCH
Definition GPU_state.hh:37
@ GPU_BARRIER_SHADER_IMAGE_ACCESS
Definition GPU_state.hh:35
struct GPUShader GPUShader
void submit(PassSimple &pass, View &view)
void bind_texture(const char *name, GPUTexture *texture, GPUSamplerState state=sampler_auto)
void bind_resources(U &resources)
Definition draw_pass.hh:426
void bind_image(const char *name, GPUTexture *image)
void specialize_constant(GPUShader *shader, const char *name, const float &data)
void dispatch(int group_len)
Definition draw_pass.hh:874
void barrier(eGPUBarrier type)
Definition draw_pass.hh:943
void push_constant(const char *name, const float &data)
void shader_set(GPUShader *shader)
Definition draw_pass.hh:971
int2 render_extent_get() const
eViewLayerEEVEEPassType enabled_passes_get() const
struct blender::eevee::HiZBuffer::@195 front
UniformDataModule uniform_data
GPUShader * static_shader_get(eShaderType shader_type)
#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< float, 2 > float2
float fast_gi_thickness_near
float fast_gi_thickness_far
struct SceneEEVEE eevee