Blender V4.5
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 "eevee_lightprobe.hh"
15
16namespace blender::eevee {
17
18class Instance;
19class CaptureView;
20
21/* -------------------------------------------------------------------- */
24
26 friend LightProbeModule;
27 /* Capture View requires access to the probe texture for frame-buffer configuration. */
28 friend class CaptureView;
29 /* Instance requires access to #update_probes_this_sample_ */
30 friend class Instance;
31
32 private:
33 Instance &instance_;
34 SphereProbeDataBuf data_buf_;
35
37 Texture probes_tx_ = {"Probes"};
38
40 PassSimple remap_ps_ = {"Probe.CubemapToOctahedral"};
42 PassSimple sum_sh_ps_ = {"Probe.SumSphericalHarmonics"};
44 PassSimple sum_sun_ps_ = {"Probe.SumSunlight"};
46 PassSimple select_ps_ = {"Probe.Select"};
48 PassSimple convolve_ps_ = {"Probe.Convolve"};
50 GPUTexture *convolve_input_ = nullptr;
52 GPUTexture *convolve_output_ = nullptr;
53 int convolve_lod_ = 0;
54 /* True if we extract spherical harmonic during `remap_ps_`. */
55 bool extract_sh_ = false;
56
57 int3 dispatch_probe_pack_ = int3(1);
58 int3 dispatch_probe_convolve_ = int3(1);
59 int3 dispatch_probe_select_ = int3(1);
60
66 Texture cubemap_tx_ = {"Probe.Cubemap"};
68 int probe_index_ = 0;
70 SphereProbeUvArea probe_sampling_coord_;
71 SphereProbePixelArea probe_write_coord_;
73 SphereProbePixelArea probe_read_coord_;
75 SphereProbeUvArea world_sampling_coord_;
77 int lightprobe_sphere_count_ = 0;
78
80 StorageArrayBuffer<SphereProbeHarmonic, SPHERE_PROBE_MAX_HARMONIC, true>
81 tmp_spherical_harmonics_ = {"tmp_spherical_harmonics_"};
83 StorageBuffer<SphereProbeHarmonic, true> spherical_harmonics_ = {"spherical_harmonics_"};
84
86 StorageArrayBuffer<SphereProbeSunLight, SPHERE_PROBE_MAX_HARMONIC, true> tmp_sunlight_ = {
87 "tmp_sunlight_"};
88
96 bool update_probes_next_sample_ = false;
98 bool update_probes_this_sample_ = false;
100 bool do_world_irradiance_update = true;
101
103 bool do_display_draw_ = false;
104 SphereProbeDisplayDataBuf display_data_buf_;
105 PassSimple viewport_display_ps_ = {"ProbeSphereModule.Viewport Display"};
106
107 public:
108 SphereProbeModule(Instance &instance) : instance_(instance){};
109
110 void init();
111 void begin_sync();
112 void end_sync();
113
114 void viewport_draw(View &view, GPUFrameBuffer *view_fb);
115
116 template<typename PassType> void bind_resources(PassType &pass)
117 {
118 pass.bind_texture(SPHERE_PROBE_TEX_SLOT, &probes_tx_);
119 pass.bind_ubo(SPHERE_PROBE_BUF_SLOT, &data_buf_);
120 }
121
126 void set_view(View &view);
127
133 int probe_render_extent() const;
134
136 {
137 return spherical_harmonics_;
138 }
139
140 private:
141 /* Return the subdivision level for the requested probe resolution.
142 * Result is safely clamped to max resolution. */
143 int subdivision_level_get(const eLightProbeResolution probe_resolution)
144 {
145 return max_ii(SPHERE_PROBE_ATLAS_MAX_SUBDIV - int(probe_resolution), 0);
146 }
147
152 bool ensure_atlas();
153
157 void ensure_cubemap_render_target(int resolution);
158
159 struct UpdateInfo {
160 float3 probe_pos;
162 int cube_target_extent;
163
164 float2 clipping_distances;
165
166 SphereProbeAtlasCoord atlas_coord;
167
168 bool do_render;
169 };
170
171 UpdateInfo update_info_from_probe(SphereProbe &probe);
172
176 std::optional<UpdateInfo> world_update_info_pop();
177 std::optional<UpdateInfo> probe_update_info_pop();
178
185 void remap_to_octahedral_projection(const SphereProbeAtlasCoord &atlas_coord,
186 bool extract_spherical_harmonics);
187
188 void sync_display(Vector<SphereProbe *> &probe_active);
189};
190
192
193} // namespace blender::eevee
MINLINE int max_ii(int a, int b)
float[3] Vector
eLightProbeResolution
static AppView * view
A running instance of the engine.
StorageBuffer< SphereProbeHarmonic, true > & spherical_harmonics_buf()
void viewport_draw(View &view, GPUFrameBuffer *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