Blender V4.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
9#pragma once
10
11#include "eevee_lightprobe.hh"
13
14#include "BKE_cryptomatte.hh"
15
16extern "C" {
17}
18
19namespace blender::eevee {
20
21class Instance;
22class CaptureView;
23
24/* -------------------------------------------------------------------- */
29 friend LightProbeModule;
30 /* Capture View requires access to the probe texture for frame-buffer configuration. */
31 friend class CaptureView;
32 /* Instance requires access to #update_probes_this_sample_ */
33 friend class Instance;
34
35 private:
36 Instance &instance_;
37 SphereProbeDataBuf data_buf_;
38
40 Texture probes_tx_ = {"Probes"};
41
43 PassSimple remap_ps_ = {"Probe.CubemapToOctahedral"};
45 PassSimple sum_sh_ps_ = {"Probe.SumSphericalHarmonics"};
47 PassSimple sum_sun_ps_ = {"Probe.SumSunlight"};
49 PassSimple select_ps_ = {"Probe.Select"};
51 PassSimple convolve_ps_ = {"Probe.Convolve"};
53 GPUTexture *convolve_input_ = nullptr;
55 GPUTexture *convolve_output_ = nullptr;
56 int convolve_lod_ = 0;
57 /* True if we extract spherical harmonic during `remap_ps_`. */
58 bool extract_sh_ = false;
59
60 int3 dispatch_probe_pack_ = int3(1);
61 int3 dispatch_probe_convolve_ = int3(1);
62 int3 dispatch_probe_select_ = int3(1);
63
69 Texture cubemap_tx_ = {"Probe.Cubemap"};
71 int probe_index_ = 0;
73 SphereProbeUvArea probe_sampling_coord_;
74 SphereProbePixelArea probe_write_coord_;
76 SphereProbePixelArea probe_read_coord_;
78 SphereProbeUvArea world_sampling_coord_;
80 int lightprobe_sphere_count_ = 0;
81
83 StorageArrayBuffer<SphereProbeHarmonic, SPHERE_PROBE_MAX_HARMONIC, true>
84 tmp_spherical_harmonics_ = {"tmp_spherical_harmonics_"};
86 StorageBuffer<SphereProbeHarmonic, true> spherical_harmonics_ = {"spherical_harmonics_"};
87
89 StorageArrayBuffer<SphereProbeSunLight, SPHERE_PROBE_MAX_HARMONIC, true> tmp_sunlight_ = {
90 "tmp_sunlight_"};
91
99 bool update_probes_next_sample_ = false;
101 bool update_probes_this_sample_ = false;
103 bool do_world_irradiance_update = true;
104
106 bool do_display_draw_ = false;
107 SphereProbeDisplayDataBuf display_data_buf_;
108 PassSimple viewport_display_ps_ = {"ProbeSphereModule.Viewport Display"};
109
110 public:
111 SphereProbeModule(Instance &instance) : instance_(instance){};
112
113 void init();
114 void begin_sync();
115 void end_sync();
116
117 void viewport_draw(View &view, GPUFrameBuffer *view_fb);
118
119 template<typename PassType> void bind_resources(PassType &pass)
120 {
121 pass.bind_texture(SPHERE_PROBE_TEX_SLOT, &probes_tx_);
122 pass.bind_ubo(SPHERE_PROBE_BUF_SLOT, &data_buf_);
123 }
124
129 void set_view(View &view);
130
136 int probe_render_extent() const;
137
139 {
140 return spherical_harmonics_;
141 }
142
143 private:
144 /* Return the subdivision level for the requested probe resolution.
145 * Result is safely clamped to max resolution. */
146 int subdivision_level_get(const eLightProbeResolution probe_resolution)
147 {
148 return max_ii(SPHERE_PROBE_ATLAS_MAX_SUBDIV - int(probe_resolution), 0);
149 }
150
155 bool ensure_atlas();
156
160 void ensure_cubemap_render_target(int resolution);
161
162 struct UpdateInfo {
163 float3 probe_pos;
165 int cube_target_extent;
166
167 float2 clipping_distances;
168
169 SphereProbeAtlasCoord atlas_coord;
170
171 bool do_render;
172 };
173
174 UpdateInfo update_info_from_probe(SphereProbe &probe);
175
179 std::optional<UpdateInfo> world_update_info_pop();
180 std::optional<UpdateInfo> probe_update_info_pop();
181
188 void remap_to_octahedral_projection(const SphereProbeAtlasCoord &atlas_coord,
189 bool extract_spherical_harmonics);
190
191 void sync_display(Vector<SphereProbe *> &probe_active);
192};
193
196} // namespace blender::eevee
MINLINE int max_ii(int a, int b)
eLightProbeResolution
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
VecBase< int32_t, 3 > int3