Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/rendering/renderer_rd/environment/gi.h
21100 views
1
/**************************************************************************/
2
/* gi.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "core/templates/local_vector.h"
34
#include "core/templates/rid_owner.h"
35
#include "servers/rendering/environment/renderer_gi.h"
36
#include "servers/rendering/renderer_compositor.h"
37
#include "servers/rendering/renderer_rd/environment/sky.h"
38
#include "servers/rendering/renderer_rd/pipeline_deferred_rd.h"
39
#include "servers/rendering/renderer_rd/shaders/environment/gi.glsl.gen.h"
40
#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_debug.glsl.gen.h"
41
#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_debug_probes.glsl.gen.h"
42
#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_direct_light.glsl.gen.h"
43
#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_integrate.glsl.gen.h"
44
#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_preprocess.glsl.gen.h"
45
#include "servers/rendering/renderer_rd/shaders/environment/voxel_gi.glsl.gen.h"
46
#include "servers/rendering/renderer_rd/shaders/environment/voxel_gi_debug.glsl.gen.h"
47
#include "servers/rendering/renderer_rd/storage_rd/render_buffer_custom_data_rd.h"
48
#include "servers/rendering/renderer_scene_render.h"
49
#include "servers/rendering/rendering_device.h"
50
#include "servers/rendering/storage/utilities.h"
51
52
#define RB_SCOPE_GI SNAME("rbgi")
53
#define RB_SCOPE_SDFGI SNAME("sdfgi")
54
55
#define RB_TEX_AMBIENT SNAME("ambient")
56
#define RB_TEX_REFLECTION SNAME("reflection")
57
58
// Forward declare RenderDataRD and RendererSceneRenderRD so we can pass it into some of our methods, these classes are pretty tightly bound
59
class RenderDataRD;
60
class RendererSceneRenderRD;
61
62
namespace RendererRD {
63
64
class GI : public RendererGI {
65
public:
66
/* VOXEL GI STORAGE */
67
68
struct VoxelGI {
69
RID octree_buffer;
70
RID data_buffer;
71
RID sdf_texture;
72
73
uint32_t octree_buffer_size = 0;
74
uint32_t data_buffer_size = 0;
75
76
Vector<int> level_counts;
77
78
int cell_count = 0;
79
80
Transform3D to_cell_xform;
81
AABB bounds;
82
Vector3i octree_size;
83
84
float dynamic_range = 2.0;
85
float energy = 1.0;
86
float baked_exposure = 1.0;
87
float bias = 1.4;
88
float normal_bias = 0.0;
89
float propagation = 0.5;
90
bool interior = false;
91
bool use_two_bounces = true;
92
93
uint32_t version = 1;
94
uint32_t data_version = 1;
95
96
Dependency dependency;
97
};
98
99
/* VOXEL_GI INSTANCE */
100
101
//@TODO VoxelGIInstance is still directly used in the render code, we'll address this when we refactor the render code itself.
102
103
struct VoxelGIInstance {
104
// access to our containers
105
GI *gi = nullptr;
106
107
RID probe;
108
RID texture;
109
RID write_buffer;
110
111
struct Mipmap {
112
RID texture;
113
RID uniform_set;
114
RID second_bounce_uniform_set;
115
RID write_uniform_set;
116
uint32_t level;
117
uint32_t cell_offset;
118
uint32_t cell_count;
119
};
120
Vector<Mipmap> mipmaps;
121
122
struct DynamicMap {
123
RID texture; //color normally, or emission on first pass
124
RID fb_depth; //actual depth buffer for the first pass, float depth for later passes
125
RID depth; //actual depth buffer for the first pass, float depth for later passes
126
RID normal; //normal buffer for the first pass
127
RID albedo; //emission buffer for the first pass
128
RID orm; //orm buffer for the first pass
129
RID fb; //used for rendering, only valid on first map
130
RID uniform_set;
131
uint32_t size;
132
int mipmap; // mipmap to write to, -1 if no mipmap assigned
133
};
134
135
Vector<DynamicMap> dynamic_maps;
136
137
int slot = -1;
138
uint32_t last_probe_version = 0;
139
uint32_t last_probe_data_version = 0;
140
141
//uint64_t last_pass = 0;
142
uint32_t render_index = 0;
143
144
bool has_dynamic_object_data = false;
145
146
Transform3D transform;
147
148
void update(bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<RenderGeometryInstance *> &p_dynamic_objects);
149
void debug(RD::DrawListID p_draw_list, RID p_framebuffer, const Projection &p_camera_with_transform, bool p_lighting, bool p_emission, float p_alpha);
150
void free_resources();
151
};
152
153
private:
154
static GI *singleton;
155
156
/* VOXEL GI STORAGE */
157
158
mutable RID_Owner<VoxelGI, true> voxel_gi_owner;
159
160
/* VOXEL_GI INSTANCE */
161
162
mutable RID_Owner<VoxelGIInstance> voxel_gi_instance_owner;
163
164
struct VoxelGILight {
165
uint32_t type;
166
float energy;
167
float radius;
168
float attenuation;
169
170
float color[3];
171
float cos_spot_angle;
172
173
float position[3];
174
float inv_spot_attenuation;
175
176
float direction[3];
177
uint32_t has_shadow;
178
};
179
180
struct VoxelGIPushConstant {
181
int32_t limits[3];
182
uint32_t stack_size;
183
184
float emission_scale;
185
float propagation;
186
float dynamic_range;
187
uint32_t light_count;
188
189
uint32_t cell_offset;
190
uint32_t cell_count;
191
float aniso_strength;
192
float cell_size;
193
};
194
195
struct VoxelGIDynamicPushConstant {
196
int32_t limits[3];
197
uint32_t light_count;
198
int32_t x_dir[3];
199
float z_base;
200
int32_t y_dir[3];
201
float z_sign;
202
int32_t z_dir[3];
203
float pos_multiplier;
204
uint32_t rect_pos[2];
205
uint32_t rect_size[2];
206
uint32_t prev_rect_ofs[2];
207
uint32_t prev_rect_size[2];
208
uint32_t flip_x;
209
uint32_t flip_y;
210
float dynamic_range;
211
uint32_t on_mipmap;
212
float propagation;
213
float cell_size;
214
float pad[2];
215
};
216
217
VoxelGILight *voxel_gi_lights = nullptr;
218
uint32_t voxel_gi_max_lights = 32;
219
RID voxel_gi_lights_uniform;
220
221
enum {
222
VOXEL_GI_SHADER_VERSION_COMPUTE_LIGHT,
223
VOXEL_GI_SHADER_VERSION_COMPUTE_SECOND_BOUNCE,
224
VOXEL_GI_SHADER_VERSION_COMPUTE_MIPMAP,
225
VOXEL_GI_SHADER_VERSION_WRITE_TEXTURE,
226
VOXEL_GI_SHADER_VERSION_DYNAMIC_OBJECT_LIGHTING,
227
VOXEL_GI_SHADER_VERSION_DYNAMIC_SHRINK_WRITE,
228
VOXEL_GI_SHADER_VERSION_DYNAMIC_SHRINK_PLOT,
229
VOXEL_GI_SHADER_VERSION_DYNAMIC_SHRINK_WRITE_PLOT,
230
VOXEL_GI_SHADER_VERSION_MAX
231
};
232
233
VoxelGiShaderRD voxel_gi_shader;
234
RID voxel_gi_lighting_shader_version;
235
RID voxel_gi_lighting_shader_version_shaders[VOXEL_GI_SHADER_VERSION_MAX];
236
PipelineDeferredRD voxel_gi_lighting_shader_version_pipelines[VOXEL_GI_SHADER_VERSION_MAX];
237
238
enum {
239
VOXEL_GI_DEBUG_COLOR,
240
VOXEL_GI_DEBUG_LIGHT,
241
VOXEL_GI_DEBUG_EMISSION,
242
VOXEL_GI_DEBUG_LIGHT_FULL,
243
VOXEL_GI_DEBUG_MAX
244
};
245
246
struct VoxelGIDebugPushConstant {
247
float projection[16];
248
uint32_t cell_offset;
249
float dynamic_range;
250
float alpha;
251
uint32_t level;
252
int32_t bounds[3];
253
uint32_t pad;
254
};
255
256
VoxelGiDebugShaderRD voxel_gi_debug_shader;
257
RID voxel_gi_debug_shader_version;
258
RID voxel_gi_debug_shader_version_shaders[VOXEL_GI_DEBUG_MAX];
259
PipelineCacheRD voxel_gi_debug_shader_version_pipelines[VOXEL_GI_DEBUG_MAX];
260
RID voxel_gi_debug_uniform_set;
261
262
/* SDFGI */
263
264
struct SDFGIShader {
265
enum SDFGIPreprocessShaderVersion {
266
PRE_PROCESS_SCROLL,
267
PRE_PROCESS_SCROLL_OCCLUSION,
268
PRE_PROCESS_JUMP_FLOOD_INITIALIZE,
269
PRE_PROCESS_JUMP_FLOOD_INITIALIZE_HALF,
270
PRE_PROCESS_JUMP_FLOOD,
271
PRE_PROCESS_JUMP_FLOOD_OPTIMIZED,
272
PRE_PROCESS_JUMP_FLOOD_UPSCALE,
273
PRE_PROCESS_OCCLUSION,
274
PRE_PROCESS_STORE,
275
PRE_PROCESS_MAX
276
};
277
278
struct PreprocessPushConstant {
279
int32_t scroll[3];
280
int32_t grid_size;
281
282
int32_t probe_offset[3];
283
int32_t step_size;
284
285
int32_t half_size;
286
uint32_t occlusion_index;
287
int32_t cascade;
288
uint32_t pad;
289
};
290
291
SdfgiPreprocessShaderRD preprocess;
292
RID preprocess_shader;
293
PipelineDeferredRD preprocess_pipeline[PRE_PROCESS_MAX];
294
295
struct DebugPushConstant {
296
float grid_size[3];
297
uint32_t max_cascades;
298
299
int32_t screen_size[2];
300
float y_mult;
301
302
float z_near;
303
304
float inv_projection[3][4];
305
float cam_basis[3][3];
306
float cam_origin[3];
307
};
308
309
SdfgiDebugShaderRD debug;
310
RID debug_shader;
311
RID debug_shader_version;
312
PipelineDeferredRD debug_pipeline;
313
314
enum ProbeDebugMode {
315
PROBE_DEBUG_PROBES,
316
PROBE_DEBUG_PROBES_MULTIVIEW,
317
PROBE_DEBUG_VISIBILITY,
318
PROBE_DEBUG_VISIBILITY_MULTIVIEW,
319
PROBE_DEBUG_MAX
320
};
321
322
struct DebugProbesSceneData {
323
float projection[2][16];
324
};
325
326
struct DebugProbesPushConstant {
327
uint32_t band_power;
328
uint32_t sections_in_band;
329
uint32_t band_mask;
330
float section_arc;
331
332
float grid_size[3];
333
uint32_t cascade;
334
335
uint32_t pad;
336
float y_mult;
337
int32_t probe_debug_index;
338
int32_t probe_axis_size;
339
};
340
341
SdfgiDebugProbesShaderRD debug_probes;
342
RID debug_probes_shader;
343
RID debug_probes_shader_version;
344
345
PipelineCacheRD debug_probes_pipeline[PROBE_DEBUG_MAX];
346
347
struct Light {
348
float color[3];
349
float energy;
350
351
float direction[3];
352
uint32_t has_shadow;
353
354
float position[3];
355
float attenuation;
356
357
uint32_t type;
358
float cos_spot_angle;
359
float inv_spot_attenuation;
360
float radius;
361
};
362
363
struct DirectLightPushConstant {
364
float grid_size[3];
365
uint32_t max_cascades;
366
367
uint32_t cascade;
368
uint32_t light_count;
369
uint32_t process_offset;
370
uint32_t process_increment;
371
372
int32_t probe_axis_size;
373
float bounce_feedback;
374
float y_mult;
375
uint32_t use_occlusion;
376
};
377
378
enum {
379
DIRECT_LIGHT_MODE_STATIC,
380
DIRECT_LIGHT_MODE_DYNAMIC,
381
DIRECT_LIGHT_MODE_MAX
382
};
383
SdfgiDirectLightShaderRD direct_light;
384
RID direct_light_shader;
385
PipelineDeferredRD direct_light_pipeline[DIRECT_LIGHT_MODE_MAX];
386
387
enum {
388
INTEGRATE_MODE_PROCESS,
389
INTEGRATE_MODE_STORE,
390
INTEGRATE_MODE_SCROLL,
391
INTEGRATE_MODE_SCROLL_STORE,
392
INTEGRATE_MODE_MAX
393
};
394
struct IntegratePushConstant {
395
enum {
396
SKY_FLAGS_MODE_COLOR = 0x01,
397
SKY_FLAGS_MODE_SKY = 0x02,
398
SKY_FLAGS_ORIENTATION_SIGN = 0x04,
399
};
400
401
float grid_size[3];
402
uint32_t max_cascades;
403
404
uint32_t probe_axis_size;
405
uint32_t cascade;
406
uint32_t history_index;
407
uint32_t history_size;
408
409
uint32_t ray_count;
410
float ray_bias;
411
int32_t image_size[2];
412
413
int32_t world_offset[3];
414
uint32_t sky_flags;
415
416
int32_t scroll[3];
417
float sky_energy;
418
419
float sky_color_or_orientation[3];
420
float y_mult;
421
422
float sky_irradiance_border_size[2];
423
uint32_t store_ambient_texture;
424
uint32_t pad;
425
};
426
427
SdfgiIntegrateShaderRD integrate;
428
RID integrate_shader;
429
PipelineDeferredRD integrate_pipeline[INTEGRATE_MODE_MAX];
430
431
RID integrate_default_sky_uniform_set;
432
433
} sdfgi_shader;
434
435
public:
436
static GI *get_singleton() { return singleton; }
437
438
/* GI */
439
440
enum {
441
MAX_VOXEL_GI_INSTANCES = 8
442
};
443
444
// Struct for use in render buffer
445
class RenderBuffersGI : public RenderBufferCustomDataRD {
446
GDCLASS(RenderBuffersGI, RenderBufferCustomDataRD)
447
448
private:
449
RID voxel_gi_buffer;
450
451
public:
452
RID voxel_gi_textures[MAX_VOXEL_GI_INSTANCES];
453
454
RID full_buffer;
455
RID full_dispatch;
456
RID full_mask;
457
458
/* GI buffers */
459
bool using_half_size_gi = false;
460
461
RID uniform_set[RendererSceneRender::MAX_RENDER_VIEWS];
462
RID scene_data_ubo;
463
464
RID get_voxel_gi_buffer();
465
466
virtual void configure(RenderSceneBuffersRD *p_render_buffers) override {}
467
virtual void free_data() override;
468
};
469
470
/* VOXEL GI API */
471
472
bool owns_voxel_gi(RID p_rid) { return voxel_gi_owner.owns(p_rid); }
473
474
virtual RID voxel_gi_allocate() override;
475
virtual void voxel_gi_free(RID p_voxel_gi) override;
476
virtual void voxel_gi_initialize(RID p_voxel_gi) override;
477
478
virtual void voxel_gi_allocate_data(RID p_voxel_gi, const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) override;
479
480
virtual AABB voxel_gi_get_bounds(RID p_voxel_gi) const override;
481
virtual Vector3i voxel_gi_get_octree_size(RID p_voxel_gi) const override;
482
virtual Vector<uint8_t> voxel_gi_get_octree_cells(RID p_voxel_gi) const override;
483
virtual Vector<uint8_t> voxel_gi_get_data_cells(RID p_voxel_gi) const override;
484
virtual Vector<uint8_t> voxel_gi_get_distance_field(RID p_voxel_gi) const override;
485
486
virtual Vector<int> voxel_gi_get_level_counts(RID p_voxel_gi) const override;
487
virtual Transform3D voxel_gi_get_to_cell_xform(RID p_voxel_gi) const override;
488
489
virtual void voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range) override;
490
virtual float voxel_gi_get_dynamic_range(RID p_voxel_gi) const override;
491
492
virtual void voxel_gi_set_propagation(RID p_voxel_gi, float p_range) override;
493
virtual float voxel_gi_get_propagation(RID p_voxel_gi) const override;
494
495
virtual void voxel_gi_set_energy(RID p_voxel_gi, float p_energy) override;
496
virtual float voxel_gi_get_energy(RID p_voxel_gi) const override;
497
498
virtual void voxel_gi_set_baked_exposure_normalization(RID p_voxel_gi, float p_baked_exposure) override;
499
virtual float voxel_gi_get_baked_exposure_normalization(RID p_voxel_gi) const override;
500
501
virtual void voxel_gi_set_bias(RID p_voxel_gi, float p_bias) override;
502
virtual float voxel_gi_get_bias(RID p_voxel_gi) const override;
503
504
virtual void voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range) override;
505
virtual float voxel_gi_get_normal_bias(RID p_voxel_gi) const override;
506
507
virtual void voxel_gi_set_interior(RID p_voxel_gi, bool p_enable) override;
508
virtual bool voxel_gi_is_interior(RID p_voxel_gi) const override;
509
510
virtual void voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable) override;
511
virtual bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const override;
512
513
virtual uint32_t voxel_gi_get_version(RID p_probe) const override;
514
uint32_t voxel_gi_get_data_version(RID p_probe);
515
516
RID voxel_gi_get_octree_buffer(RID p_voxel_gi) const;
517
RID voxel_gi_get_data_buffer(RID p_voxel_gi) const;
518
519
RID voxel_gi_get_sdf_texture(RID p_voxel_gi);
520
521
Dependency *voxel_gi_get_dependency(RID p_voxel_gi) const;
522
523
/* VOXEL_GI INSTANCE */
524
525
_FORCE_INLINE_ RID voxel_gi_instance_get_texture(RID p_probe) {
526
VoxelGIInstance *voxel_gi = voxel_gi_instance_owner.get_or_null(p_probe);
527
ERR_FAIL_NULL_V(voxel_gi, RID());
528
return voxel_gi->texture;
529
}
530
531
_FORCE_INLINE_ void voxel_gi_instance_set_render_index(RID p_probe, uint32_t p_index) {
532
VoxelGIInstance *voxel_gi = voxel_gi_instance_owner.get_or_null(p_probe);
533
ERR_FAIL_NULL(voxel_gi);
534
535
voxel_gi->render_index = p_index;
536
}
537
538
bool voxel_gi_instance_owns(RID p_rid) const {
539
return voxel_gi_instance_owner.owns(p_rid);
540
}
541
542
void voxel_gi_instance_free(RID p_rid);
543
544
RS::VoxelGIQuality voxel_gi_quality = RS::VOXEL_GI_QUALITY_LOW;
545
546
/* SDFGI */
547
548
class SDFGI : public RenderBufferCustomDataRD {
549
GDCLASS(SDFGI, RenderBufferCustomDataRD)
550
551
public:
552
enum {
553
MAX_CASCADES = 8,
554
CASCADE_SIZE = 128,
555
PROBE_DIVISOR = 16,
556
ANISOTROPY_SIZE = 6,
557
MAX_DYNAMIC_LIGHTS = 128,
558
MAX_STATIC_LIGHTS = 1024,
559
LIGHTPROBE_OCT_SIZE = 6,
560
SH_SIZE = 16
561
};
562
563
struct Cascade {
564
struct UBO {
565
float offset[3];
566
float to_cell;
567
int32_t probe_offset[3];
568
uint32_t pad;
569
float pad2[4];
570
};
571
572
//cascade blocks are full-size for volume (128^3), half size for albedo/emission
573
RID sdf_tex;
574
RID light_tex;
575
RID light_aniso_0_tex;
576
RID light_aniso_1_tex;
577
578
RID light_data;
579
RID light_aniso_0_data;
580
RID light_aniso_1_data;
581
582
struct SolidCell { // this struct is unused, but remains as reference for size
583
uint32_t position;
584
uint32_t albedo;
585
uint32_t static_light;
586
uint32_t static_light_aniso;
587
};
588
589
// Buffers for indirect compute dispatch.
590
RID solid_cell_dispatch_buffer_storage;
591
RID solid_cell_dispatch_buffer_call;
592
RID solid_cell_buffer;
593
594
RID lightprobe_history_tex;
595
RID lightprobe_average_tex;
596
597
float cell_size;
598
Vector3i position;
599
600
static const Vector3i DIRTY_ALL;
601
Vector3i dirty_regions; //(0,0,0 is not dirty, negative is refresh from the end, DIRTY_ALL is refresh all.
602
603
RID sdf_store_uniform_set;
604
RID sdf_direct_light_static_uniform_set;
605
RID sdf_direct_light_dynamic_uniform_set;
606
RID scroll_uniform_set;
607
RID scroll_occlusion_uniform_set;
608
RID integrate_uniform_set;
609
RID lights_buffer;
610
611
float baked_exposure_normalization = 1.0;
612
613
bool all_dynamic_lights_dirty = true;
614
};
615
616
// access to our containers
617
GI *gi = nullptr;
618
619
// used for rendering (voxelization)
620
RID render_albedo;
621
RID render_emission;
622
RID render_emission_aniso;
623
RID render_occlusion[8];
624
RID render_geom_facing;
625
626
RID render_sdf[2];
627
RID render_sdf_half[2];
628
629
// used for ping pong processing in cascades
630
RID sdf_initialize_uniform_set;
631
RID sdf_initialize_half_uniform_set;
632
RID jump_flood_uniform_set[2];
633
RID jump_flood_half_uniform_set[2];
634
RID sdf_upscale_uniform_set;
635
int upscale_jfa_uniform_set_index;
636
RID occlusion_uniform_set;
637
638
uint32_t cascade_size = 128;
639
640
LocalVector<Cascade> cascades;
641
642
RID lightprobe_texture;
643
RID lightprobe_data;
644
RID occlusion_texture;
645
RID occlusion_data;
646
RID ambient_texture; //integrates with volumetric fog
647
648
RID lightprobe_history_scroll; //used for scrolling lightprobes
649
RID lightprobe_average_scroll; //used for scrolling lightprobes
650
651
uint32_t history_size = 0;
652
float solid_cell_ratio = 0;
653
uint32_t solid_cell_count = 0;
654
655
int num_cascades = 6;
656
float min_cell_size = 0;
657
uint32_t probe_axis_count = 0; //amount of probes per axis, this is an odd number because it encloses endpoints
658
659
RID debug_uniform_set[RendererSceneRender::MAX_RENDER_VIEWS];
660
RID debug_probes_scene_data_ubo;
661
RID debug_probes_uniform_set;
662
RID cascades_ubo;
663
664
bool uses_occlusion = false;
665
float bounce_feedback = 0.5;
666
bool reads_sky = true;
667
float energy = 1.0;
668
float normal_bias = 1.1;
669
float probe_bias = 1.1;
670
RS::EnvironmentSDFGIYScale y_scale_mode = RS::ENV_SDFGI_Y_SCALE_75_PERCENT;
671
672
float y_mult = 1.0;
673
674
uint32_t version = 0;
675
uint32_t render_pass = 0;
676
677
int32_t cascade_dynamic_light_count[SDFGI::MAX_CASCADES]; //used dynamically
678
RID integrate_sky_uniform_set;
679
680
virtual void configure(RenderSceneBuffersRD *p_render_buffers) override {}
681
virtual void free_data() override;
682
~SDFGI();
683
684
void create(RID p_env, const Vector3 &p_world_position, uint32_t p_requested_history_size, GI *p_gi);
685
void update(RID p_env, const Vector3 &p_world_position);
686
void update_light();
687
void update_probes(RID p_env, RendererRD::SkyRD::Sky *p_sky);
688
void store_probes();
689
int get_pending_region_data(int p_region, Vector3i &r_local_offset, Vector3i &r_local_size, AABB &r_bounds) const;
690
void update_cascades();
691
692
void debug_draw(uint32_t p_view_count, const Projection *p_projections, const Transform3D &p_transform, int p_width, int p_height, RID p_render_target, RID p_texture, const Vector<RID> &p_texture_views);
693
void debug_probes(RID p_framebuffer, const uint32_t p_view_count, const Projection *p_camera_with_transforms);
694
695
void pre_process_gi(const Transform3D &p_transform, RenderDataRD *p_render_data);
696
void render_region(Ref<RenderSceneBuffersRD> p_render_buffers, int p_region, const PagedArray<RenderGeometryInstance *> &p_instances, float p_exposure_normalization);
697
void render_static_lights(RenderDataRD *p_render_data, Ref<RenderSceneBuffersRD> p_render_buffers, uint32_t p_cascade_count, const uint32_t *p_cascade_indices, const PagedArray<RID> *p_positional_light_cull_result);
698
};
699
700
RS::EnvironmentSDFGIRayCount sdfgi_ray_count = RS::ENV_SDFGI_RAY_COUNT_16;
701
RS::EnvironmentSDFGIFramesToConverge sdfgi_frames_to_converge = RS::ENV_SDFGI_CONVERGE_IN_30_FRAMES;
702
RS::EnvironmentSDFGIFramesToUpdateLight sdfgi_frames_to_update_light = RS::ENV_SDFGI_UPDATE_LIGHT_IN_4_FRAMES;
703
704
float sdfgi_solid_cell_ratio = 0.25;
705
Vector3 sdfgi_debug_probe_pos;
706
Vector3 sdfgi_debug_probe_dir;
707
bool sdfgi_debug_probe_enabled = false;
708
Vector3i sdfgi_debug_probe_index;
709
uint32_t sdfgi_current_version = 0;
710
711
/* SDFGI UPDATE */
712
713
int sdfgi_get_lightprobe_octahedron_size() const { return SDFGI::LIGHTPROBE_OCT_SIZE; }
714
715
virtual void sdfgi_reset() override;
716
717
struct SDFGIData {
718
float grid_size[3];
719
uint32_t max_cascades;
720
721
uint32_t use_occlusion;
722
int32_t probe_axis_size;
723
float probe_to_uvw;
724
float normal_bias;
725
726
float lightprobe_tex_pixel_size[3];
727
float energy;
728
729
float lightprobe_uv_offset[3];
730
float y_mult;
731
732
float occlusion_clamp[3];
733
uint32_t pad3;
734
735
float occlusion_renormalize[3];
736
uint32_t pad4;
737
738
float cascade_probe_size[3];
739
uint32_t pad5;
740
741
struct ProbeCascadeData {
742
float position[3]; //offset of (0,0,0) in world coordinates
743
float to_probe; // 1/bounds * grid_size
744
int32_t probe_world_offset[3];
745
float to_cell; // 1/bounds * grid_size
746
float pad[3];
747
float exposure_normalization;
748
};
749
750
ProbeCascadeData cascades[SDFGI::MAX_CASCADES];
751
};
752
753
struct VoxelGIData {
754
float xform[16]; // 64 - 64
755
756
float bounds[3]; // 12 - 76
757
float dynamic_range; // 4 - 80
758
759
float bias; // 4 - 84
760
float normal_bias; // 4 - 88
761
uint32_t blend_ambient; // 4 - 92
762
uint32_t mipmaps; // 4 - 96
763
764
float pad[3]; // 12 - 108
765
float exposure_normalization; // 4 - 112
766
};
767
768
struct SceneData {
769
float inv_projection[2][16];
770
float cam_transform[16];
771
float eye_offset[2][4];
772
773
int32_t screen_size[2];
774
float pad1;
775
float pad2;
776
};
777
778
struct PushConstant {
779
uint32_t max_voxel_gi_instances;
780
uint32_t high_quality_vct;
781
uint32_t orthogonal;
782
uint32_t view_index;
783
784
float proj_info[4];
785
786
float z_near;
787
float z_far;
788
float pad2;
789
float pad3;
790
};
791
792
RID sdfgi_ubo;
793
794
enum Group {
795
GROUP_NORMAL,
796
GROUP_VRS,
797
};
798
799
enum Mode {
800
MODE_VOXEL_GI,
801
MODE_VOXEL_GI_WITHOUT_SAMPLER,
802
MODE_SDFGI,
803
MODE_COMBINED,
804
MODE_COMBINED_WITHOUT_SAMPLER,
805
MODE_MAX
806
};
807
808
enum ShaderSpecializations {
809
SHADER_SPECIALIZATION_HALF_RES = 1 << 0,
810
SHADER_SPECIALIZATION_USE_FULL_PROJECTION_MATRIX = 1 << 1,
811
SHADER_SPECIALIZATION_USE_VRS = 1 << 2,
812
SHADER_SPECIALIZATION_VARIATIONS = 8,
813
};
814
815
RID default_voxel_gi_buffer;
816
817
bool half_resolution = false;
818
GiShaderRD shader;
819
RID shader_version;
820
PipelineDeferredRD pipelines[SHADER_SPECIALIZATION_VARIATIONS][MODE_MAX];
821
822
GI();
823
~GI();
824
825
void init(RendererRD::SkyRD *p_sky);
826
void free();
827
828
Ref<SDFGI> create_sdfgi(RID p_env, const Vector3 &p_world_position, uint32_t p_requested_history_size);
829
830
void setup_voxel_gi_instances(RenderDataRD *p_render_data, Ref<RenderSceneBuffersRD> p_render_buffers, const Transform3D &p_transform, const PagedArray<RID> &p_voxel_gi_instances, uint32_t &r_voxel_gi_instances_used);
831
void process_gi(Ref<RenderSceneBuffersRD> p_render_buffers, const RID *p_normal_roughness_slices, RID p_voxel_gi_buffer, RID p_environment, uint32_t p_view_count, const Projection *p_projections, const Vector3 *p_eye_offsets, const Transform3D &p_cam_transform, const PagedArray<RID> &p_voxel_gi_instances);
832
833
RID voxel_gi_instance_create(RID p_base);
834
void voxel_gi_instance_set_transform_to_data(RID p_probe, const Transform3D &p_xform);
835
bool voxel_gi_needs_update(RID p_probe) const;
836
void voxel_gi_update(RID p_probe, bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<RenderGeometryInstance *> &p_dynamic_objects);
837
void debug_voxel_gi(RID p_voxel_gi, RD::DrawListID p_draw_list, RID p_framebuffer, const Projection &p_camera_with_transform, bool p_lighting, bool p_emission, float p_alpha);
838
839
void enable_vrs_shader_group();
840
};
841
842
} // namespace RendererRD
843
844