Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/rendering/renderer_scene_cull.h
10277 views
1
/**************************************************************************/
2
/* renderer_scene_cull.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/math/dynamic_bvh.h"
34
#include "core/math/transform_interpolator.h"
35
#include "core/templates/bin_sorted_array.h"
36
#include "core/templates/local_vector.h"
37
#include "core/templates/paged_allocator.h"
38
#include "core/templates/paged_array.h"
39
#include "core/templates/pass_func.h"
40
#include "core/templates/rid_owner.h"
41
#include "core/templates/self_list.h"
42
#include "servers/rendering/instance_uniforms.h"
43
#include "servers/rendering/renderer_scene_occlusion_cull.h"
44
#include "servers/rendering/renderer_scene_render.h"
45
#include "servers/rendering/rendering_method.h"
46
#include "servers/rendering/rendering_server_globals.h"
47
#include "servers/rendering/storage/utilities.h"
48
49
class RenderingLightCuller;
50
51
class RendererSceneCull : public RenderingMethod {
52
public:
53
RendererSceneRender *scene_render = nullptr;
54
55
enum {
56
SDFGI_MAX_CASCADES = 8,
57
SDFGI_MAX_REGIONS_PER_CASCADE = 3,
58
MAX_INSTANCE_PAIRS = 32,
59
MAX_UPDATE_SHADOWS = 512
60
};
61
62
uint64_t render_pass;
63
64
static RendererSceneCull *singleton;
65
66
/* EVENT QUEUING */
67
68
void tick();
69
void pre_draw(bool p_will_draw);
70
71
/* CAMERA API */
72
73
struct Camera {
74
enum Type {
75
PERSPECTIVE,
76
ORTHOGONAL,
77
FRUSTUM
78
};
79
Type type;
80
float fov;
81
float znear, zfar;
82
float size;
83
Vector2 offset;
84
uint32_t visible_layers;
85
bool vaspect;
86
RID env;
87
RID attributes;
88
RID compositor;
89
90
Transform3D transform;
91
92
Camera() {
93
visible_layers = 0xFFFFFFFF;
94
fov = 75;
95
type = PERSPECTIVE;
96
znear = 0.05;
97
zfar = 4000;
98
size = 1.0;
99
offset = Vector2();
100
vaspect = false;
101
}
102
};
103
104
mutable RID_Owner<Camera, true> camera_owner;
105
106
virtual RID camera_allocate();
107
virtual void camera_initialize(RID p_rid);
108
109
virtual void camera_set_perspective(RID p_camera, float p_fovy_degrees, float p_z_near, float p_z_far);
110
virtual void camera_set_orthogonal(RID p_camera, float p_size, float p_z_near, float p_z_far);
111
virtual void camera_set_frustum(RID p_camera, float p_size, Vector2 p_offset, float p_z_near, float p_z_far);
112
virtual void camera_set_transform(RID p_camera, const Transform3D &p_transform);
113
virtual void camera_set_cull_mask(RID p_camera, uint32_t p_layers);
114
virtual void camera_set_environment(RID p_camera, RID p_env);
115
virtual void camera_set_camera_attributes(RID p_camera, RID p_attributes);
116
virtual void camera_set_compositor(RID p_camera, RID p_compositor);
117
virtual void camera_set_use_vertical_aspect(RID p_camera, bool p_enable);
118
virtual bool is_camera(RID p_camera) const;
119
120
/* OCCLUDER API */
121
122
virtual RID occluder_allocate();
123
virtual void occluder_initialize(RID p_occluder);
124
virtual void occluder_set_mesh(RID p_occluder, const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices);
125
126
/* VISIBILITY NOTIFIER API */
127
128
RendererSceneOcclusionCull *dummy_occlusion_culling = nullptr;
129
130
/* SCENARIO API */
131
132
struct Instance;
133
134
struct PlaneSign {
135
_ALWAYS_INLINE_ PlaneSign() {}
136
_ALWAYS_INLINE_ PlaneSign(const Plane &p_plane) {
137
if (p_plane.normal.x > 0) {
138
signs[0] = 0;
139
} else {
140
signs[0] = 3;
141
}
142
if (p_plane.normal.y > 0) {
143
signs[1] = 1;
144
} else {
145
signs[1] = 4;
146
}
147
if (p_plane.normal.z > 0) {
148
signs[2] = 2;
149
} else {
150
signs[2] = 5;
151
}
152
}
153
154
uint32_t signs[3];
155
};
156
157
struct Frustum {
158
Vector<Plane> planes;
159
Vector<PlaneSign> plane_signs;
160
const Plane *planes_ptr;
161
const PlaneSign *plane_signs_ptr;
162
uint32_t plane_count;
163
164
_ALWAYS_INLINE_ Frustum() {}
165
_ALWAYS_INLINE_ Frustum(const Frustum &p_frustum) {
166
planes = p_frustum.planes;
167
plane_signs = p_frustum.plane_signs;
168
169
planes_ptr = planes.ptr();
170
plane_signs_ptr = plane_signs.ptr();
171
plane_count = p_frustum.plane_count;
172
}
173
_ALWAYS_INLINE_ void operator=(const Frustum &p_frustum) {
174
planes = p_frustum.planes;
175
plane_signs = p_frustum.plane_signs;
176
177
planes_ptr = planes.ptr();
178
plane_signs_ptr = plane_signs.ptr();
179
plane_count = p_frustum.plane_count;
180
}
181
_ALWAYS_INLINE_ Frustum(const Vector<Plane> &p_planes) {
182
planes = p_planes;
183
planes_ptr = planes.ptrw();
184
plane_count = planes.size();
185
for (int i = 0; i < planes.size(); i++) {
186
PlaneSign ps(p_planes[i]);
187
plane_signs.push_back(ps);
188
}
189
190
plane_signs_ptr = plane_signs.ptr();
191
}
192
};
193
194
struct InstanceBounds {
195
// Efficiently store instance bounds.
196
// Because bounds checking is performed first,
197
// keep it separated from data.
198
199
real_t bounds[6];
200
_ALWAYS_INLINE_ InstanceBounds() {}
201
202
_ALWAYS_INLINE_ InstanceBounds(const AABB &p_aabb) {
203
bounds[0] = p_aabb.position.x;
204
bounds[1] = p_aabb.position.y;
205
bounds[2] = p_aabb.position.z;
206
bounds[3] = p_aabb.position.x + p_aabb.size.x;
207
bounds[4] = p_aabb.position.y + p_aabb.size.y;
208
bounds[5] = p_aabb.position.z + p_aabb.size.z;
209
}
210
_ALWAYS_INLINE_ bool in_frustum(const Frustum &p_frustum) const {
211
// This is not a full SAT check and the possibility of false positives exist,
212
// but the tradeoff vs performance is still very good.
213
214
for (uint32_t i = 0; i < p_frustum.plane_count; i++) {
215
Vector3 min(
216
bounds[p_frustum.plane_signs_ptr[i].signs[0]],
217
bounds[p_frustum.plane_signs_ptr[i].signs[1]],
218
bounds[p_frustum.plane_signs_ptr[i].signs[2]]);
219
220
if (p_frustum.planes_ptr[i].distance_to(min) >= 0.0) {
221
return false;
222
}
223
}
224
225
return true;
226
}
227
_ALWAYS_INLINE_ bool in_aabb(const AABB &p_aabb) const {
228
Vector3 end = p_aabb.position + p_aabb.size;
229
230
if (bounds[0] >= end.x) {
231
return false;
232
}
233
if (bounds[3] <= p_aabb.position.x) {
234
return false;
235
}
236
if (bounds[1] >= end.y) {
237
return false;
238
}
239
if (bounds[4] <= p_aabb.position.y) {
240
return false;
241
}
242
if (bounds[2] >= end.z) {
243
return false;
244
}
245
if (bounds[5] <= p_aabb.position.z) {
246
return false;
247
}
248
249
return true;
250
}
251
};
252
253
struct InstanceVisibilityNotifierData;
254
255
struct InstanceData {
256
// Store instance pointer as well as common instance processing information,
257
// to make processing more cache friendly.
258
enum Flags : uint32_t {
259
FLAG_BASE_TYPE_MASK = 0xFF,
260
FLAG_CAST_SHADOWS = (1 << 8),
261
FLAG_CAST_SHADOWS_ONLY = (1 << 9),
262
FLAG_REDRAW_IF_VISIBLE = (1 << 10),
263
FLAG_GEOM_LIGHTING_DIRTY = (1 << 11),
264
FLAG_GEOM_REFLECTION_DIRTY = (1 << 12),
265
FLAG_GEOM_DECAL_DIRTY = (1 << 13),
266
FLAG_GEOM_VOXEL_GI_DIRTY = (1 << 14),
267
FLAG_LIGHTMAP_CAPTURE = (1 << 15),
268
FLAG_USES_BAKED_LIGHT = (1 << 16),
269
FLAG_USES_MESH_INSTANCE = (1 << 17),
270
FLAG_REFLECTION_PROBE_DIRTY = (1 << 18),
271
FLAG_IGNORE_OCCLUSION_CULLING = (1 << 19),
272
FLAG_VISIBILITY_DEPENDENCY_NEEDS_CHECK = (3 << 20), // 2 bits, overlaps with the other vis. dependency flags
273
FLAG_VISIBILITY_DEPENDENCY_HIDDEN_CLOSE_RANGE = (1 << 20),
274
FLAG_VISIBILITY_DEPENDENCY_HIDDEN = (1 << 21),
275
FLAG_VISIBILITY_DEPENDENCY_FADE_CHILDREN = (1 << 22),
276
FLAG_GEOM_PROJECTOR_SOFTSHADOW_DIRTY = (1 << 23),
277
FLAG_IGNORE_ALL_CULLING = (1 << 24),
278
};
279
280
uint32_t flags = 0;
281
uint32_t layer_mask = 0; //for fast layer-mask discard
282
RID base_rid;
283
union {
284
uint64_t instance_data_rid;
285
RenderGeometryInstance *instance_geometry;
286
InstanceVisibilityNotifierData *visibility_notifier = nullptr;
287
};
288
Instance *instance = nullptr;
289
int32_t parent_array_index = -1;
290
int32_t visibility_index = -1;
291
292
// Each time occlusion culling determines an instance is visible,
293
// set this to occlusion_frame plus some delay.
294
// Once the timeout is reached, allow the instance to be occlusion culled.
295
// This creates a delay for occlusion culling, which prevents flickering
296
// when jittering the raster occlusion projection.
297
uint64_t occlusion_timeout = 0;
298
};
299
300
struct InstanceVisibilityData {
301
uint64_t viewport_state = 0;
302
int32_t array_index = -1;
303
RS::VisibilityRangeFadeMode fade_mode = RS::VISIBILITY_RANGE_FADE_DISABLED;
304
Vector3 position;
305
Instance *instance = nullptr;
306
float range_begin = 0.0f;
307
float range_end = 0.0f;
308
float range_begin_margin = 0.0f;
309
float range_end_margin = 0.0f;
310
float children_fade_alpha = 1.0f;
311
};
312
313
class VisibilityArray : public BinSortedArray<InstanceVisibilityData> {
314
_FORCE_INLINE_ virtual void _update_idx(InstanceVisibilityData &r_element, uint64_t p_idx) {
315
r_element.instance->visibility_index = p_idx;
316
if (r_element.instance->scenario && r_element.instance->array_index != -1) {
317
r_element.instance->scenario->instance_data[r_element.instance->array_index].visibility_index = p_idx;
318
}
319
}
320
};
321
322
PagedArrayPool<InstanceBounds> instance_aabb_page_pool;
323
PagedArrayPool<InstanceData> instance_data_page_pool;
324
PagedArrayPool<InstanceVisibilityData> instance_visibility_data_page_pool;
325
326
struct Scenario {
327
enum IndexerType {
328
INDEXER_GEOMETRY, //for geometry
329
INDEXER_VOLUMES, //for everything else
330
INDEXER_MAX
331
};
332
333
DynamicBVH indexers[INDEXER_MAX];
334
335
RID self;
336
337
List<Instance *> directional_lights;
338
RID environment;
339
RID fallback_environment;
340
RID camera_attributes;
341
RID compositor;
342
RID reflection_probe_shadow_atlas;
343
RID reflection_atlas;
344
uint64_t used_viewport_visibility_bits;
345
HashMap<RID, uint64_t> viewport_visibility_masks;
346
347
SelfList<Instance>::List instances;
348
349
LocalVector<RID> dynamic_lights;
350
351
PagedArray<InstanceBounds> instance_aabbs;
352
PagedArray<InstanceData> instance_data;
353
VisibilityArray instance_visibility;
354
355
Scenario() {
356
indexers[INDEXER_GEOMETRY].set_index(INDEXER_GEOMETRY);
357
indexers[INDEXER_VOLUMES].set_index(INDEXER_VOLUMES);
358
used_viewport_visibility_bits = 0;
359
}
360
};
361
362
int indexer_update_iterations = 0;
363
364
mutable RID_Owner<Scenario, true> scenario_owner;
365
366
static void _instance_pair(Instance *p_A, Instance *p_B);
367
static void _instance_unpair(Instance *p_A, Instance *p_B);
368
369
void _instance_update_mesh_instance(Instance *p_instance) const;
370
371
virtual RID scenario_allocate();
372
virtual void scenario_initialize(RID p_rid);
373
374
virtual void scenario_set_environment(RID p_scenario, RID p_environment);
375
virtual void scenario_set_camera_attributes(RID p_scenario, RID p_attributes);
376
virtual void scenario_set_fallback_environment(RID p_scenario, RID p_environment);
377
virtual void scenario_set_compositor(RID p_scenario, RID p_compositor);
378
virtual void scenario_set_reflection_atlas_size(RID p_scenario, int p_reflection_size, int p_reflection_count);
379
virtual bool is_scenario(RID p_scenario) const;
380
virtual RID scenario_get_environment(RID p_scenario);
381
virtual void scenario_add_viewport_visibility_mask(RID p_scenario, RID p_viewport);
382
virtual void scenario_remove_viewport_visibility_mask(RID p_scenario, RID p_viewport);
383
384
/* INSTANCING API */
385
386
struct InstancePair {
387
Instance *a = nullptr;
388
Instance *b = nullptr;
389
SelfList<InstancePair> list_a;
390
SelfList<InstancePair> list_b;
391
InstancePair() :
392
list_a(this), list_b(this) {}
393
};
394
395
mutable PagedAllocator<InstancePair> pair_allocator;
396
397
struct InstanceBaseData {
398
virtual ~InstanceBaseData() {}
399
};
400
401
struct Instance {
402
RS::InstanceType base_type;
403
RID base;
404
405
RID skeleton;
406
RID material_override;
407
RID material_overlay;
408
409
RID mesh_instance; //only used for meshes and when skeleton/blendshapes exist
410
411
Transform3D transform;
412
bool teleported = false;
413
414
float lod_bias;
415
416
bool ignore_occlusion_culling;
417
bool ignore_all_culling;
418
419
Vector<RID> materials;
420
421
RS::ShadowCastingSetting cast_shadows;
422
423
uint32_t layer_mask;
424
// Fit in 32 bits.
425
bool mirror : 1;
426
bool receive_shadows : 1;
427
bool visible : 1;
428
bool baked_light : 1; // This flag is only to know if it actually did use baked light.
429
bool dynamic_gi : 1; // Same as above for dynamic objects.
430
bool redraw_if_visible : 1;
431
432
Instance *lightmap = nullptr;
433
Rect2 lightmap_uv_scale;
434
int lightmap_slice_index;
435
uint32_t lightmap_cull_index;
436
Vector<Color> lightmap_sh; //spherical harmonic
437
438
AABB aabb;
439
AABB transformed_aabb;
440
AABB prev_transformed_aabb;
441
442
InstanceUniforms instance_uniforms;
443
444
//
445
446
RID self;
447
//scenario stuff
448
DynamicBVH::ID indexer_id;
449
int32_t array_index = -1;
450
int32_t visibility_index = -1;
451
float visibility_range_begin = 0.0f;
452
float visibility_range_end = 0.0f;
453
float visibility_range_begin_margin = 0.0f;
454
float visibility_range_end_margin = 0.0f;
455
RS::VisibilityRangeFadeMode visibility_range_fade_mode = RS::VISIBILITY_RANGE_FADE_DISABLED;
456
Instance *visibility_parent = nullptr;
457
HashSet<Instance *> visibility_dependencies;
458
uint32_t visibility_dependencies_depth = 0;
459
float transparency = 0.0f;
460
Scenario *scenario = nullptr;
461
SelfList<Instance> scenario_item;
462
463
//aabb stuff
464
bool update_aabb;
465
bool update_dependencies;
466
467
SelfList<Instance> update_item;
468
469
AABB *custom_aabb = nullptr; // <Zylann> would using aabb directly with a bool be better?
470
float extra_margin;
471
ObjectID object_id;
472
473
// sorting
474
float sorting_offset = 0.0;
475
bool use_aabb_center = true;
476
477
Vector<Color> lightmap_target_sh; //target is used for incrementally changing the SH over time, this avoids pops in some corner cases and when going interior <-> exterior
478
479
uint64_t last_frame_pass;
480
481
uint64_t version; // changes to this, and changes to base increase version
482
483
InstanceBaseData *base_data = nullptr;
484
485
SelfList<InstancePair>::List pairs;
486
uint64_t pair_check;
487
488
DependencyTracker dependency_tracker;
489
490
static void dependency_changed(Dependency::DependencyChangedNotification p_notification, DependencyTracker *tracker) {
491
Instance *instance = (Instance *)tracker->userdata;
492
switch (p_notification) {
493
case Dependency::DEPENDENCY_CHANGED_SKELETON_DATA:
494
case Dependency::DEPENDENCY_CHANGED_SKELETON_BONES:
495
case Dependency::DEPENDENCY_CHANGED_AABB: {
496
singleton->_instance_queue_update(instance, true, false);
497
498
} break;
499
case Dependency::DEPENDENCY_CHANGED_MULTIMESH_VISIBLE_INSTANCES:
500
case Dependency::DEPENDENCY_CHANGED_MATERIAL: {
501
singleton->_instance_queue_update(instance, false, true);
502
} break;
503
case Dependency::DEPENDENCY_CHANGED_MESH:
504
case Dependency::DEPENDENCY_CHANGED_PARTICLES:
505
case Dependency::DEPENDENCY_CHANGED_MULTIMESH:
506
case Dependency::DEPENDENCY_CHANGED_DECAL:
507
case Dependency::DEPENDENCY_CHANGED_LIGHT: {
508
singleton->_instance_queue_update(instance, true, true);
509
} break;
510
case Dependency::DEPENDENCY_CHANGED_REFLECTION_PROBE:
511
case Dependency::DEPENDENCY_CHANGED_LIGHT_SOFT_SHADOW_AND_PROJECTOR:
512
case Dependency::DEPENDENCY_CHANGED_CULL_MASK: {
513
//requires repairing
514
if (instance->indexer_id.is_valid()) {
515
singleton->_unpair_instance(instance);
516
singleton->_instance_queue_update(instance, true, true);
517
}
518
519
} break;
520
default: {
521
// Ignored notifications.
522
} break;
523
}
524
}
525
526
static void dependency_deleted(const RID &p_dependency, DependencyTracker *tracker) {
527
Instance *instance = (Instance *)tracker->userdata;
528
529
if (p_dependency == instance->base) {
530
singleton->instance_set_base(instance->self, RID());
531
} else if (p_dependency == instance->skeleton) {
532
singleton->instance_attach_skeleton(instance->self, RID());
533
} else {
534
// It's possible the same material is used in multiple slots,
535
// so we check whether we need to clear them all.
536
if (p_dependency == instance->material_override) {
537
singleton->instance_geometry_set_material_override(instance->self, RID());
538
}
539
if (p_dependency == instance->material_overlay) {
540
singleton->instance_geometry_set_material_overlay(instance->self, RID());
541
}
542
for (int i = 0; i < instance->materials.size(); i++) {
543
if (p_dependency == instance->materials[i]) {
544
singleton->instance_set_surface_override_material(instance->self, i, RID());
545
}
546
}
547
if (instance->base_type == RS::INSTANCE_PARTICLES) {
548
RID particle_material = RSG::particles_storage->particles_get_process_material(instance->base);
549
if (p_dependency == particle_material) {
550
RSG::particles_storage->particles_set_process_material(instance->base, RID());
551
}
552
}
553
554
// Even if no change is made we still need to call `_instance_queue_update`.
555
// This dependency could also be a result of the freed material being used
556
// by the mesh this mesh instance uses.
557
singleton->_instance_queue_update(instance, false, true);
558
}
559
}
560
561
Instance() :
562
scenario_item(this),
563
update_item(this) {
564
base_type = RS::INSTANCE_NONE;
565
cast_shadows = RS::SHADOW_CASTING_SETTING_ON;
566
receive_shadows = true;
567
visible = true;
568
layer_mask = 1;
569
baked_light = true;
570
dynamic_gi = false;
571
redraw_if_visible = false;
572
573
lightmap_slice_index = 0;
574
lightmap = nullptr;
575
lightmap_cull_index = 0;
576
lod_bias = 1.0;
577
ignore_occlusion_culling = false;
578
ignore_all_culling = false;
579
580
scenario = nullptr;
581
582
update_aabb = false;
583
update_dependencies = false;
584
585
extra_margin = 0;
586
587
visible = true;
588
589
visibility_range_begin = 0;
590
visibility_range_end = 0;
591
visibility_range_begin_margin = 0;
592
visibility_range_end_margin = 0;
593
594
last_frame_pass = 0;
595
version = 1;
596
base_data = nullptr;
597
598
custom_aabb = nullptr;
599
600
pair_check = 0;
601
array_index = -1;
602
603
dependency_tracker.userdata = this;
604
dependency_tracker.changed_callback = dependency_changed;
605
dependency_tracker.deleted_callback = dependency_deleted;
606
}
607
608
~Instance() {
609
if (base_data) {
610
memdelete(base_data);
611
}
612
if (custom_aabb) {
613
memdelete(custom_aabb);
614
}
615
}
616
};
617
618
mutable SelfList<Instance>::List _instance_update_list;
619
void _instance_queue_update(Instance *p_instance, bool p_update_aabb, bool p_update_dependencies = false) const;
620
621
struct InstanceGeometryData : public InstanceBaseData {
622
RenderGeometryInstance *geometry_instance = nullptr;
623
HashSet<Instance *> lights;
624
bool can_cast_shadows;
625
bool material_is_animated;
626
uint32_t projector_count = 0;
627
uint32_t softshadow_count = 0;
628
629
HashSet<Instance *> decals;
630
HashSet<Instance *> reflection_probes;
631
HashSet<Instance *> voxel_gi_instances;
632
HashSet<Instance *> lightmap_captures;
633
634
InstanceGeometryData() {
635
can_cast_shadows = true;
636
material_is_animated = true;
637
}
638
};
639
640
struct InstanceReflectionProbeData : public InstanceBaseData {
641
Instance *owner = nullptr;
642
643
HashSet<Instance *> geometries;
644
645
RID instance;
646
SelfList<InstanceReflectionProbeData> update_list;
647
648
int render_step;
649
650
InstanceReflectionProbeData() :
651
update_list(this) {
652
render_step = -1;
653
}
654
};
655
656
struct InstanceDecalData : public InstanceBaseData {
657
Instance *owner = nullptr;
658
RID instance;
659
uint32_t cull_mask = 0xFFFFFFFF;
660
661
HashSet<Instance *> geometries;
662
663
InstanceDecalData() {
664
}
665
};
666
667
SelfList<InstanceReflectionProbeData>::List reflection_probe_render_list;
668
669
struct InstanceParticlesCollisionData : public InstanceBaseData {
670
RID instance;
671
uint32_t cull_mask = 0xFFFFFFFF;
672
};
673
674
struct InstanceFogVolumeData : public InstanceBaseData {
675
RID instance;
676
bool is_global;
677
};
678
679
struct InstanceVisibilityNotifierData : public InstanceBaseData {
680
bool just_visible = false;
681
uint64_t visible_in_frame = 0;
682
RID base;
683
SelfList<InstanceVisibilityNotifierData> list_element;
684
InstanceVisibilityNotifierData() :
685
list_element(this) {}
686
};
687
688
SpinLock visible_notifier_list_lock;
689
SelfList<InstanceVisibilityNotifierData>::List visible_notifier_list;
690
691
struct InstanceLightData : public InstanceBaseData {
692
RID instance;
693
uint64_t last_version;
694
List<Instance *>::Element *D; // directional light in scenario
695
696
bool uses_projector = false;
697
bool uses_softshadow = false;
698
699
HashSet<Instance *> geometries;
700
701
Instance *baked_light = nullptr;
702
703
RS::LightBakeMode bake_mode;
704
uint32_t max_sdfgi_cascade = 2;
705
uint32_t cull_mask = 0xFFFFFFFF;
706
707
private:
708
// Instead of a single dirty flag, we maintain a count
709
// so that we can detect lights that are being made dirty
710
// each frame, and switch on tighter caster culling.
711
int32_t shadow_dirty_count;
712
713
uint32_t light_update_frame_id;
714
bool light_intersects_multiple_cameras;
715
uint32_t light_intersects_multiple_cameras_timeout_frame_id;
716
717
public:
718
bool is_shadow_dirty() const { return shadow_dirty_count != 0; }
719
void make_shadow_dirty() { shadow_dirty_count = light_intersects_multiple_cameras ? 1 : 2; }
720
void detect_light_intersects_multiple_cameras(uint32_t p_frame_id) {
721
// We need to detect the case where shadow updates are occurring
722
// more than once per frame. In this case, we need to turn off
723
// tighter caster culling, so situation reverts to one full shadow update
724
// per frame (light_intersects_multiple_cameras is set).
725
if (p_frame_id == light_update_frame_id) {
726
light_intersects_multiple_cameras = true;
727
light_intersects_multiple_cameras_timeout_frame_id = p_frame_id + 60;
728
} else {
729
// When shadow_volume_intersects_multiple_cameras is set, we
730
// want to detect the situation this is no longer the case, via a timeout.
731
// The system can go back to tighter caster culling in this situation.
732
// Having a long-ish timeout prevents rapid cycling.
733
if (light_intersects_multiple_cameras && (p_frame_id >= light_intersects_multiple_cameras_timeout_frame_id)) {
734
light_intersects_multiple_cameras = false;
735
light_intersects_multiple_cameras_timeout_frame_id = UINT32_MAX;
736
}
737
}
738
light_update_frame_id = p_frame_id;
739
}
740
741
void decrement_shadow_dirty() {
742
shadow_dirty_count--;
743
DEV_ASSERT(shadow_dirty_count >= 0);
744
}
745
746
// Shadow updates can either full (everything in the shadow volume)
747
// or closely culled to the camera frustum.
748
bool is_shadow_update_full() const { return shadow_dirty_count == 0; }
749
750
InstanceLightData() {
751
bake_mode = RS::LIGHT_BAKE_DISABLED;
752
D = nullptr;
753
last_version = 0;
754
baked_light = nullptr;
755
756
shadow_dirty_count = 1;
757
light_update_frame_id = UINT32_MAX;
758
light_intersects_multiple_cameras_timeout_frame_id = UINT32_MAX;
759
light_intersects_multiple_cameras = false;
760
}
761
};
762
763
struct InstanceVoxelGIData : public InstanceBaseData {
764
Instance *owner = nullptr;
765
766
HashSet<Instance *> geometries;
767
HashSet<Instance *> dynamic_geometries;
768
769
HashSet<Instance *> lights;
770
771
struct LightCache {
772
RS::LightType type;
773
Transform3D transform;
774
Color color;
775
float energy;
776
float intensity;
777
float bake_energy;
778
float radius;
779
float attenuation;
780
float spot_angle;
781
float spot_attenuation;
782
bool has_shadow;
783
RS::LightDirectionalSkyMode sky_mode;
784
};
785
786
Vector<LightCache> light_cache;
787
Vector<RID> light_instances;
788
789
RID probe_instance;
790
791
bool invalid;
792
uint32_t base_version;
793
794
SelfList<InstanceVoxelGIData> update_element;
795
796
InstanceVoxelGIData() :
797
update_element(this) {
798
invalid = true;
799
base_version = 0;
800
}
801
};
802
803
SelfList<InstanceVoxelGIData>::List voxel_gi_update_list;
804
805
struct InstanceLightmapData : public InstanceBaseData {
806
RID instance;
807
HashSet<Instance *> geometries;
808
HashSet<Instance *> users;
809
810
InstanceLightmapData() {
811
}
812
};
813
814
mutable uint64_t pair_pass = 1;
815
816
struct PairInstances {
817
Instance *instance = nullptr;
818
PagedAllocator<InstancePair> *pair_allocator = nullptr;
819
SelfList<InstancePair>::List pairs_found;
820
DynamicBVH *bvh = nullptr;
821
DynamicBVH *bvh2 = nullptr; //some may need to cull in two
822
uint32_t pair_mask;
823
uint64_t pair_pass;
824
825
_FORCE_INLINE_ bool operator()(void *p_data) {
826
Instance *p_instance = (Instance *)p_data;
827
828
if (instance != p_instance && instance->transformed_aabb.intersects(p_instance->transformed_aabb) && (pair_mask & (1 << p_instance->base_type))) {
829
//test is more coarse in indexer
830
p_instance->pair_check = pair_pass;
831
InstancePair *pair = pair_allocator->alloc();
832
pair->a = instance;
833
pair->b = p_instance;
834
pairs_found.add(&pair->list_a);
835
}
836
return false;
837
}
838
839
void pair() {
840
if (bvh) {
841
bvh->aabb_query(instance->transformed_aabb, *this);
842
}
843
if (bvh2) {
844
bvh2->aabb_query(instance->transformed_aabb, *this);
845
}
846
while (instance->pairs.first()) {
847
InstancePair *pair = instance->pairs.first()->self();
848
Instance *other_instance = instance == pair->a ? pair->b : pair->a;
849
if (other_instance->pair_check != pair_pass) {
850
//unpaired
851
_instance_unpair(instance, other_instance);
852
} else {
853
//kept
854
other_instance->pair_check = 0; // if kept, then put pair check to zero, so we can distinguish with the newly added ones
855
}
856
857
pair_allocator->free(pair);
858
}
859
while (pairs_found.first()) {
860
InstancePair *pair = pairs_found.first()->self();
861
pairs_found.remove(pairs_found.first());
862
863
if (pair->b->pair_check == pair_pass) {
864
//paired
865
_instance_pair(instance, pair->b);
866
}
867
pair->a->pairs.add(&pair->list_a);
868
pair->b->pairs.add(&pair->list_b);
869
}
870
}
871
};
872
873
mutable HashSet<Instance *> heightfield_particle_colliders_update_list;
874
875
PagedArrayPool<Instance *> instance_cull_page_pool;
876
PagedArrayPool<RenderGeometryInstance *> geometry_instance_cull_page_pool;
877
PagedArrayPool<RID> rid_cull_page_pool;
878
879
PagedArray<Instance *> instance_cull_result;
880
PagedArray<Instance *> instance_shadow_cull_result;
881
882
struct InstanceCullResult {
883
PagedArray<RenderGeometryInstance *> geometry_instances;
884
PagedArray<Instance *> lights;
885
PagedArray<RID> light_instances;
886
PagedArray<RID> lightmaps;
887
PagedArray<RID> reflections;
888
PagedArray<RID> decals;
889
PagedArray<RID> voxel_gi_instances;
890
PagedArray<RID> mesh_instances;
891
PagedArray<RID> fog_volumes;
892
893
struct DirectionalShadow {
894
PagedArray<RenderGeometryInstance *> cascade_geometry_instances[RendererSceneRender::MAX_DIRECTIONAL_LIGHT_CASCADES];
895
} directional_shadows[RendererSceneRender::MAX_DIRECTIONAL_LIGHTS];
896
897
PagedArray<RenderGeometryInstance *> sdfgi_region_geometry_instances[SDFGI_MAX_CASCADES * SDFGI_MAX_REGIONS_PER_CASCADE];
898
PagedArray<RID> sdfgi_cascade_lights[SDFGI_MAX_CASCADES];
899
900
void clear() {
901
geometry_instances.clear();
902
lights.clear();
903
light_instances.clear();
904
lightmaps.clear();
905
reflections.clear();
906
decals.clear();
907
voxel_gi_instances.clear();
908
mesh_instances.clear();
909
fog_volumes.clear();
910
for (int i = 0; i < RendererSceneRender::MAX_DIRECTIONAL_LIGHTS; i++) {
911
for (int j = 0; j < RendererSceneRender::MAX_DIRECTIONAL_LIGHT_CASCADES; j++) {
912
directional_shadows[i].cascade_geometry_instances[j].clear();
913
}
914
}
915
916
for (int i = 0; i < SDFGI_MAX_CASCADES * SDFGI_MAX_REGIONS_PER_CASCADE; i++) {
917
sdfgi_region_geometry_instances[i].clear();
918
}
919
920
for (int i = 0; i < SDFGI_MAX_CASCADES; i++) {
921
sdfgi_cascade_lights[i].clear();
922
}
923
}
924
925
void reset() {
926
geometry_instances.reset();
927
lights.reset();
928
light_instances.reset();
929
lightmaps.reset();
930
reflections.reset();
931
decals.reset();
932
voxel_gi_instances.reset();
933
mesh_instances.reset();
934
fog_volumes.reset();
935
for (int i = 0; i < RendererSceneRender::MAX_DIRECTIONAL_LIGHTS; i++) {
936
for (int j = 0; j < RendererSceneRender::MAX_DIRECTIONAL_LIGHT_CASCADES; j++) {
937
directional_shadows[i].cascade_geometry_instances[j].reset();
938
}
939
}
940
941
for (int i = 0; i < SDFGI_MAX_CASCADES * SDFGI_MAX_REGIONS_PER_CASCADE; i++) {
942
sdfgi_region_geometry_instances[i].reset();
943
}
944
945
for (int i = 0; i < SDFGI_MAX_CASCADES; i++) {
946
sdfgi_cascade_lights[i].reset();
947
}
948
}
949
950
void append_from(InstanceCullResult &p_cull_result) {
951
geometry_instances.merge_unordered(p_cull_result.geometry_instances);
952
lights.merge_unordered(p_cull_result.lights);
953
light_instances.merge_unordered(p_cull_result.light_instances);
954
lightmaps.merge_unordered(p_cull_result.lightmaps);
955
reflections.merge_unordered(p_cull_result.reflections);
956
decals.merge_unordered(p_cull_result.decals);
957
voxel_gi_instances.merge_unordered(p_cull_result.voxel_gi_instances);
958
mesh_instances.merge_unordered(p_cull_result.mesh_instances);
959
fog_volumes.merge_unordered(p_cull_result.fog_volumes);
960
961
for (int i = 0; i < RendererSceneRender::MAX_DIRECTIONAL_LIGHTS; i++) {
962
for (int j = 0; j < RendererSceneRender::MAX_DIRECTIONAL_LIGHT_CASCADES; j++) {
963
directional_shadows[i].cascade_geometry_instances[j].merge_unordered(p_cull_result.directional_shadows[i].cascade_geometry_instances[j]);
964
}
965
}
966
967
for (int i = 0; i < SDFGI_MAX_CASCADES * SDFGI_MAX_REGIONS_PER_CASCADE; i++) {
968
sdfgi_region_geometry_instances[i].merge_unordered(p_cull_result.sdfgi_region_geometry_instances[i]);
969
}
970
971
for (int i = 0; i < SDFGI_MAX_CASCADES; i++) {
972
sdfgi_cascade_lights[i].merge_unordered(p_cull_result.sdfgi_cascade_lights[i]);
973
}
974
}
975
976
void init(PagedArrayPool<RID> *p_rid_pool, PagedArrayPool<RenderGeometryInstance *> *p_geometry_instance_pool, PagedArrayPool<Instance *> *p_instance_pool) {
977
geometry_instances.set_page_pool(p_geometry_instance_pool);
978
light_instances.set_page_pool(p_rid_pool);
979
lights.set_page_pool(p_instance_pool);
980
lightmaps.set_page_pool(p_rid_pool);
981
reflections.set_page_pool(p_rid_pool);
982
decals.set_page_pool(p_rid_pool);
983
voxel_gi_instances.set_page_pool(p_rid_pool);
984
mesh_instances.set_page_pool(p_rid_pool);
985
fog_volumes.set_page_pool(p_rid_pool);
986
for (int i = 0; i < RendererSceneRender::MAX_DIRECTIONAL_LIGHTS; i++) {
987
for (int j = 0; j < RendererSceneRender::MAX_DIRECTIONAL_LIGHT_CASCADES; j++) {
988
directional_shadows[i].cascade_geometry_instances[j].set_page_pool(p_geometry_instance_pool);
989
}
990
}
991
992
for (int i = 0; i < SDFGI_MAX_CASCADES * SDFGI_MAX_REGIONS_PER_CASCADE; i++) {
993
sdfgi_region_geometry_instances[i].set_page_pool(p_geometry_instance_pool);
994
}
995
996
for (int i = 0; i < SDFGI_MAX_CASCADES; i++) {
997
sdfgi_cascade_lights[i].set_page_pool(p_rid_pool);
998
}
999
}
1000
};
1001
1002
InstanceCullResult scene_cull_result;
1003
LocalVector<InstanceCullResult> scene_cull_result_threads;
1004
1005
RendererSceneRender::RenderShadowData render_shadow_data[MAX_UPDATE_SHADOWS];
1006
uint32_t max_shadows_used = 0;
1007
1008
RendererSceneRender::RenderSDFGIData render_sdfgi_data[SDFGI_MAX_CASCADES * SDFGI_MAX_REGIONS_PER_CASCADE];
1009
RendererSceneRender::RenderSDFGIUpdateData sdfgi_update_data;
1010
1011
uint32_t thread_cull_threshold = 200;
1012
1013
mutable RID_Owner<Instance, true> instance_owner{ 65536, 4194304 };
1014
1015
uint32_t geometry_instance_pair_mask = 0; // used in traditional forward, unnecessary on clustered
1016
1017
LocalVector<Vector2> camera_jitter_array;
1018
RenderingLightCuller *light_culler = nullptr;
1019
1020
virtual RID instance_allocate();
1021
virtual void instance_initialize(RID p_rid);
1022
1023
virtual void instance_set_base(RID p_instance, RID p_base);
1024
virtual void instance_set_scenario(RID p_instance, RID p_scenario);
1025
virtual void instance_set_layer_mask(RID p_instance, uint32_t p_mask);
1026
virtual void instance_set_pivot_data(RID p_instance, float p_sorting_offset, bool p_use_aabb_center);
1027
virtual void instance_set_transform(RID p_instance, const Transform3D &p_transform);
1028
virtual void instance_attach_object_instance_id(RID p_instance, ObjectID p_id);
1029
virtual void instance_set_blend_shape_weight(RID p_instance, int p_shape, float p_weight);
1030
virtual void instance_set_surface_override_material(RID p_instance, int p_surface, RID p_material);
1031
virtual void instance_set_visible(RID p_instance, bool p_visible);
1032
virtual void instance_geometry_set_transparency(RID p_instance, float p_transparency);
1033
1034
virtual void instance_teleport(RID p_instance);
1035
1036
virtual void instance_set_custom_aabb(RID p_instance, AABB p_aabb);
1037
1038
virtual void instance_attach_skeleton(RID p_instance, RID p_skeleton);
1039
1040
virtual void instance_set_extra_visibility_margin(RID p_instance, real_t p_margin);
1041
1042
virtual void instance_set_visibility_parent(RID p_instance, RID p_parent_instance);
1043
1044
virtual void instance_set_ignore_culling(RID p_instance, bool p_enabled);
1045
1046
bool _update_instance_visibility_depth(Instance *p_instance);
1047
void _update_instance_visibility_dependencies(Instance *p_instance) const;
1048
1049
// don't use these in a game!
1050
virtual Vector<ObjectID> instances_cull_aabb(const AABB &p_aabb, RID p_scenario = RID()) const;
1051
virtual Vector<ObjectID> instances_cull_ray(const Vector3 &p_from, const Vector3 &p_to, RID p_scenario = RID()) const;
1052
virtual Vector<ObjectID> instances_cull_convex(const Vector<Plane> &p_convex, RID p_scenario = RID()) const;
1053
1054
virtual void instance_geometry_set_flag(RID p_instance, RS::InstanceFlags p_flags, bool p_enabled);
1055
virtual void instance_geometry_set_cast_shadows_setting(RID p_instance, RS::ShadowCastingSetting p_shadow_casting_setting);
1056
virtual void instance_geometry_set_material_override(RID p_instance, RID p_material);
1057
virtual void instance_geometry_set_material_overlay(RID p_instance, RID p_material);
1058
1059
virtual void instance_geometry_set_visibility_range(RID p_instance, float p_min, float p_max, float p_min_margin, float p_max_margin, RS::VisibilityRangeFadeMode p_fade_mode);
1060
1061
virtual void instance_geometry_set_lightmap(RID p_instance, RID p_lightmap, const Rect2 &p_lightmap_uv_scale, int p_slice_index);
1062
virtual void instance_geometry_set_lod_bias(RID p_instance, float p_lod_bias);
1063
1064
virtual void instance_geometry_set_shader_parameter(RID p_instance, const StringName &p_parameter, const Variant &p_value);
1065
virtual void instance_geometry_get_shader_parameter_list(RID p_instance, List<PropertyInfo> *p_parameters) const;
1066
virtual Variant instance_geometry_get_shader_parameter(RID p_instance, const StringName &p_parameter) const;
1067
virtual Variant instance_geometry_get_shader_parameter_default_value(RID p_instance, const StringName &p_parameter) const;
1068
1069
virtual void mesh_generate_pipelines(RID p_mesh, bool p_background_compilation);
1070
virtual uint32_t get_pipeline_compilations(RS::PipelineSource p_source);
1071
1072
_FORCE_INLINE_ void _update_instance(Instance *p_instance) const;
1073
_FORCE_INLINE_ void _update_instance_aabb(Instance *p_instance) const;
1074
_FORCE_INLINE_ void _update_dirty_instance(Instance *p_instance) const;
1075
_FORCE_INLINE_ void _update_instance_lightmap_captures(Instance *p_instance) const;
1076
void _unpair_instance(Instance *p_instance);
1077
1078
void _light_instance_setup_directional_shadow(int p_shadow_index, Instance *p_instance, const Transform3D p_cam_transform, const Projection &p_cam_projection, bool p_cam_orthogonal, bool p_cam_vaspect);
1079
1080
_FORCE_INLINE_ bool _light_instance_update_shadow(Instance *p_instance, const Transform3D p_cam_transform, const Projection &p_cam_projection, bool p_cam_orthogonal, bool p_cam_vaspect, RID p_shadow_atlas, Scenario *p_scenario, float p_screen_mesh_lod_threshold, uint32_t p_visible_layers = 0xFFFFFF);
1081
1082
RID _render_get_environment(RID p_camera, RID p_scenario);
1083
RID _render_get_compositor(RID p_camera, RID p_scenario);
1084
1085
struct Cull {
1086
struct Shadow {
1087
RID light_instance;
1088
uint32_t caster_mask;
1089
struct Cascade {
1090
Frustum frustum;
1091
1092
Projection projection;
1093
Transform3D transform;
1094
real_t zfar;
1095
real_t split;
1096
real_t shadow_texel_size;
1097
real_t bias_scale;
1098
real_t range_begin;
1099
Vector2 uv_scale;
1100
1101
} cascades[RendererSceneRender::MAX_DIRECTIONAL_LIGHT_CASCADES]; //max 4 cascades
1102
uint32_t cascade_count;
1103
1104
} shadows[RendererSceneRender::MAX_DIRECTIONAL_LIGHTS];
1105
1106
uint32_t shadow_count;
1107
1108
struct SDFGI {
1109
//have arrays here because SDFGI functions expects this, plus regions can have areas
1110
AABB region_aabb[SDFGI_MAX_CASCADES * SDFGI_MAX_REGIONS_PER_CASCADE]; //max 3 regions per cascade
1111
uint32_t region_cascade[SDFGI_MAX_CASCADES * SDFGI_MAX_REGIONS_PER_CASCADE]; //max 3 regions per cascade
1112
uint32_t region_count = 0;
1113
1114
uint32_t cascade_light_index[SDFGI_MAX_CASCADES];
1115
uint32_t cascade_light_count = 0;
1116
1117
} sdfgi;
1118
1119
SpinLock lock;
1120
1121
Frustum frustum;
1122
} cull;
1123
1124
struct VisibilityCullData {
1125
uint64_t viewport_mask;
1126
Scenario *scenario = nullptr;
1127
Vector3 camera_position;
1128
uint32_t cull_offset;
1129
uint32_t cull_count;
1130
};
1131
1132
void _visibility_cull_threaded(uint32_t p_thread, VisibilityCullData *cull_data);
1133
void _visibility_cull(const VisibilityCullData &cull_data, uint64_t p_from, uint64_t p_to);
1134
template <bool p_fade_check>
1135
_FORCE_INLINE_ int _visibility_range_check(InstanceVisibilityData &r_vis_data, const Vector3 &p_camera_pos, uint64_t p_viewport_mask);
1136
1137
struct CullData {
1138
Cull *cull = nullptr;
1139
Scenario *scenario = nullptr;
1140
RID shadow_atlas;
1141
Transform3D cam_transform;
1142
uint32_t visible_layers;
1143
Instance *render_reflection_probe = nullptr;
1144
const RendererSceneOcclusionCull::HZBuffer *occlusion_buffer;
1145
const Projection *camera_matrix;
1146
uint64_t visibility_viewport_mask;
1147
};
1148
1149
void _scene_cull_threaded(uint32_t p_thread, CullData *cull_data);
1150
void _scene_cull(CullData &cull_data, InstanceCullResult &cull_result, uint64_t p_from, uint64_t p_to);
1151
static void _scene_particles_set_view_axis(RID p_particles, const Vector3 &p_axis, const Vector3 &p_up_axis);
1152
_FORCE_INLINE_ bool _visibility_parent_check(const CullData &p_cull_data, const InstanceData &p_instance_data);
1153
1154
bool _render_reflection_probe_step(Instance *p_instance, int p_step);
1155
1156
void _render_scene(const RendererSceneRender::CameraData *p_camera_data, const Ref<RenderSceneBuffers> &p_render_buffers, RID p_environment, RID p_force_camera_attributes, RID p_compositor, uint32_t p_visible_layers, RID p_scenario, RID p_viewport, RID p_shadow_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_mesh_lod_threshold, bool p_using_shadows = true, RenderInfo *r_render_info = nullptr);
1157
void render_empty_scene(const Ref<RenderSceneBuffers> &p_render_buffers, RID p_scenario, RID p_shadow_atlas);
1158
1159
void render_camera(const Ref<RenderSceneBuffers> &p_render_buffers, RID p_camera, RID p_scenario, RID p_viewport, Size2 p_viewport_size, uint32_t p_jitter_phase_count, float p_screen_mesh_lod_threshold, RID p_shadow_atlas, Ref<XRInterface> &p_xr_interface, RenderingMethod::RenderInfo *r_render_info = nullptr);
1160
void update_dirty_instances() const;
1161
1162
void render_particle_colliders();
1163
virtual void render_probes();
1164
1165
TypedArray<Image> bake_render_uv2(RID p_base, const TypedArray<RID> &p_material_overrides, const Size2i &p_image_size);
1166
1167
//pass to scene render
1168
1169
/* ENVIRONMENT API */
1170
1171
#ifdef PASSBASE
1172
#undef PASSBASE
1173
#endif
1174
1175
#define PASSBASE scene_render
1176
1177
PASS1(voxel_gi_set_quality, RS::VoxelGIQuality)
1178
1179
/* SKY API */
1180
1181
PASS0R(RID, sky_allocate)
1182
PASS1(sky_initialize, RID)
1183
1184
PASS2(sky_set_radiance_size, RID, int)
1185
PASS2(sky_set_mode, RID, RS::SkyMode)
1186
PASS2(sky_set_material, RID, RID)
1187
PASS4R(Ref<Image>, sky_bake_panorama, RID, float, bool, const Size2i &)
1188
1189
// Compositor effect
1190
1191
PASS0R(RID, compositor_effect_allocate)
1192
PASS1(compositor_effect_initialize, RID)
1193
1194
PASS1RC(bool, is_compositor_effect, RID)
1195
1196
PASS2(compositor_effect_set_enabled, RID, bool)
1197
PASS3(compositor_effect_set_callback, RID, RS::CompositorEffectCallbackType, const Callable &)
1198
PASS3(compositor_effect_set_flag, RID, RS::CompositorEffectFlags, bool)
1199
1200
// Compositor
1201
1202
PASS0R(RID, compositor_allocate)
1203
PASS1(compositor_initialize, RID)
1204
1205
PASS1RC(bool, is_compositor, RID)
1206
1207
PASS2(compositor_set_compositor_effects, RID, const TypedArray<RID> &)
1208
1209
// Environment
1210
1211
PASS0R(RID, environment_allocate)
1212
PASS1(environment_initialize, RID)
1213
1214
PASS1RC(bool, is_environment, RID)
1215
1216
// Background
1217
PASS2(environment_set_background, RID, RS::EnvironmentBG)
1218
PASS2(environment_set_sky, RID, RID)
1219
PASS2(environment_set_sky_custom_fov, RID, float)
1220
PASS2(environment_set_sky_orientation, RID, const Basis &)
1221
PASS2(environment_set_bg_color, RID, const Color &)
1222
PASS3(environment_set_bg_energy, RID, float, float)
1223
PASS2(environment_set_canvas_max_layer, RID, int)
1224
PASS6(environment_set_ambient_light, RID, const Color &, RS::EnvironmentAmbientSource, float, float, RS::EnvironmentReflectionSource)
1225
PASS2(environment_set_camera_feed_id, RID, int)
1226
1227
PASS1RC(RS::EnvironmentBG, environment_get_background, RID)
1228
PASS1RC(RID, environment_get_sky, RID)
1229
PASS1RC(float, environment_get_sky_custom_fov, RID)
1230
PASS1RC(Basis, environment_get_sky_orientation, RID)
1231
PASS1RC(Color, environment_get_bg_color, RID)
1232
PASS1RC(float, environment_get_bg_energy_multiplier, RID)
1233
PASS1RC(float, environment_get_bg_intensity, RID)
1234
PASS1RC(int, environment_get_canvas_max_layer, RID)
1235
PASS1RC(RS::EnvironmentAmbientSource, environment_get_ambient_source, RID)
1236
PASS1RC(Color, environment_get_ambient_light, RID)
1237
PASS1RC(float, environment_get_ambient_light_energy, RID)
1238
PASS1RC(float, environment_get_ambient_sky_contribution, RID)
1239
PASS1RC(RS::EnvironmentReflectionSource, environment_get_reflection_source, RID)
1240
1241
// Tonemap
1242
PASS4(environment_set_tonemap, RID, RS::EnvironmentToneMapper, float, float)
1243
PASS1RC(RS::EnvironmentToneMapper, environment_get_tone_mapper, RID)
1244
PASS1RC(float, environment_get_exposure, RID)
1245
PASS1RC(float, environment_get_white, RID)
1246
1247
// Fog
1248
PASS11(environment_set_fog, RID, bool, const Color &, float, float, float, float, float, float, float, RS::EnvironmentFogMode)
1249
1250
PASS1RC(bool, environment_get_fog_enabled, RID)
1251
PASS1RC(Color, environment_get_fog_light_color, RID)
1252
PASS1RC(float, environment_get_fog_light_energy, RID)
1253
PASS1RC(float, environment_get_fog_sun_scatter, RID)
1254
PASS1RC(float, environment_get_fog_density, RID)
1255
PASS1RC(float, environment_get_fog_sky_affect, RID)
1256
PASS1RC(float, environment_get_fog_height, RID)
1257
PASS1RC(float, environment_get_fog_height_density, RID)
1258
PASS1RC(float, environment_get_fog_aerial_perspective, RID)
1259
PASS1RC(RS::EnvironmentFogMode, environment_get_fog_mode, RID)
1260
1261
PASS2(environment_set_volumetric_fog_volume_size, int, int)
1262
PASS1(environment_set_volumetric_fog_filter_active, bool)
1263
1264
// Depth Fog
1265
PASS4(environment_set_fog_depth, RID, float, float, float)
1266
PASS1RC(float, environment_get_fog_depth_curve, RID)
1267
PASS1RC(float, environment_get_fog_depth_begin, RID)
1268
PASS1RC(float, environment_get_fog_depth_end, RID)
1269
1270
// Volumentric Fog
1271
PASS14(environment_set_volumetric_fog, RID, bool, float, const Color &, const Color &, float, float, float, float, float, bool, float, float, float)
1272
1273
PASS1RC(bool, environment_get_volumetric_fog_enabled, RID)
1274
PASS1RC(float, environment_get_volumetric_fog_density, RID)
1275
PASS1RC(Color, environment_get_volumetric_fog_scattering, RID)
1276
PASS1RC(Color, environment_get_volumetric_fog_emission, RID)
1277
PASS1RC(float, environment_get_volumetric_fog_emission_energy, RID)
1278
PASS1RC(float, environment_get_volumetric_fog_anisotropy, RID)
1279
PASS1RC(float, environment_get_volumetric_fog_length, RID)
1280
PASS1RC(float, environment_get_volumetric_fog_detail_spread, RID)
1281
PASS1RC(float, environment_get_volumetric_fog_gi_inject, RID)
1282
PASS1RC(float, environment_get_volumetric_fog_sky_affect, RID)
1283
PASS1RC(bool, environment_get_volumetric_fog_temporal_reprojection, RID)
1284
PASS1RC(float, environment_get_volumetric_fog_temporal_reprojection_amount, RID)
1285
PASS1RC(float, environment_get_volumetric_fog_ambient_inject, RID)
1286
1287
// Glow
1288
PASS13(environment_set_glow, RID, bool, Vector<float>, float, float, float, float, RS::EnvironmentGlowBlendMode, float, float, float, float, RID)
1289
1290
PASS1RC(bool, environment_get_glow_enabled, RID)
1291
PASS1RC(Vector<float>, environment_get_glow_levels, RID)
1292
PASS1RC(float, environment_get_glow_intensity, RID)
1293
PASS1RC(float, environment_get_glow_strength, RID)
1294
PASS1RC(float, environment_get_glow_bloom, RID)
1295
PASS1RC(float, environment_get_glow_mix, RID)
1296
PASS1RC(RS::EnvironmentGlowBlendMode, environment_get_glow_blend_mode, RID)
1297
PASS1RC(float, environment_get_glow_hdr_bleed_threshold, RID)
1298
PASS1RC(float, environment_get_glow_hdr_luminance_cap, RID)
1299
PASS1RC(float, environment_get_glow_hdr_bleed_scale, RID)
1300
PASS1RC(float, environment_get_glow_map_strength, RID)
1301
PASS1RC(RID, environment_get_glow_map, RID)
1302
1303
PASS1(environment_glow_set_use_bicubic_upscale, bool)
1304
1305
// SSR
1306
PASS6(environment_set_ssr, RID, bool, int, float, float, float)
1307
1308
PASS1RC(bool, environment_get_ssr_enabled, RID)
1309
PASS1RC(int, environment_get_ssr_max_steps, RID)
1310
PASS1RC(float, environment_get_ssr_fade_in, RID)
1311
PASS1RC(float, environment_get_ssr_fade_out, RID)
1312
PASS1RC(float, environment_get_ssr_depth_tolerance, RID)
1313
1314
PASS1(environment_set_ssr_roughness_quality, RS::EnvironmentSSRRoughnessQuality)
1315
1316
// SSAO
1317
PASS10(environment_set_ssao, RID, bool, float, float, float, float, float, float, float, float)
1318
1319
PASS1RC(bool, environment_get_ssao_enabled, RID)
1320
PASS1RC(float, environment_get_ssao_radius, RID)
1321
PASS1RC(float, environment_get_ssao_intensity, RID)
1322
PASS1RC(float, environment_get_ssao_power, RID)
1323
PASS1RC(float, environment_get_ssao_detail, RID)
1324
PASS1RC(float, environment_get_ssao_horizon, RID)
1325
PASS1RC(float, environment_get_ssao_sharpness, RID)
1326
PASS1RC(float, environment_get_ssao_direct_light_affect, RID)
1327
PASS1RC(float, environment_get_ssao_ao_channel_affect, RID)
1328
1329
PASS6(environment_set_ssao_quality, RS::EnvironmentSSAOQuality, bool, float, int, float, float)
1330
1331
// SSIL
1332
PASS6(environment_set_ssil, RID, bool, float, float, float, float)
1333
1334
PASS1RC(bool, environment_get_ssil_enabled, RID)
1335
PASS1RC(float, environment_get_ssil_radius, RID)
1336
PASS1RC(float, environment_get_ssil_intensity, RID)
1337
PASS1RC(float, environment_get_ssil_sharpness, RID)
1338
PASS1RC(float, environment_get_ssil_normal_rejection, RID)
1339
1340
PASS6(environment_set_ssil_quality, RS::EnvironmentSSILQuality, bool, float, int, float, float)
1341
1342
// SDFGI
1343
1344
PASS11(environment_set_sdfgi, RID, bool, int, float, RS::EnvironmentSDFGIYScale, bool, float, bool, float, float, float)
1345
1346
PASS1RC(bool, environment_get_sdfgi_enabled, RID)
1347
PASS1RC(int, environment_get_sdfgi_cascades, RID)
1348
PASS1RC(float, environment_get_sdfgi_min_cell_size, RID)
1349
PASS1RC(bool, environment_get_sdfgi_use_occlusion, RID)
1350
PASS1RC(float, environment_get_sdfgi_bounce_feedback, RID)
1351
PASS1RC(bool, environment_get_sdfgi_read_sky_light, RID)
1352
PASS1RC(float, environment_get_sdfgi_energy, RID)
1353
PASS1RC(float, environment_get_sdfgi_normal_bias, RID)
1354
PASS1RC(float, environment_get_sdfgi_probe_bias, RID)
1355
PASS1RC(RS::EnvironmentSDFGIYScale, environment_get_sdfgi_y_scale, RID)
1356
1357
PASS1(environment_set_sdfgi_ray_count, RS::EnvironmentSDFGIRayCount)
1358
PASS1(environment_set_sdfgi_frames_to_converge, RS::EnvironmentSDFGIFramesToConverge)
1359
PASS1(environment_set_sdfgi_frames_to_update_light, RS::EnvironmentSDFGIFramesToUpdateLight)
1360
1361
// Adjustment
1362
PASS7(environment_set_adjustment, RID, bool, float, float, float, bool, RID)
1363
1364
PASS1RC(bool, environment_get_adjustments_enabled, RID)
1365
PASS1RC(float, environment_get_adjustments_brightness, RID)
1366
PASS1RC(float, environment_get_adjustments_contrast, RID)
1367
PASS1RC(float, environment_get_adjustments_saturation, RID)
1368
PASS1RC(bool, environment_get_use_1d_color_correction, RID)
1369
PASS1RC(RID, environment_get_color_correction, RID)
1370
1371
PASS3R(Ref<Image>, environment_bake_panorama, RID, bool, const Size2i &)
1372
1373
PASS3(screen_space_roughness_limiter_set_active, bool, float, float)
1374
PASS1(sub_surface_scattering_set_quality, RS::SubSurfaceScatteringQuality)
1375
PASS2(sub_surface_scattering_set_scale, float, float)
1376
1377
PASS1(positional_soft_shadow_filter_set_quality, RS::ShadowQuality)
1378
PASS1(directional_soft_shadow_filter_set_quality, RS::ShadowQuality)
1379
1380
PASS2(sdfgi_set_debug_probe_select, const Vector3 &, const Vector3 &)
1381
1382
/* Render Buffers */
1383
1384
PASS0R(Ref<RenderSceneBuffers>, render_buffers_create)
1385
PASS1(gi_set_use_half_resolution, bool)
1386
1387
/* Misc */
1388
PASS1(set_debug_draw_mode, RS::ViewportDebugDraw)
1389
1390
PASS1(decals_set_filter, RS::DecalFilter)
1391
PASS1(light_projectors_set_filter, RS::LightProjectorFilter)
1392
PASS1(lightmaps_set_bicubic_filter, bool)
1393
1394
virtual void update();
1395
1396
bool free(RID p_rid);
1397
1398
void set_scene_render(RendererSceneRender *p_scene_render);
1399
1400
virtual void update_visibility_notifiers();
1401
1402
/* INTERPOLATION */
1403
1404
void update_interpolation_tick(bool p_process = true);
1405
void update_interpolation_frame(bool p_process = true);
1406
virtual void set_physics_interpolation_enabled(bool p_enabled);
1407
1408
struct InterpolationData {
1409
bool interpolation_enabled = false;
1410
} _interpolation_data;
1411
1412
RendererSceneCull();
1413
virtual ~RendererSceneCull();
1414
};
1415
1416