Blender V4.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
9#pragma once
10
12
14
15#include "eevee_lightprobe.hh"
17
18namespace blender::eevee {
19
22
23class Instance;
24class CapturePipeline;
25class ShadowModule;
26class Camera;
27class SphereProbeModule;
28
33 friend CapturePipeline;
34 friend ShadowModule;
35 friend Camera;
36
37 private:
38 Instance &inst_;
39
41 LightCache *light_cache_ = nullptr;
43 SurfelBuf surfels_buf_;
45 CaptureInfoBuf capture_info_buf_;
47 Framebuffer empty_raster_fb_ = {"empty_raster_fb_"};
49 PassSimple surfel_light_eval_ps_ = {"LightEval"};
51 PassSimple surfel_ray_build_ps_ = {"RayBuild"};
53 PassSimple surfel_cluster_build_ps_ = {"RayBuild"};
55 PassSimple surfel_light_propagate_ps_ = {"LightPropagate"};
57 PassSimple irradiance_capture_ps_ = {"IrradianceCapture"};
59 PassSimple irradiance_offset_ps_ = {"IrradianceOffset"};
61 PassSimple irradiance_bounds_ps_ = {"IrradianceBounds"};
63 int radiance_src_ = 0, radiance_dst_ = 1;
64
73 View view_x_ = {"BakingViewX"};
74 View view_y_ = {"BakingViewY"};
75 View view_z_ = {"BakingViewZ"};
77 int3 grid_pixel_extent_ = int3(0);
79 SurfelListInfoBuf list_info_buf_ = {"list_info_buf_"};
81 StorageArrayBuffer<int, 16, true> list_start_buf_ = {"list_start_buf_"};
82
83 /* Dispatch size for per surfel workload. */
84 int3 dispatch_per_surfel_ = int3(1);
85 /* Dispatch size for per surfel list workload. */
86 int3 dispatch_per_list_ = int3(1);
87 /* Dispatch size for per grid sample workload. */
88 int3 dispatch_per_grid_sample_ = int3(1);
89
91 View ray_view_ = {"RayProjectionView"};
92
94 Texture irradiance_L0_tx_ = {"irradiance_L0_tx_"};
95 Texture irradiance_L1_a_tx_ = {"irradiance_L1_a_tx_"};
96 Texture irradiance_L1_b_tx_ = {"irradiance_L1_b_tx_"};
97 Texture irradiance_L1_c_tx_ = {"irradiance_L1_c_tx_"};
99 Texture virtual_offset_tx_ = {"virtual_offset_tx_"};
101 Texture cluster_list_tx_ = {"cluster_list_tx_"};
103 Texture validity_tx_ = {"validity_tx_"};
104
105 /* Bounding sphere of the scene being baked. In world space. */
106 float4 scene_bound_sphere_;
107 /* Surfel per unit distance in world space. */
108 float surfel_density_ = 1.0f;
114 float min_distance_to_surface_ = 0.05f;
120 float max_virtual_offset_ = 0.1f;
124 float clip_distance_;
125
127 bool capture_world_ = false;
129 bool capture_indirect_ = false;
131 bool capture_emission_ = false;
132
134 bool do_break_ = false;
135
136 public:
137 IrradianceBake(Instance &inst) : inst_(inst){};
138
139 void init(const Object &probe_object);
140 void sync();
141
144 {
145 return do_break_;
146 }
147
149 void surfel_raster_views_sync(const float3 &scene_min,
150 const float3 &scene_max,
151 const float4x4 &probe_to_world);
153 void surfels_create(const Object &probe_object);
155 void surfels_lights_eval();
161 void clusters_build();
167 void raylists_build();
169 void propagate_light();
171 void irradiance_offset();
173 void irradiance_capture();
174
179
180 private:
182 void read_surfels(LightProbeGridCacheFrame *cache_frame);
184 void read_virtual_offset(LightProbeGridCacheFrame *cache_frame);
185};
186
192 public:
194
195 private:
196 Instance &inst_;
197
199 Texture irradiance_atlas_tx_ = {"irradiance_atlas_tx_"};
201 int world_brick_index_ = 0;
203 VolumeProbeDataBuf grids_infos_buf_ = {"grids_infos_buf_"};
204 IrradianceBrickBuf bricks_infos_buf_ = {"bricks_infos_buf_"};
206 Vector<IrradianceBrickPacked> brick_pool_;
208 PassSimple grid_upload_ps_ = {"VolumeProbeModule.Upload"};
210 bool do_full_update_ = true;
214 uint irradiance_pool_size_ = 0;
216 uint irradiance_pool_size_alloc_ = 0;
217
219 PassSimple debug_ps_ = {"VolumeProbeModule.Debug"};
221 draw::StorageArrayBuffer<Surfel> debug_surfels_buf_;
222
224 bool display_grids_enabled_ = false;
225 PassSimple display_grids_ps_ = {"VolumeProbeModule.Display Grids"};
226
228 bool do_update_world_ = true;
229
230 public:
231 VolumeProbeModule(Instance &inst) : bake(inst), inst_(inst){};
233
234 void init();
235 void sync();
236
237 /* Tag all grids for reupload in set_view and composite them with the world irradiance. */
239 {
240 do_update_world_ = true;
241 }
242
243 void set_view(View &view);
244 void viewport_draw(View &view, GPUFrameBuffer *view_fb);
245
248
249 template<typename PassType> void bind_resources(PassType &pass)
250 {
251 pass.bind_ubo(IRRADIANCE_GRID_BUF_SLOT, &grids_infos_buf_);
252 pass.bind_ssbo(IRRADIANCE_BRICK_BUF_SLOT, &bricks_infos_buf_);
253 pass.bind_texture(VOLUME_PROBE_TEX_SLOT, &irradiance_atlas_tx_);
254 }
255
256 private:
257 void debug_pass_draw(View &view, GPUFrameBuffer *view_fb);
258 void display_pass_draw(View &view, GPUFrameBuffer *view_fb);
259
260 friend class SphereProbeModule;
261};
262
263} // namespace blender::eevee
unsigned int uint
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, GPUFrameBuffer *view_fb)
#define IRRADIANCE_GRID_BUF_SLOT
#define VOLUME_PROBE_TEX_SLOT
#define IRRADIANCE_BRICK_BUF_SLOT
PassType
detail::Pass< command::DrawCommandBuf > PassSimple
draw::StorageVectorBuffer< IrradianceBrickPacked, 16 > IrradianceBrickBuf
VecBase< int32_t, 3 > int3