Blender V5.0
eevee_lightprobe_sphere.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "DNA_world_types.h"
12
13#include "draw_pass.hh"
14
15#include "eevee_lightprobe.hh"
17
18namespace blender::eevee {
19
20using namespace draw;
21
22class Instance;
23class CaptureView;
24
25/* -------------------------------------------------------------------- */
28
31
33 friend LightProbeModule;
34 /* Capture View requires access to the probe texture for frame-buffer configuration. */
35 friend class CaptureView;
36 /* Instance requires access to #update_probes_this_sample_ */
37 friend class Instance;
38
39 private:
40 Instance &instance_;
41 SphereProbeDataBuf data_buf_;
42
44 Texture probes_tx_ = {"Probes"};
45
47 PassSimple remap_ps_ = {"Probe.CubemapToOctahedral"};
49 PassSimple sum_sh_ps_ = {"Probe.SumSphericalHarmonics"};
51 PassSimple sum_sun_ps_ = {"Probe.SumSunlight"};
53 PassSimple select_ps_ = {"Probe.Select"};
55 PassSimple convolve_ps_ = {"Probe.Convolve"};
57 gpu::Texture *convolve_input_ = nullptr;
59 gpu::Texture *convolve_output_ = nullptr;
60 int convolve_lod_ = 0;
61 /* True if we extract spherical harmonic during `remap_ps_`. */
62 bool extract_sh_ = false;
63
64 int3 dispatch_probe_pack_ = int3(1);
65 int3 dispatch_probe_convolve_ = int3(1);
66 int3 dispatch_probe_select_ = int3(1);
67
73 Texture cubemap_tx_ = {"Probe.Cubemap"};
75 int probe_index_ = 0;
77 SphereProbeUvArea probe_sampling_coord_;
78 SphereProbePixelArea probe_write_coord_;
80 SphereProbePixelArea probe_read_coord_;
82 SphereProbeUvArea world_sampling_coord_;
84 int lightprobe_sphere_count_ = 0;
85
87 StorageArrayBuffer<SphereProbeHarmonic, SPHERE_PROBE_MAX_HARMONIC, true>
88 tmp_spherical_harmonics_ = {"tmp_spherical_harmonics_"};
90 StorageBuffer<SphereProbeHarmonic, true> spherical_harmonics_ = {"spherical_harmonics_"};
91
93 StorageArrayBuffer<SphereProbeSunLight, SPHERE_PROBE_MAX_HARMONIC, true> tmp_sunlight_ = {
94 "tmp_sunlight_"};
95
103 bool update_probes_next_sample_ = false;
105 bool update_probes_this_sample_ = false;
107 bool do_world_irradiance_update = true;
108
110 bool do_display_draw_ = false;
111 SphereProbeDisplayDataBuf display_data_buf_;
112 PassSimple viewport_display_ps_ = {"ProbeSphereModule.Viewport Display"};
113
114 public:
115 SphereProbeModule(Instance &instance) : instance_(instance) {};
116
117 void init();
118 void begin_sync();
119 void end_sync();
120
121 void viewport_draw(View &view, gpu::FrameBuffer *view_fb);
122
123 template<typename PassType> void bind_resources(PassType &pass)
124 {
125 pass.bind_texture(SPHERE_PROBE_TEX_SLOT, &probes_tx_);
126 pass.bind_ubo(SPHERE_PROBE_BUF_SLOT, &data_buf_);
127 }
128
133 void set_view(View &view);
134
140 int probe_render_extent() const;
141
143 {
144 return spherical_harmonics_;
145 }
146
147 private:
148 /* Return the subdivision level for the requested probe resolution.
149 * Result is safely clamped to max resolution. */
150 int subdivision_level_get(const eLightProbeResolution probe_resolution)
151 {
152 return max_ii(SPHERE_PROBE_ATLAS_MAX_SUBDIV - int(probe_resolution), 0);
153 }
154
159 bool ensure_atlas();
160
164 void ensure_cubemap_render_target(int resolution);
165
166 struct UpdateInfo {
167 float3 probe_pos;
169 int cube_target_extent;
170
171 float2 clipping_distances;
172
173 SphereProbeAtlasCoord atlas_coord;
174
175 bool do_render;
176 };
177
178 UpdateInfo update_info_from_probe(SphereProbe &probe);
179
183 std::optional<UpdateInfo> world_update_info_pop();
184 std::optional<UpdateInfo> probe_update_info_pop();
185
192 void remap_to_octahedral_projection(const SphereProbeAtlasCoord &atlas_coord,
193 bool extract_spherical_harmonics);
194
195 void sync_display(Vector<SphereProbe *> &probe_active);
196};
197
199
200} // namespace blender::eevee
MINLINE int max_ii(int a, int b)
eLightProbeResolution
static AppView * view
A running instance of the engine.
StorageBuffer< SphereProbeHarmonic, true > & spherical_harmonics_buf()
void viewport_draw(View &view, gpu::FrameBuffer *view_fb)
#define SPHERE_PROBE_ATLAS_MAX_SUBDIV
#define SPHERE_PROBE_TEX_SLOT
#define SPHERE_PROBE_BUF_SLOT
PassType
detail::Pass< command::DrawCommandBuf > PassSimple
draw::StorageArrayBuffer< SphereProbeDisplayData > SphereProbeDisplayDataBuf
draw::UniformArrayBuffer< SphereProbeData, SPHERE_PROBE_MAX > SphereProbeDataBuf
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
VecBase< float, 3 > float3