Blender V5.0
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 blender::math::AxisSigned;
20using blender::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
78 View view_x_ = {"BakingViewX"};
79 View view_y_ = {"BakingViewY"};
80 View view_z_ = {"BakingViewZ"};
82 int3 grid_pixel_extent_ = int3(0);
84 SurfelListInfoBuf list_info_buf_ = {"list_info_buf_"};
86 StorageArrayBuffer<int, 16, true> list_start_buf_ = {"list_start_buf_"};
88 StorageArrayBuffer<int, 16, true> list_counter_buf_ = {"list_counter_buf_"};
90 StorageArrayBuffer<int, 16, true> list_range_buf_ = {"list_range_buf_"};
92 StorageArrayBuffer<float, 16, true> list_item_distance_buf_ = {"list_item_distance_buf_"};
93 StorageArrayBuffer<int, 16, true> list_item_surfel_id_buf_ = {"list_item_surfel_id_buf_"};
95 StorageArrayBuffer<int, 16, true> sorted_surfel_id_buf_ = {"sorted_surfel_id_buf_"};
96
97 /* Dispatch size for per surfel workload. */
98 int3 dispatch_per_surfel_ = int3(1);
99 /* Dispatch size for per surfel list workload. */
100 int3 dispatch_per_list_ = int3(1);
101 /* Dispatch size for per grid sample workload. */
102 int3 dispatch_per_grid_sample_ = int3(1);
103
105 View ray_view_ = {"RayProjectionView"};
106
108 Texture irradiance_L0_tx_ = {"irradiance_L0_tx_"};
109 Texture irradiance_L1_a_tx_ = {"irradiance_L1_a_tx_"};
110 Texture irradiance_L1_b_tx_ = {"irradiance_L1_b_tx_"};
111 Texture irradiance_L1_c_tx_ = {"irradiance_L1_c_tx_"};
113 Texture virtual_offset_tx_ = {"virtual_offset_tx_"};
115 Texture cluster_list_tx_ = {"cluster_list_tx_"};
117 Texture validity_tx_ = {"validity_tx_"};
118
119 /* Bounding sphere of the scene being baked. In world space. */
120 float4 scene_bound_sphere_;
121 /* Surfel per unit distance in world space. */
122 float surfel_density_ = 1.0f;
128 float min_distance_to_surface_ = 0.05f;
134 float max_virtual_offset_ = 0.1f;
138 float clip_distance_;
139
141 bool capture_world_ = false;
143 bool capture_indirect_ = false;
145 bool capture_emission_ = false;
146
148 bool do_break_ = false;
149
150 public:
151 IrradianceBake(Instance &inst) : inst_(inst) {};
152
153 void init(const Object &probe_object);
154 void sync();
155
158 {
159 return do_break_;
160 }
161
163 void surfel_raster_views_sync(const float3 &scene_min,
164 const float3 &scene_max,
165 const float4x4 &probe_to_world);
167 void surfels_create(const Object &probe_object);
169 void surfels_lights_eval();
175 void clusters_build();
181 void raylists_build();
183 void propagate_light();
185 void irradiance_offset();
187 void irradiance_capture();
188
193
194 private:
196 void read_surfels(LightProbeGridCacheFrame *cache_frame);
198 void read_virtual_offset(LightProbeGridCacheFrame *cache_frame);
199};
200
206 public:
208
209 private:
210 Instance &inst_;
211
213 Texture irradiance_atlas_tx_ = {"irradiance_atlas_tx_"};
215 int world_brick_index_ = 0;
217 VolumeProbeDataBuf grids_infos_buf_ = {"grids_infos_buf_"};
218 IrradianceBrickBuf bricks_infos_buf_ = {"bricks_infos_buf_"};
222 PassSimple grid_upload_ps_ = {"VolumeProbeModule.Upload"};
224 bool do_full_update_ = true;
228 uint irradiance_pool_size_ = 0;
230 uint irradiance_pool_size_alloc_ = 0;
231
233 PassSimple debug_ps_ = {"VolumeProbeModule.Debug"};
235 draw::StorageArrayBuffer<Surfel> debug_surfels_buf_;
236
238 bool display_grids_enabled_ = false;
239 PassSimple display_grids_ps_ = {"VolumeProbeModule.Display Grids"};
240
242 bool do_update_world_ = true;
243
244 public:
245 VolumeProbeModule(Instance &inst) : bake(inst), inst_(inst) {};
247
248 void init();
249 void sync();
250
251 /* Tag all grids for reupload in set_view and composite them with the world irradiance. */
253 {
254 do_update_world_ = true;
255 }
256
257 void set_view(View &view);
258 void viewport_draw(View &view, gpu::FrameBuffer *view_fb);
259
262
263 template<typename PassType> void bind_resources(PassType &pass)
264 {
265 pass.bind_ubo(IRRADIANCE_GRID_BUF_SLOT, &grids_infos_buf_);
266 pass.bind_ssbo(IRRADIANCE_BRICK_BUF_SLOT, &bricks_infos_buf_);
267 pass.bind_texture(VOLUME_PROBE_TEX_SLOT, &irradiance_atlas_tx_);
268 }
269
270 private:
271 void debug_pass_draw(View &view, gpu::FrameBuffer *view_fb);
272 void display_pass_draw(View &view, gpu::FrameBuffer *view_fb);
273
274 friend class SphereProbeModule;
275};
276
277} // namespace blender::eevee
unsigned int uint
static AppView * view
void init()
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
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< int32_t, 3 > int3
VecBase< float, 3 > float3