summaryrefslogtreecommitdiff
path: root/servers/rendering/renderer_scene_cull.h
diff options
context:
space:
mode:
Diffstat (limited to 'servers/rendering/renderer_scene_cull.h')
-rw-r--r--servers/rendering/renderer_scene_cull.h504
1 files changed, 444 insertions, 60 deletions
diff --git a/servers/rendering/renderer_scene_cull.h b/servers/rendering/renderer_scene_cull.h
index 8bf262d7c0..796fb14743 100644
--- a/servers/rendering/renderer_scene_cull.h
+++ b/servers/rendering/renderer_scene_cull.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -52,7 +52,9 @@ public:
RendererSceneRender *scene_render;
enum {
- SDFGI_MAX_CASCADES = 8
+ SDFGI_MAX_CASCADES = 8,
+ SDFGI_MAX_REGIONS_PER_CASCADE = 3,
+ MAX_INSTANCE_PAIRS = 32
};
uint64_t render_pass;
@@ -108,6 +110,156 @@ public:
struct Instance;
+ struct PlaneSign {
+ _ALWAYS_INLINE_ PlaneSign() {}
+ _ALWAYS_INLINE_ PlaneSign(const Plane &p_plane) {
+ if (p_plane.normal.x > 0) {
+ signs[0] = 0;
+ } else {
+ signs[0] = 3;
+ }
+ if (p_plane.normal.y > 0) {
+ signs[1] = 1;
+ } else {
+ signs[1] = 4;
+ }
+ if (p_plane.normal.z > 0) {
+ signs[2] = 2;
+ } else {
+ signs[2] = 5;
+ }
+ }
+
+ uint32_t signs[3];
+ };
+
+ struct Frustum {
+ Vector<Plane> planes;
+ Vector<PlaneSign> plane_signs;
+ const Plane *planes_ptr;
+ const PlaneSign *plane_signs_ptr;
+ uint32_t plane_count;
+
+ _ALWAYS_INLINE_ Frustum() {}
+ _ALWAYS_INLINE_ Frustum(const Frustum &p_frustum) {
+ planes = p_frustum.planes;
+ plane_signs = p_frustum.plane_signs;
+
+ planes_ptr = planes.ptr();
+ plane_signs_ptr = plane_signs.ptr();
+ plane_count = p_frustum.plane_count;
+ }
+ _ALWAYS_INLINE_ void operator=(const Frustum &p_frustum) {
+ planes = p_frustum.planes;
+ plane_signs = p_frustum.plane_signs;
+
+ planes_ptr = planes.ptr();
+ plane_signs_ptr = plane_signs.ptr();
+ plane_count = p_frustum.plane_count;
+ }
+ _ALWAYS_INLINE_ Frustum(const Vector<Plane> &p_planes) {
+ planes = p_planes;
+ planes_ptr = planes.ptrw();
+ plane_count = planes.size();
+ for (int i = 0; i < planes.size(); i++) {
+ PlaneSign ps(p_planes[i]);
+ plane_signs.push_back(ps);
+ }
+
+ plane_signs_ptr = plane_signs.ptr();
+ }
+ };
+
+ struct InstanceBounds {
+ // Efficiently store instance bounds.
+ // Because bounds checking is performed first,
+ // keep it separated from data.
+
+ real_t bounds[6];
+ _ALWAYS_INLINE_ InstanceBounds() {}
+
+ _ALWAYS_INLINE_ InstanceBounds(const AABB &p_aabb) {
+ bounds[0] = p_aabb.position.x;
+ bounds[1] = p_aabb.position.y;
+ bounds[2] = p_aabb.position.z;
+ bounds[3] = p_aabb.position.x + p_aabb.size.x;
+ bounds[4] = p_aabb.position.y + p_aabb.size.y;
+ bounds[5] = p_aabb.position.z + p_aabb.size.z;
+ }
+ _ALWAYS_INLINE_ bool in_frustum(const Frustum &p_frustum) const {
+ // This is not a full SAT check and the possibility of false positives exist,
+ // but the tradeoff vs performance is still very good.
+
+ for (uint32_t i = 0; i < p_frustum.plane_count; i++) {
+ Vector3 min(
+ bounds[p_frustum.plane_signs_ptr[i].signs[0]],
+ bounds[p_frustum.plane_signs_ptr[i].signs[1]],
+ bounds[p_frustum.plane_signs_ptr[i].signs[2]]);
+
+ if (p_frustum.planes_ptr[i].distance_to(min) >= 0.0) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ _ALWAYS_INLINE_ bool in_aabb(const AABB &p_aabb) const {
+ Vector3 end = p_aabb.position + p_aabb.size;
+
+ if (bounds[0] >= end.x) {
+ return false;
+ }
+ if (bounds[3] <= p_aabb.position.x) {
+ return false;
+ }
+ if (bounds[1] >= end.y) {
+ return false;
+ }
+ if (bounds[4] <= p_aabb.position.y) {
+ return false;
+ }
+ if (bounds[2] >= end.z) {
+ return false;
+ }
+ if (bounds[5] <= p_aabb.position.z) {
+ return false;
+ }
+
+ return true;
+ }
+ };
+
+ struct InstanceData {
+ // Store instance pointer as well as common instance processing information,
+ // to make processing more cache friendly.
+ enum Flags {
+ FLAG_BASE_TYPE_MASK = 0xFF,
+ FLAG_CAST_SHADOWS = (1 << 8),
+ FLAG_CAST_SHADOWS_ONLY = (1 << 9),
+ FLAG_REDRAW_IF_VISIBLE = (1 << 10),
+ FLAG_GEOM_LIGHTING_DIRTY = (1 << 11),
+ FLAG_GEOM_REFLECTION_DIRTY = (1 << 12),
+ FLAG_GEOM_DECAL_DIRTY = (1 << 13),
+ FLAG_GEOM_GI_PROBE_DIRTY = (1 << 14),
+ FLAG_LIGHTMAP_CAPTURE = (1 << 15),
+ FLAG_USES_BAKED_LIGHT = (1 << 16),
+ FLAG_USES_MESH_INSTANCE = (1 << 17),
+ FLAG_REFLECTION_PROBE_DIRTY = (1 << 18),
+ };
+
+ uint32_t flags = 0;
+ uint32_t layer_mask = 0; //for fast layer-mask discard
+ RID base_rid;
+ union {
+ uint64_t instance_data_rid;
+ RendererSceneRender::GeometryInstance *instance_geometry;
+ };
+ Instance *instance = nullptr;
+ };
+
+ PagedArrayPool<InstanceBounds> instance_aabb_page_pool;
+ PagedArrayPool<InstanceData> instance_data_page_pool;
+
struct Scenario {
enum IndexerType {
INDEXER_GEOMETRY, //for geometry
@@ -131,6 +283,9 @@ public:
LocalVector<RID> dynamic_lights;
+ PagedArray<InstanceBounds> instance_aabbs;
+ PagedArray<InstanceData> instance_data;
+
Scenario() {
indexers[INDEXER_GEOMETRY].set_index(INDEXER_GEOMETRY);
indexers[INDEXER_VOLUMES].set_index(INDEXER_VOLUMES);
@@ -145,7 +300,7 @@ public:
static void _instance_pair(Instance *p_A, Instance *p_B);
static void _instance_unpair(Instance *p_A, Instance *p_B);
- static void _instance_update_mesh_instance(Instance *p_instance);
+ void _instance_update_mesh_instance(Instance *p_instance);
virtual RID scenario_create();
@@ -174,10 +329,59 @@ public:
virtual ~InstanceBaseData() {}
};
- struct Instance : RendererSceneRender::InstanceBase {
+ struct Instance {
+ RS::InstanceType base_type;
+ RID base;
+
+ RID skeleton;
+ RID material_override;
+
+ RID mesh_instance; //only used for meshes and when skeleton/blendshapes exist
+
+ Transform transform;
+
+ float lod_bias;
+
+ Vector<RID> materials;
+
+ RS::ShadowCastingSetting cast_shadows;
+
+ uint32_t layer_mask;
+ //fit in 32 bits
+ bool mirror : 8;
+ bool receive_shadows : 8;
+ bool visible : 8;
+ bool baked_light : 2; //this flag is only to know if it actually did use baked light
+ bool dynamic_gi : 2; //same above for dynamic objects
+ bool redraw_if_visible : 4;
+
+ Instance *lightmap;
+ Rect2 lightmap_uv_scale;
+ int lightmap_slice_index;
+ uint32_t lightmap_cull_index;
+ Vector<Color> lightmap_sh; //spherical harmonic
+
+ AABB aabb;
+ AABB transformed_aabb;
+ AABB prev_transformed_aabb;
+
+ struct InstanceShaderParameter {
+ int32_t index = -1;
+ Variant value;
+ Variant default_value;
+ PropertyInfo info;
+ };
+
+ Map<StringName, InstanceShaderParameter> instance_shader_parameters;
+ bool instance_allocated_shader_parameters = false;
+ int32_t instance_allocated_shader_parameters_offset = -1;
+
+ //
+
RID self;
//scenario stuff
DynamicBVH::ID indexer_id;
+ int32_t array_index;
Scenario *scenario;
SelfList<Instance> scenario_item;
@@ -199,7 +403,6 @@ public:
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
- uint64_t last_render_pass;
uint64_t last_frame_pass;
uint64_t version; // changes to this, and changes to base increase version
@@ -209,23 +412,61 @@ public:
SelfList<InstancePair>::List pairs;
uint64_t pair_check;
- virtual void dependency_deleted(RID p_dependency) {
- if (p_dependency == base) {
- singleton->instance_set_base(self, RID());
- } else if (p_dependency == skeleton) {
- singleton->instance_attach_skeleton(self, RID());
- } else {
- singleton->_instance_queue_update(this, false, true);
+ RendererStorage::DependencyTracker dependency_tracker;
+
+ static void dependency_changed(RendererStorage::DependencyChangedNotification p_notification, RendererStorage::DependencyTracker *tracker) {
+ Instance *instance = (Instance *)tracker->userdata;
+ switch (p_notification) {
+ case RendererStorage::DEPENDENCY_CHANGED_SKELETON_DATA:
+ case RendererStorage::DEPENDENCY_CHANGED_AABB: {
+ singleton->_instance_queue_update(instance, true, false);
+
+ } break;
+ case RendererStorage::DEPENDENCY_CHANGED_MATERIAL: {
+ singleton->_instance_queue_update(instance, false, true);
+ } break;
+ case RendererStorage::DEPENDENCY_CHANGED_MESH:
+ case RendererStorage::DEPENDENCY_CHANGED_MULTIMESH:
+ case RendererStorage::DEPENDENCY_CHANGED_DECAL:
+ case RendererStorage::DEPENDENCY_CHANGED_LIGHT:
+ case RendererStorage::DEPENDENCY_CHANGED_REFLECTION_PROBE: {
+ singleton->_instance_queue_update(instance, true, true);
+ } break;
+ case RendererStorage::DEPENDENCY_CHANGED_MULTIMESH_VISIBLE_INSTANCES:
+ case RendererStorage::DEPENDENCY_CHANGED_SKELETON_BONES: {
+ //ignored
+ } break;
}
}
- virtual void dependency_changed(bool p_aabb, bool p_dependencies) {
- singleton->_instance_queue_update(this, p_aabb, p_dependencies);
+ static void dependency_deleted(const RID &p_dependency, RendererStorage::DependencyTracker *tracker) {
+ Instance *instance = (Instance *)tracker->userdata;
+
+ if (p_dependency == instance->base) {
+ singleton->instance_set_base(instance->self, RID());
+ } else if (p_dependency == instance->skeleton) {
+ singleton->instance_attach_skeleton(instance->self, RID());
+ } else {
+ singleton->_instance_queue_update(instance, false, true);
+ }
}
Instance() :
scenario_item(this),
update_item(this) {
+ base_type = RS::INSTANCE_NONE;
+ cast_shadows = RS::SHADOW_CASTING_SETTING_ON;
+ receive_shadows = true;
+ visible = true;
+ layer_mask = 1;
+ baked_light = false;
+ dynamic_gi = false;
+ redraw_if_visible = false;
+ lightmap_slice_index = 0;
+ lightmap = nullptr;
+ lightmap_cull_index = 0;
+ lod_bias = 1.0;
+
scenario = nullptr;
update_aabb = false;
@@ -240,7 +481,6 @@ public:
lod_begin_hysteresis = 0;
lod_end_hysteresis = 0;
- last_render_pass = 0;
last_frame_pass = 0;
version = 1;
base_data = nullptr;
@@ -248,6 +488,11 @@ public:
custom_aabb = nullptr;
pair_check = 0;
+ array_index = -1;
+
+ dependency_tracker.userdata = this;
+ dependency_tracker.changed_callback = dependency_changed;
+ dependency_tracker.deleted_callback = dependency_deleted;
}
~Instance() {
@@ -264,29 +509,19 @@ public:
void _instance_queue_update(Instance *p_instance, bool p_update_aabb, bool p_update_dependencies = false);
struct InstanceGeometryData : public InstanceBaseData {
+ RendererSceneRender::GeometryInstance *geometry_instance = nullptr;
Set<Instance *> lights;
- bool lighting_dirty;
bool can_cast_shadows;
bool material_is_animated;
Set<Instance *> decals;
- bool decal_dirty;
-
Set<Instance *> reflection_probes;
- bool reflection_dirty;
-
Set<Instance *> gi_probes;
- bool gi_probes_dirty;
-
Set<Instance *> lightmap_captures;
InstanceGeometryData() {
- lighting_dirty = false;
- reflection_dirty = true;
can_cast_shadows = true;
material_is_animated = true;
- gi_probes_dirty = true;
- decal_dirty = true;
}
};
@@ -296,14 +531,12 @@ public:
Set<Instance *> geometries;
RID instance;
- bool reflection_dirty;
SelfList<InstanceReflectionProbeData> update_list;
int render_step;
InstanceReflectionProbeData() :
update_list(this) {
- reflection_dirty = true;
render_step = -1;
}
};
@@ -320,6 +553,10 @@ public:
SelfList<InstanceReflectionProbeData>::List reflection_probe_render_list;
+ struct InstanceParticlesCollisionData : public InstanceBaseData {
+ RID instance;
+ };
+
struct InstanceLightData : public InstanceBaseData {
RID instance;
uint64_t last_version;
@@ -334,8 +571,6 @@ public:
RS::LightBakeMode bake_mode;
uint32_t max_sdfgi_cascade = 2;
- uint64_t sdfgi_cascade_light_pass = 0;
-
InstanceLightData() {
bake_mode = RS::LIGHT_BAKE_DISABLED;
shadow_dirty = true;
@@ -387,6 +622,7 @@ public:
SelfList<InstanceGIProbeData>::List gi_probe_update_list;
struct InstanceLightmapData : public InstanceBaseData {
+ RID instance;
Set<Instance *> geometries;
Set<Instance *> users;
@@ -452,44 +688,138 @@ public:
}
};
- struct CullResult {
- PagedArray<Instance *> *result;
- _FORCE_INLINE_ bool operator()(void *p_data) {
- Instance *p_instance = (Instance *)p_data;
- result->push_back(p_instance);
- return false;
- }
- };
-
Set<Instance *> heightfield_particle_colliders_update_list;
PagedArrayPool<Instance *> instance_cull_page_pool;
- PagedArrayPool<RendererSceneRender::InstanceBase *> base_instance_cull_page_pool;
+ PagedArrayPool<RendererSceneRender::GeometryInstance *> geometry_instance_cull_page_pool;
PagedArrayPool<RID> rid_cull_page_pool;
PagedArray<Instance *> instance_cull_result;
- PagedArray<RendererSceneRender::InstanceBase *> geometry_instances_to_render;
PagedArray<Instance *> instance_shadow_cull_result;
- PagedArray<RendererSceneRender::InstanceBase *> geometry_instances_to_shadow_render;
- PagedArray<Instance *> instance_sdfgi_cull_result;
- PagedArray<RendererSceneRender::InstanceBase *> geometry_instances_to_sdfgi_render;
- PagedArray<Instance *> light_cull_result;
- PagedArray<RendererSceneRender::InstanceBase *> lightmap_cull_result;
- PagedArray<Instance *> directional_shadow_cull_result;
- PagedArray<RID> reflection_probe_instance_cull_result;
- PagedArray<RID> light_instance_cull_result;
- PagedArray<RID> directional_light_cull_result;
- PagedArray<RID> gi_probe_instance_cull_result;
- PagedArray<RID> decal_instance_cull_result;
-
- PagedArray<RID> sdfgi_cascade_lights[SDFGI_MAX_CASCADES];
-
- uint64_t sdfgi_light_cull_pass = 0;
- int directional_light_count;
+ PagedArray<RendererSceneRender::GeometryInstance *> geometry_instances_to_shadow_render;
+
+ struct FrustumCullResult {
+ PagedArray<RendererSceneRender::GeometryInstance *> geometry_instances;
+ PagedArray<Instance *> lights;
+ PagedArray<RID> light_instances;
+ PagedArray<RID> lightmaps;
+ PagedArray<RID> reflections;
+ PagedArray<RID> decals;
+ PagedArray<RID> gi_probes;
+ PagedArray<RID> mesh_instances;
+
+ struct DirectionalShadow {
+ PagedArray<RendererSceneRender::GeometryInstance *> cascade_geometry_instances[RendererSceneRender::MAX_DIRECTIONAL_LIGHT_CASCADES];
+ } directional_shadows[RendererSceneRender::MAX_DIRECTIONAL_LIGHTS];
+
+ PagedArray<RendererSceneRender::GeometryInstance *> sdfgi_region_geometry_instances[SDFGI_MAX_CASCADES * SDFGI_MAX_REGIONS_PER_CASCADE];
+ PagedArray<RID> sdfgi_cascade_lights[SDFGI_MAX_CASCADES];
+
+ void clear() {
+ geometry_instances.clear();
+ lights.clear();
+ light_instances.clear();
+ lightmaps.clear();
+ reflections.clear();
+ decals.clear();
+ gi_probes.clear();
+ mesh_instances.clear();
+ for (int i = 0; i < RendererSceneRender::MAX_DIRECTIONAL_LIGHTS; i++) {
+ for (int j = 0; j < RendererSceneRender::MAX_DIRECTIONAL_LIGHT_CASCADES; j++) {
+ directional_shadows[i].cascade_geometry_instances[j].clear();
+ }
+ }
+
+ for (int i = 0; i < SDFGI_MAX_CASCADES * SDFGI_MAX_REGIONS_PER_CASCADE; i++) {
+ sdfgi_region_geometry_instances[i].clear();
+ }
+
+ for (int i = 0; i < SDFGI_MAX_CASCADES; i++) {
+ sdfgi_cascade_lights[i].clear();
+ }
+ }
+
+ void reset() {
+ geometry_instances.reset();
+ lights.reset();
+ light_instances.reset();
+ lightmaps.reset();
+ reflections.reset();
+ decals.reset();
+ gi_probes.reset();
+ mesh_instances.reset();
+ for (int i = 0; i < RendererSceneRender::MAX_DIRECTIONAL_LIGHTS; i++) {
+ for (int j = 0; j < RendererSceneRender::MAX_DIRECTIONAL_LIGHT_CASCADES; j++) {
+ directional_shadows[i].cascade_geometry_instances[j].reset();
+ }
+ }
+
+ for (int i = 0; i < SDFGI_MAX_CASCADES * SDFGI_MAX_REGIONS_PER_CASCADE; i++) {
+ sdfgi_region_geometry_instances[i].reset();
+ }
+
+ for (int i = 0; i < SDFGI_MAX_CASCADES; i++) {
+ sdfgi_cascade_lights[i].reset();
+ }
+ }
+
+ void append_from(FrustumCullResult &p_cull_result) {
+ geometry_instances.merge_unordered(p_cull_result.geometry_instances);
+ lights.merge_unordered(p_cull_result.lights);
+ light_instances.merge_unordered(p_cull_result.light_instances);
+ lightmaps.merge_unordered(p_cull_result.lightmaps);
+ reflections.merge_unordered(p_cull_result.reflections);
+ decals.merge_unordered(p_cull_result.decals);
+ gi_probes.merge_unordered(p_cull_result.gi_probes);
+ mesh_instances.merge_unordered(p_cull_result.mesh_instances);
+
+ for (int i = 0; i < RendererSceneRender::MAX_DIRECTIONAL_LIGHTS; i++) {
+ for (int j = 0; j < RendererSceneRender::MAX_DIRECTIONAL_LIGHT_CASCADES; j++) {
+ directional_shadows[i].cascade_geometry_instances[j].merge_unordered(p_cull_result.directional_shadows[i].cascade_geometry_instances[j]);
+ }
+ }
+
+ for (int i = 0; i < SDFGI_MAX_CASCADES * SDFGI_MAX_REGIONS_PER_CASCADE; i++) {
+ sdfgi_region_geometry_instances[i].merge_unordered(p_cull_result.sdfgi_region_geometry_instances[i]);
+ }
+
+ for (int i = 0; i < SDFGI_MAX_CASCADES; i++) {
+ sdfgi_cascade_lights[i].merge_unordered(p_cull_result.sdfgi_cascade_lights[i]);
+ }
+ }
+
+ void init(PagedArrayPool<RID> *p_rid_pool, PagedArrayPool<RendererSceneRender::GeometryInstance *> *p_geometry_instance_pool, PagedArrayPool<Instance *> *p_instance_pool) {
+ geometry_instances.set_page_pool(p_geometry_instance_pool);
+ light_instances.set_page_pool(p_rid_pool);
+ lights.set_page_pool(p_instance_pool);
+ lightmaps.set_page_pool(p_rid_pool);
+ reflections.set_page_pool(p_rid_pool);
+ decals.set_page_pool(p_rid_pool);
+ mesh_instances.set_page_pool(p_rid_pool);
+ for (int i = 0; i < RendererSceneRender::MAX_DIRECTIONAL_LIGHTS; i++) {
+ for (int j = 0; j < RendererSceneRender::MAX_DIRECTIONAL_LIGHT_CASCADES; j++) {
+ directional_shadows[i].cascade_geometry_instances[j].set_page_pool(p_geometry_instance_pool);
+ }
+ }
+
+ for (int i = 0; i < SDFGI_MAX_CASCADES * SDFGI_MAX_REGIONS_PER_CASCADE; i++) {
+ sdfgi_region_geometry_instances[i].set_page_pool(p_geometry_instance_pool);
+ }
+
+ for (int i = 0; i < SDFGI_MAX_CASCADES; i++) {
+ sdfgi_cascade_lights[i].set_page_pool(p_rid_pool);
+ }
+ }
+ };
+
+ FrustumCullResult frustum_cull_result;
+ LocalVector<FrustumCullResult> frustum_cull_result_threads;
+
+ uint32_t thread_cull_threshold = 200;
RID_PtrOwner<Instance> instance_owner;
- bool pair_volumes_to_mesh; // used in traditional forward, unnecesary on clustered
+ uint32_t geometry_instance_pair_mask; // used in traditional forward, unnecesary on clustered
virtual RID instance_create();
@@ -523,7 +853,7 @@ public:
virtual void instance_geometry_set_lightmap(RID p_instance, RID p_lightmap, const Rect2 &p_lightmap_uv_scale, int p_slice_index);
virtual void instance_geometry_set_lod_bias(RID p_instance, float p_lod_bias);
- void _update_instance_shader_parameters_from_material(Map<StringName, RendererSceneRender::InstanceBase::InstanceShaderParameter> &isparams, const Map<StringName, RendererSceneRender::InstanceBase::InstanceShaderParameter> &existing_isparams, RID p_material);
+ void _update_instance_shader_parameters_from_material(Map<StringName, Instance::InstanceShaderParameter> &isparams, const Map<StringName, Instance::InstanceShaderParameter> &existing_isparams, RID p_material);
virtual void instance_geometry_set_shader_parameter(RID p_instance, const StringName &p_parameter, const Variant &p_value);
virtual void instance_geometry_get_shader_parameter_list(RID p_instance, List<PropertyInfo> *p_parameters) const;
@@ -536,10 +866,62 @@ public:
_FORCE_INLINE_ void _update_instance_lightmap_captures(Instance *p_instance);
void _unpair_instance(Instance *p_instance);
+ void _light_instance_setup_directional_shadow(int p_shadow_index, Instance *p_instance, const Transform p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, bool p_cam_vaspect);
+
_FORCE_INLINE_ bool _light_instance_update_shadow(Instance *p_instance, const Transform p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, bool p_cam_vaspect, RID p_shadow_atlas, Scenario *p_scenario, float p_scren_lod_threshold);
RID _render_get_environment(RID p_camera, RID p_scenario);
+ struct Cull {
+ struct Shadow {
+ RID light_instance;
+ struct Cascade {
+ Frustum frustum;
+
+ CameraMatrix projection;
+ Transform transform;
+ real_t zfar;
+ real_t split;
+ real_t shadow_texel_size;
+ real_t bias_scale;
+ real_t range_begin;
+ Vector2 uv_scale;
+
+ } cascades[RendererSceneRender::MAX_DIRECTIONAL_LIGHT_CASCADES]; //max 4 cascades
+ uint32_t cascade_count;
+
+ } shadows[RendererSceneRender::MAX_DIRECTIONAL_LIGHTS];
+
+ uint32_t shadow_count;
+
+ struct SDFGI {
+ //have arrays here because SDFGI functions expects this, plus regions can have areas
+ AABB region_aabb[SDFGI_MAX_CASCADES * SDFGI_MAX_REGIONS_PER_CASCADE]; //max 3 regions per cascade
+ uint32_t region_cascade[SDFGI_MAX_CASCADES * SDFGI_MAX_REGIONS_PER_CASCADE]; //max 3 regions per cascade
+ uint32_t region_count = 0;
+
+ uint32_t cascade_light_index[SDFGI_MAX_CASCADES];
+ uint32_t cascade_light_count = 0;
+
+ } sdfgi;
+
+ SpinLock lock;
+
+ Frustum frustum;
+ } cull;
+
+ struct FrustumCullData {
+ Cull *cull;
+ Scenario *scenario;
+ RID shadow_atlas;
+ Transform cam_transform;
+ uint32_t visible_layers;
+ Instance *render_reflection_probe;
+ };
+
+ void _frustum_cull_threaded(uint32_t p_thread, FrustumCullData *cull_data);
+ void _frustum_cull(FrustumCullData &cull_data, FrustumCullResult &cull_result, uint64_t p_from, uint64_t p_to);
+
bool _render_reflection_probe_step(Instance *p_instance, int p_step);
void _prepare_scene(const Transform p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, bool p_cam_vaspect, RID p_render_buffers, RID p_environment, uint32_t p_visible_layers, RID p_scenario, RID p_shadow_atlas, RID p_reflection_probe, float p_screen_lod_threshold, bool p_using_shadows = true);
void _render_scene(RID p_render_buffers, const Transform p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, RID p_environment, RID p_force_camera_effects, RID p_scenario, RID p_shadow_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_lod_threshold);
@@ -654,6 +1036,8 @@ public:
bool free(RID p_rid);
+ void set_scene_render(RendererSceneRender *p_scene_render);
+
RendererSceneCull();
virtual ~RendererSceneCull();
};