summaryrefslogtreecommitdiff
path: root/servers/visual/visual_server_scene.h
diff options
context:
space:
mode:
Diffstat (limited to 'servers/visual/visual_server_scene.h')
-rw-r--r--servers/visual/visual_server_scene.h172
1 files changed, 38 insertions, 134 deletions
diff --git a/servers/visual/visual_server_scene.h b/servers/visual/visual_server_scene.h
index a174d9e616..a811e8b27a 100644
--- a/servers/visual/visual_server_scene.h
+++ b/servers/visual/visual_server_scene.h
@@ -37,6 +37,7 @@
#include "core/math/octree.h"
#include "core/os/semaphore.h"
#include "core/os/thread.h"
+#include "core/rid_owner.h"
#include "core/self_list.h"
#include "servers/arvr/arvr_interface.h"
@@ -47,6 +48,7 @@ public:
MAX_INSTANCE_CULL = 65536,
MAX_LIGHTS_CULLED = 4096,
MAX_REFLECTION_PROBES_CULLED = 4096,
+ MAX_GI_PROBES_CULLED = 4096,
MAX_ROOM_CULL = 32,
MAX_EXTERIOR_PORTALS = 128,
};
@@ -57,7 +59,7 @@ public:
/* CAMERA API */
- struct Camera : public RID_Data {
+ struct Camera {
enum Type {
PERSPECTIVE,
@@ -72,6 +74,7 @@ public:
uint32_t visible_layers;
bool vaspect;
RID env;
+ RID effects;
Transform transform;
@@ -88,7 +91,7 @@ public:
}
};
- mutable RID_Owner<Camera> camera_owner;
+ mutable RID_PtrOwner<Camera> camera_owner;
virtual RID camera_create();
virtual void camera_set_perspective(RID p_camera, float p_fovy_degrees, float p_z_near, float p_z_far);
@@ -97,13 +100,14 @@ public:
virtual void camera_set_transform(RID p_camera, const Transform &p_transform);
virtual void camera_set_cull_mask(RID p_camera, uint32_t p_layers);
virtual void camera_set_environment(RID p_camera, RID p_env);
+ virtual void camera_set_camera_effects(RID p_camera, RID p_fx);
virtual void camera_set_use_vertical_aspect(RID p_camera, bool p_enable);
/* SCENARIO API */
struct Instance;
- struct Scenario : RID_Data {
+ struct Scenario {
VS::ScenarioDebugMode debug;
RID self;
@@ -113,6 +117,7 @@ public:
List<Instance *> directional_lights;
RID environment;
RID fallback_environment;
+ RID camera_effects;
RID reflection_probe_shadow_atlas;
RID reflection_atlas;
@@ -121,7 +126,7 @@ public:
Scenario() { debug = VS::SCENARIO_DEBUG_DISABLED; }
};
- mutable RID_Owner<Scenario> scenario_owner;
+ mutable RID_PtrOwner<Scenario> scenario_owner;
static void *_instance_pair(void *p_self, OctreeElementID, Instance *p_A, int, OctreeElementID, Instance *p_B, int);
static void _instance_unpair(void *p_self, OctreeElementID, Instance *p_A, int, OctreeElementID, Instance *p_B, int, void *);
@@ -130,8 +135,9 @@ public:
virtual void scenario_set_debug(RID p_scenario, VS::ScenarioDebugMode p_debug_mode);
virtual void scenario_set_environment(RID p_scenario, RID p_environment);
+ virtual void scenario_set_camera_effects(RID p_scenario, RID p_fx);
virtual void scenario_set_fallback_environment(RID p_scenario, RID p_environment);
- virtual void scenario_set_reflection_atlas_size(RID p_scenario, int p_size, int p_subdiv);
+ virtual void scenario_set_reflection_atlas_size(RID p_scenario, int p_reflection_size, int p_reflection_count);
/* INSTANCING API */
@@ -150,12 +156,10 @@ public:
//aabb stuff
bool update_aabb;
- bool update_materials;
+ bool update_dependencies;
SelfList<Instance> update_item;
- AABB aabb;
- AABB transformed_aabb;
AABB *custom_aabb; // <Zylann> would using aabb directly with a bool be better?
float extra_margin;
uint32_t object_id;
@@ -173,14 +177,18 @@ public:
InstanceBaseData *base_data;
- virtual void base_removed() {
-
- singleton->instance_set_base(self, RID());
+ 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);
+ }
}
- virtual void base_changed(bool p_aabb, bool p_materials) {
-
- singleton->_instance_queue_update(this, p_aabb, p_materials);
+ virtual void dependency_changed(bool p_aabb, bool p_dependencies) {
+ singleton->_instance_queue_update(this, p_aabb, p_dependencies);
}
Instance() :
@@ -191,7 +199,7 @@ public:
scenario = NULL;
update_aabb = false;
- update_materials = false;
+ update_dependencies = false;
extra_margin = 0;
@@ -221,7 +229,7 @@ public:
};
SelfList<Instance>::List _instance_update_list;
- void _instance_queue_update(Instance *p_instance, bool p_update_aabb, bool p_update_materials = false);
+ void _instance_queue_update(Instance *p_instance, bool p_update_aabb, bool p_update_dependencies = false);
struct InstanceGeometryData : public InstanceBaseData {
@@ -310,6 +318,7 @@ public:
};
List<PairInfo> geometries;
+ List<PairInfo> dynamic_geometries;
Set<Instance *> lights;
@@ -319,77 +328,16 @@ public:
Transform transform;
Color color;
float energy;
+ float bake_energy;
float radius;
float attenuation;
float spot_angle;
float spot_attenuation;
- bool visible;
-
- bool operator==(const LightCache &p_cache) {
-
- return (type == p_cache.type &&
- transform == p_cache.transform &&
- color == p_cache.color &&
- energy == p_cache.energy &&
- radius == p_cache.radius &&
- attenuation == p_cache.attenuation &&
- spot_angle == p_cache.spot_angle &&
- spot_attenuation == p_cache.spot_attenuation &&
- visible == p_cache.visible);
- }
-
- bool operator!=(const LightCache &p_cache) {
-
- return !operator==(p_cache);
- }
-
- LightCache() {
-
- type = VS::LIGHT_DIRECTIONAL;
- energy = 1.0;
- radius = 1.0;
- attenuation = 1.0;
- spot_angle = 1.0;
- spot_attenuation = 1.0;
- visible = true;
- }
- };
-
- struct LocalData {
- uint16_t pos[3];
- uint16_t energy[3]; //using 0..1024 for float range 0..1. integer is needed for deterministic add/remove of lights
- };
-
- struct CompBlockS3TC {
- uint32_t offset; //offset in mipmap
- uint32_t source_count; //sources
- uint32_t sources[16]; //id for each source
- uint8_t alpha[8]; //alpha block is pre-computed
+ bool has_shadow;
};
- struct Dynamic {
-
- Map<RID, LightCache> light_cache;
- Map<RID, LightCache> light_cache_changes;
- PoolVector<int> light_data;
- PoolVector<LocalData> local_data;
- Vector<Vector<uint32_t> > level_cell_lists;
- RID probe_data;
- bool enabled;
- int bake_dynamic_range;
- RasterizerStorage::GIProbeCompression compression;
-
- Vector<PoolVector<uint8_t> > mipmaps_3d;
- Vector<PoolVector<CompBlockS3TC> > mipmaps_s3tc; //for s3tc
-
- int updating_stage;
- float propagate;
-
- int grid_size[3];
-
- Transform light_to_cell_xform;
-
- } dynamic;
+ Vector<LightCache> light_cache;
+ Vector<RID> light_instances;
RID probe_instance;
@@ -402,7 +350,6 @@ public:
update_element(this) {
invalid = true;
base_version = 0;
- dynamic.updating_stage = GI_UPDATE_STAGE_CHECK;
}
};
@@ -431,8 +378,10 @@ public:
int directional_light_count;
RID reflection_probe_instance_cull_result[MAX_REFLECTION_PROBES_CULLED];
int reflection_probe_cull_count;
+ RID gi_probe_instance_cull_result[MAX_GI_PROBES_CULLED];
+ int gi_probe_cull_count;
- RID_Owner<Instance> instance_owner;
+ RID_PtrOwner<Instance> instance_owner;
virtual RID instance_create();
@@ -472,60 +421,15 @@ public:
_FORCE_INLINE_ bool _light_instance_update_shadow(Instance *p_instance, const Transform p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, RID p_shadow_atlas, Scenario *p_scenario);
- void _prepare_scene(const Transform p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, RID p_force_environment, uint32_t p_visible_layers, RID p_scenario, RID p_shadow_atlas, RID p_reflection_probe);
- void _render_scene(const Transform p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, RID p_force_environment, RID p_scenario, RID p_shadow_atlas, RID p_reflection_probe, int p_reflection_probe_pass);
- void render_empty_scene(RID p_scenario, RID p_shadow_atlas);
+ 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, RID p_force_environment, RID p_force_camera_effects, uint32_t p_visible_layers, RID p_scenario, RID p_shadow_atlas, RID p_reflection_probe, 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_force_environment, RID p_force_camera_effects, RID p_scenario, RID p_shadow_atlas, RID p_reflection_probe, int p_reflection_probe_pass);
+ void render_empty_scene(RID p_render_buffers, RID p_scenario, RID p_shadow_atlas);
- void render_camera(RID p_camera, RID p_scenario, Size2 p_viewport_size, RID p_shadow_atlas);
- void render_camera(Ref<ARVRInterface> &p_interface, ARVRInterface::Eyes p_eye, RID p_camera, RID p_scenario, Size2 p_viewport_size, RID p_shadow_atlas);
+ void render_camera(RID p_render_buffers, RID p_camera, RID p_scenario, Size2 p_viewport_size, RID p_shadow_atlas);
+ void render_camera(RID p_render_buffers, Ref<ARVRInterface> &p_interface, ARVRInterface::Eyes p_eye, RID p_camera, RID p_scenario, Size2 p_viewport_size, RID p_shadow_atlas);
void update_dirty_instances();
- //probes
- struct GIProbeDataHeader {
-
- uint32_t version;
- uint32_t cell_subdiv;
- uint32_t width;
- uint32_t height;
- uint32_t depth;
- uint32_t cell_count;
- uint32_t leaf_cell_count;
- };
-
- struct GIProbeDataCell {
-
- uint32_t children[8];
- uint32_t albedo;
- uint32_t emission;
- uint32_t normal;
- uint32_t level_alpha;
- };
-
- enum {
- GI_UPDATE_STAGE_CHECK,
- GI_UPDATE_STAGE_LIGHTING,
- GI_UPDATE_STAGE_UPLOADING,
- };
-
- void _gi_probe_bake_thread();
- static void _gi_probe_bake_threads(void *);
-
- volatile bool probe_bake_thread_exit;
- Thread *probe_bake_thread;
- Semaphore *probe_bake_sem;
- Mutex *probe_bake_mutex;
- List<Instance *> probe_bake_list;
-
- bool _render_reflection_probe_step(Instance *p_instance, int p_step);
- void _gi_probe_fill_local_data(int p_idx, int p_level, int p_x, int p_y, int p_z, const GIProbeDataCell *p_cell, const GIProbeDataHeader *p_header, InstanceGIProbeData::LocalData *p_local_data, Vector<uint32_t> *prev_cell);
-
- _FORCE_INLINE_ uint32_t _gi_bake_find_cell(const GIProbeDataCell *cells, int x, int y, int z, int p_cell_subdiv);
- void _bake_gi_downscale_light(int p_idx, int p_level, const GIProbeDataCell *p_cells, const GIProbeDataHeader *p_header, InstanceGIProbeData::LocalData *p_local_data, float p_propagate);
- void _bake_gi_probe_light(const GIProbeDataHeader *header, const GIProbeDataCell *cells, InstanceGIProbeData::LocalData *local_data, const uint32_t *leaves, int p_leaf_count, const InstanceGIProbeData::LightCache &light_cache, int p_sign);
- void _bake_gi_probe(Instance *p_gi_probe);
- bool _check_gi_probe(Instance *p_gi_probe);
- void _setup_gi_probe(Instance *p_instance);
-
void render_probes();
bool free(RID p_rid);