Blender V5.3
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;
24class LookdevModule;
25
26/* -------------------------------------------------------------------- */
29
32
34 friend LightProbeModule;
35 /* Capture View requires access to the probe texture for frame-buffer configuration. */
36 friend class CaptureView;
37 /* Instance requires access to #update_probes_this_sample_ */
38 friend class Instance;
39
40 private:
41 Instance &instance_;
42 SphereProbeDataBuf data_buf_;
43
45 Texture probes_tx_ = {"Probes"};
46
48 PassSimple remap_ps_ = {"Probe.CubemapToOctahedral"};
50 PassSimple sum_sh_ps_ = {"Probe.SumSphericalHarmonics"};
52 PassSimple sum_sun_ps_ = {"Probe.SumSunlight"};
54 PassSimple select_ps_ = {"Probe.Select"};
56 PassSimple convolve_ps_ = {"Probe.Convolve"};
58 gpu::Texture *convolve_input_ = nullptr;
60 gpu::Texture *convolve_output_ = nullptr;
61 int convolve_lod_ = 0;
62 /* True if we extract spherical harmonic during `remap_ps_`. */
63 bool extract_sh_ = false;
64 /* True if we extract sun during `remap_ps_`. */
65 bool extract_sun_ = false;
66 /* True if we actually remap the data during `remap_ps_`. */
67 bool32_t do_remap_mip0_ = false;
68
69 int3 dispatch_probe_pack_ = int3(1);
70 int3 dispatch_probe_convolve_ = int3(1);
71 int3 dispatch_probe_select_ = int3(1);
72
78 Texture cubemap_tx_ = {"Probe.Cubemap"};
80 int probe_index_ = 0;
82 SphereProbeUvArea probe_sampling_coord_;
83 SphereProbePixelArea probe_write_coord_;
85 SphereProbePixelArea probe_read_coord_;
87 SphereProbeUvArea world_sampling_coord_;
89 int lightprobe_sphere_count_ = 0;
90
92 StorageArrayBuffer<SphereProbeHarmonic, SPHERE_PROBE_MAX_HARMONIC, true>
93 tmp_spherical_harmonics_ = {"tmp_spherical_harmonics_"};
95 StorageBuffer<SphereProbeHarmonic, true> spherical_harmonics_ = {"spherical_harmonics_"};
96
98 StorageArrayBuffer<SphereProbeSunLight, SPHERE_PROBE_MAX_HARMONIC, true> tmp_sunlight_ = {
99 "tmp_sunlight_"};
101 int extract_sun_index_ = -1;
102
110 bool update_probes_next_sample_ = false;
112 bool update_probes_this_sample_ = false;
114 bool do_world_irradiance_update = true;
115
117 bool do_display_draw_ = false;
118 SphereProbeDisplayDataBuf display_data_buf_;
119 PassSimple viewport_display_ps_ = {"ProbeSphereModule.Viewport Display"};
120
121 public:
122 SphereProbeModule(Instance &instance) : instance_(instance) {};
123
124 void init();
125 void begin_sync();
126 void end_sync();
127
128 void viewport_draw(View &view, gpu::FrameBuffer *view_fb);
129
130 template<typename PassType> void bind_resources(PassType &pass)
131 {
132 pass.bind_texture(SPHERE_PROBE_TEX_SLOT, &probes_tx_);
133 pass.bind_ubo(SPHERE_PROBE_BUF_SLOT, &data_buf_);
134 }
135
140 void set_view(View &view);
141
147 int probe_render_extent() const;
148
150 {
151 return spherical_harmonics_;
152 }
153
154 const SphereProbe &world_sphere_probe() const;
155
157 {
158 return probes_tx_;
159 }
160
161 private:
162 /* Return the subdivision level for the requested probe resolution.
163 * Result is safely clamped to max resolution. */
164 int subdivision_level_get(const eLightProbeResolution probe_resolution)
165 {
166 return max_ii(SPHERE_PROBE_ATLAS_MAX_SUBDIV - int(probe_resolution), 0);
167 }
168
173 bool ensure_atlas();
174
178 void ensure_cubemap_render_target(int resolution);
182 void release_render_target();
183
184 struct UpdateInfo {
185 float3 probe_pos;
187 int cube_target_extent;
188
189 float2 clipping_distances;
190
191 SphereProbeAtlasCoord atlas_coord;
192
193 bool do_render;
194 };
195
196 UpdateInfo update_info_from_probe(SphereProbe &probe);
197
201 std::optional<UpdateInfo> world_update_info_pop();
202 std::optional<UpdateInfo> probe_update_info_pop();
203
218 void remap_to_octahedral_projection(const SphereProbeAtlasCoord &atlas_coord,
219 bool convolve_octahedral,
220 bool extract_spherical_harmonics,
221 int extract_sun = -1);
222
223 void sync_display(Vector<SphereProbe *> &probe_active);
224};
225
227
228} // namespace blender::eevee
int32_t bool32_t
A running instance of the engine.
StorageBuffer< SphereProbeHarmonic, true > & spherical_harmonics_buf()
const SphereProbe & world_sphere_probe() const
void viewport_draw(View &view, gpu::FrameBuffer *view_fb)
#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
MINLINE int max_ii(int a, int b)
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
VecBase< float, 3 > float3