Blender V5.3
eevee_lightprobe_volume.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
12
14
15#include "eevee_lightprobe.hh"
16
17namespace blender::eevee {
18
19using math::AxisSigned;
20using math::CartesianBasis;
21
22class Instance;
23class CapturePipeline;
24class ShadowModule;
25class Camera;
27
33
38 friend CapturePipeline;
39 friend ShadowModule;
40 friend Camera;
41
42 private:
43 Instance &inst_;
44
46 LightCache *light_cache_ = nullptr;
48 SurfelBuf surfels_buf_;
50 CaptureInfoBuf capture_info_buf_;
52 Framebuffer empty_raster_fb_ = {"empty_raster_fb_"};
54 PassSimple surfel_light_eval_ps_ = {"LightEval"};
56 PassSimple surfel_ray_build_ps_ = {"RayBuild"};
58 PassSimple surfel_cluster_build_ps_ = {"RayBuild"};
60 PassSimple surfel_light_propagate_ps_ = {"LightPropagate"};
62 PassSimple irradiance_capture_ps_ = {"IrradianceCapture"};
64 PassSimple irradiance_offset_ps_ = {"IrradianceOffset"};
66 PassSimple irradiance_bounds_ps_ = {"IrradianceBounds"};
68 int radiance_src_ = 0, radiance_dst_ = 1;
69
79 View view_x_ = {"BakingViewX"};
80 View view_y_ = {"BakingViewY"};
81 View view_z_ = {"BakingViewZ"};
83 int3 grid_pixel_extent_ = int3(0);
85 SurfelListInfoBuf list_info_buf_ = {"list_info_buf_"};
87 StorageArrayBuffer<int, 16, true> list_start_buf_ = {"list_start_buf_"};
89 StorageArrayBuffer<int, 16, true> list_counter_buf_ = {"list_counter_buf_"};
91 StorageArrayBuffer<int, 16, true> list_range_buf_ = {"list_range_buf_"};
93 StorageArrayBuffer<float, 16, true> list_item_distance_buf_ = {"list_item_distance_buf_"};
94 StorageArrayBuffer<int, 16, true> list_item_surfel_id_buf_ = {"list_item_surfel_id_buf_"};
96 StorageArrayBuffer<int, 16, true> sorted_surfel_id_buf_ = {"sorted_surfel_id_buf_"};
97
98 /* Dispatch size for per surfel workload. */
99 int3 dispatch_per_surfel_ = int3(1);
100 /* Dispatch size for per surfel list workload. */
101 int3 dispatch_per_list_ = int3(1);
102 /* Dispatch size for per grid sample workload. */
103 int3 dispatch_per_grid_sample_ = int3(1);
104
106 View ray_view_ = {"RayProjectionView"};
107
109 Texture irradiance_L0_tx_ = {"irradiance_L0_tx_"};
110 Texture irradiance_L1_a_tx_ = {"irradiance_L1_a_tx_"};
111 Texture irradiance_L1_b_tx_ = {"irradiance_L1_b_tx_"};
112 Texture irradiance_L1_c_tx_ = {"irradiance_L1_c_tx_"};
114 Texture virtual_offset_tx_ = {"virtual_offset_tx_"};
116 Texture cluster_list_tx_ = {"cluster_list_tx_"};
118 Texture validity_tx_ = {"validity_tx_"};
119
120 /* Bounding sphere of the scene being baked. In world space. */
121 float4 scene_bound_sphere_;
122 /* Surfel per unit distance in world space. */
123 float surfel_density_ = 1.0f;
129 float min_distance_to_surface_ = 0.05f;
135 float max_virtual_offset_ = 0.1f;
139 float clip_distance_;
140
142 bool capture_world_ = false;
144 bool capture_indirect_ = false;
146 bool capture_emission_ = false;
147
149 bool do_break_ = false;
150
151 public:
152 IrradianceBake(Instance &inst) : inst_(inst) {};
153
154 void init(const Object &probe_object);
155 void sync();
156
159 {
160 return do_break_;
161 }
162
164 void surfel_raster_views_sync(const float3 &scene_min,
165 const float3 &scene_max,
166 const float4x4 &probe_to_world);
168 void surfels_create(const Object &probe_object);
170 void surfels_lights_eval();
176 void clusters_build();
182 void raylists_build();
184 void propagate_light();
186 void irradiance_offset();
188 void irradiance_capture();
189
194
195 private:
197 void read_surfels(LightProbeGridCacheFrame *cache_frame);
199 void read_virtual_offset(LightProbeGridCacheFrame *cache_frame);
200};
201
207 public:
209
210 private:
211 Instance &inst_;
212
214 Texture irradiance_atlas_tx_ = {"irradiance_atlas_tx_"};
216 int world_brick_index_ = 0;
218 VolumeProbeDataBuf grids_infos_buf_ = {"grids_infos_buf_"};
219 IrradianceBrickBuf bricks_infos_buf_ = {"bricks_infos_buf_"};
221 Vector<IrradianceBrickPacked> brick_pool_;
223 PassSimple grid_upload_ps_ = {"VolumeProbeModule.Upload"};
225 bool do_full_update_ = true;
230 uint irradiance_pool_size_ = 0;
232 uint irradiance_pool_size_alloc_ = 0;
233
235 PassSimple debug_ps_ = {"VolumeProbeModule.Debug"};
237 draw::StorageArrayBuffer<Surfel> debug_surfels_buf_;
238
240 bool display_grids_enabled_ = false;
241 PassSimple display_grids_ps_ = {"VolumeProbeModule.Display Grids"};
242
244 bool do_update_world_ = true;
245
246 public:
247 VolumeProbeModule(Instance &inst) : bake(inst), inst_(inst) {};
249
250 void init();
251 void sync();
252
253 /* Tag all grids for reupload in set_view and composite them with the world irradiance. */
255 {
256 do_update_world_ = true;
257 }
258
259 void set_view(View &view);
260 void viewport_draw(View &view, gpu::FrameBuffer *view_fb);
261
264
265 template<typename PassType> void bind_resources(PassType &pass)
266 {
267 pass.bind_ubo(IRRADIANCE_GRID_BUF_SLOT, &grids_infos_buf_);
268 pass.bind_ssbo(IRRADIANCE_BRICK_BUF_SLOT, &bricks_infos_buf_);
269 pass.bind_texture(VOLUME_PROBE_TEX_SLOT, &irradiance_atlas_tx_);
270 }
271
272 private:
273 void debug_pass_draw(View &view, gpu::FrameBuffer *view_fb);
274 void display_pass_draw(View &view, gpu::FrameBuffer *view_fb);
275
276 friend class SphereProbeModule;
277};
278
279} // namespace blender::eevee
A running instance of the engine.
LightProbeGridCacheFrame * read_result_packed()
LightProbeGridCacheFrame * read_result_unpacked()
void surfels_create(const Object &probe_object)
void surfel_raster_views_sync(const float3 &scene_min, const float3 &scene_max, const float4x4 &probe_to_world)
Vector< IrradianceBrickPacked > bricks_alloc(int brick_len)
void bricks_free(Vector< IrradianceBrickPacked > &bricks)
void viewport_draw(View &view, gpu::FrameBuffer *view_fb)
#define IRRADIANCE_GRID_BUF_SLOT
#define VOLUME_PROBE_TEX_SLOT
#define IRRADIANCE_BRICK_BUF_SLOT
PassType
detail::Pass< command::DrawCommandBuf > PassSimple
draw::StorageBuffer< SurfelListInfoData > SurfelListInfoBuf
draw::StorageArrayBuffer< Surfel, 64 > SurfelBuf
draw::UniformArrayBuffer< VolumeProbeData, IRRADIANCE_GRID_MAX > VolumeProbeDataBuf
draw::StorageBuffer< CaptureInfoData > CaptureInfoBuf
draw::StorageVectorBuffer< IrradianceBrickPacked, 16 > IrradianceBrickBuf
unsigned int uint
Definition BKE_text.h:55
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< int32_t, 3 > int3
VecBase< float, 3 > float3