diff options
Diffstat (limited to 'servers/rendering/renderer_scene_cull.cpp')
-rw-r--r-- | servers/rendering/renderer_scene_cull.cpp | 100 |
1 files changed, 23 insertions, 77 deletions
diff --git a/servers/rendering/renderer_scene_cull.cpp b/servers/rendering/renderer_scene_cull.cpp index efaf77f30b..271c039aad 100644 --- a/servers/rendering/renderer_scene_cull.cpp +++ b/servers/rendering/renderer_scene_cull.cpp @@ -43,7 +43,7 @@ RID RendererSceneCull::camera_allocate() { return camera_owner.allocate_rid(); } void RendererSceneCull::camera_initialize(RID p_rid) { - camera_owner.initialize_rid(p_rid, memnew(Camera)); + camera_owner.initialize_rid(p_rid); } void RendererSceneCull::camera_set_perspective(RID p_camera, float p_fovy_degrees, float p_z_near, float p_z_far) { @@ -310,7 +310,9 @@ RID RendererSceneCull::scenario_allocate() { return scenario_owner.allocate_rid(); } void RendererSceneCull::scenario_initialize(RID p_rid) { - Scenario *scenario = memnew(Scenario); + scenario_owner.initialize_rid(p_rid); + + Scenario *scenario = scenario_owner.getornull(p_rid); scenario->self = p_rid; scenario->reflection_probe_shadow_atlas = scene_render->shadow_atlas_create(); @@ -326,14 +328,6 @@ void RendererSceneCull::scenario_initialize(RID p_rid) { scenario->instance_visibility.set_page_pool(&instance_visibility_data_page_pool); RendererSceneOcclusionCull::get_singleton()->add_scenario(p_rid); - - scenario_owner.initialize_rid(p_rid, scenario); -} - -void RendererSceneCull::scenario_set_debug(RID p_scenario, RS::ScenarioDebugMode p_debug_mode) { - Scenario *scenario = scenario_owner.getornull(p_scenario); - ERR_FAIL_COND(!scenario); - scenario->debug = p_debug_mode; } void RendererSceneCull::scenario_set_environment(RID p_scenario, RID p_environment) { @@ -422,10 +416,9 @@ RID RendererSceneCull::instance_allocate() { return instance_owner.allocate_rid(); } void RendererSceneCull::instance_initialize(RID p_rid) { - Instance *instance = memnew(Instance); + instance_owner.initialize_rid(p_rid); + Instance *instance = instance_owner.getornull(p_rid); instance->self = p_rid; - - instance_owner.initialize_rid(p_rid, instance); } void RendererSceneCull::_instance_update_mesh_instance(Instance *p_instance) { @@ -479,7 +472,6 @@ void RendererSceneCull::instance_set_base(RID p_instance, RID p_base) { switch (instance->base_type) { case RS::INSTANCE_MESH: case RS::INSTANCE_MULTIMESH: - case RS::INSTANCE_IMMEDIATE: case RS::INSTANCE_PARTICLES: { InstanceGeometryData *geom = static_cast<InstanceGeometryData *>(instance->base_data); scene_render->geometry_instance_free(geom->geometry_instance); @@ -591,7 +583,6 @@ void RendererSceneCull::instance_set_base(RID p_instance, RID p_base) { } break; case RS::INSTANCE_MESH: case RS::INSTANCE_MULTIMESH: - case RS::INSTANCE_IMMEDIATE: case RS::INSTANCE_PARTICLES: { InstanceGeometryData *geom = memnew(InstanceGeometryData); instance->base_data = geom; @@ -889,7 +880,7 @@ void RendererSceneCull::instance_set_visible(RID p_instance, bool p_visible) { } inline bool is_geometry_instance(RenderingServer::InstanceType p_type) { - return p_type == RS::INSTANCE_MESH || p_type == RS::INSTANCE_MULTIMESH || p_type == RS::INSTANCE_PARTICLES || p_type == RS::INSTANCE_IMMEDIATE; + return p_type == RS::INSTANCE_MESH || p_type == RS::INSTANCE_MULTIMESH || p_type == RS::INSTANCE_PARTICLES; } void RendererSceneCull::instance_set_custom_aabb(RID p_instance, AABB p_aabb) { @@ -942,9 +933,6 @@ void RendererSceneCull::instance_attach_skeleton(RID p_instance, RID p_skeleton) } } -void RendererSceneCull::instance_set_exterior(RID p_instance, bool p_enabled) { -} - void RendererSceneCull::instance_set_extra_visibility_margin(RID p_instance, real_t p_margin) { Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); @@ -1327,6 +1315,8 @@ void RendererSceneCull::instance_geometry_set_shader_parameter(RID p_instance, c Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); + ERR_FAIL_COND(p_value.get_type() == Variant::OBJECT); + Map<StringName, Instance::InstanceShaderParameter>::Element *E = instance->instance_shader_parameters.find(p_parameter); if (!E) { @@ -1530,7 +1520,6 @@ void RendererSceneCull::_update_instance(Instance *p_instance) { switch (p_instance->base_type) { case RS::INSTANCE_MESH: case RS::INSTANCE_MULTIMESH: - case RS::INSTANCE_IMMEDIATE: case RS::INSTANCE_PARTICLES: { InstanceGeometryData *geom = static_cast<InstanceGeometryData *>(p_instance->base_data); idata.instance_geometry = geom->geometry_instance; @@ -1749,14 +1738,6 @@ void RendererSceneCull::_update_instance_aabb(Instance *p_instance) { } } break; - case RenderingServer::INSTANCE_IMMEDIATE: { - if (p_instance->custom_aabb) { - new_aabb = *p_instance->custom_aabb; - } else { - new_aabb = RSG::storage->immediate_get_aabb(p_instance->base); - } - - } break; case RenderingServer::INSTANCE_PARTICLES: { if (p_instance->custom_aabb) { new_aabb = *p_instance->custom_aabb; @@ -1898,8 +1879,6 @@ void RendererSceneCull::_light_instance_setup_directional_shadow(int p_shadow_in max_distance = MAX(max_distance, p_cam_projection.get_z_near() + 0.001); real_t min_distance = MIN(p_cam_projection.get_z_near(), max_distance); - RS::LightDirectionalShadowDepthRangeMode depth_range_mode = RSG::storage->light_directional_get_shadow_depth_range_mode(p_instance->base); - real_t pancake_size = RSG::storage->light_get_param(p_instance->base, RS::LIGHT_PARAM_SHADOW_PANCAKE_SIZE); real_t range = max_distance - min_distance; @@ -2059,22 +2038,13 @@ void RendererSceneCull::_light_instance_setup_directional_shadow(int p_shadow_in } } - x_max_cam = x_vec.dot(center) + radius + soft_shadow_expand; - x_min_cam = x_vec.dot(center) - radius - soft_shadow_expand; - y_max_cam = y_vec.dot(center) + radius + soft_shadow_expand; - y_min_cam = y_vec.dot(center) - radius - soft_shadow_expand; - - if (depth_range_mode == RS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE) { - //this trick here is what stabilizes the shadow (make potential jaggies to not move) - //at the cost of some wasted resolution. Still the quality increase is very well worth it - - real_t unit = radius * 2.0 / texture_size; - - x_max_cam = Math::snapped(x_max_cam, unit); - x_min_cam = Math::snapped(x_min_cam, unit); - y_max_cam = Math::snapped(y_max_cam, unit); - y_min_cam = Math::snapped(y_min_cam, unit); - } + // This trick here is what stabilizes the shadow (make potential jaggies to not move) + // at the cost of some wasted resolution. Still, the quality increase is very well worth it. + const real_t unit = radius * 2.0 / texture_size; + x_max_cam = Math::snapped(x_vec.dot(center) + radius + soft_shadow_expand, unit); + x_min_cam = Math::snapped(x_vec.dot(center) - radius - soft_shadow_expand, unit); + y_max_cam = Math::snapped(y_vec.dot(center) + radius + soft_shadow_expand, unit); + y_min_cam = Math::snapped(y_vec.dot(center) - radius - soft_shadow_expand, unit); } //now that we know all ranges, we can proceed to make the light frustum planes, for culling octree @@ -2404,7 +2374,7 @@ bool RendererSceneCull::_light_instance_update_shadow(Instance *p_instance, cons return animated_material_found; } -void RendererSceneCull::render_camera(RID p_render_buffers, RID p_camera, RID p_scenario, RID p_viewport, Size2 p_viewport_size, float p_screen_lod_threshold, RID p_shadow_atlas, Ref<XRInterface> &p_xr_interface) { +void RendererSceneCull::render_camera(RID p_render_buffers, RID p_camera, RID p_scenario, RID p_viewport, Size2 p_viewport_size, float p_screen_lod_threshold, RID p_shadow_atlas, Ref<XRInterface> &p_xr_interface, RenderInfo *r_render_info) { #ifndef _3D_DISABLED Camera *camera = camera_owner.getornull(p_camera); @@ -2486,7 +2456,7 @@ void RendererSceneCull::render_camera(RID p_render_buffers, RID p_camera, RID p_ // For now just cull on the first camera RendererSceneOcclusionCull::get_singleton()->buffer_update(p_viewport, camera_data.main_transform, camera_data.main_projection, camera_data.is_ortogonal, RendererThreadPool::singleton->thread_work_pool); - _render_scene(&camera_data, p_render_buffers, environment, camera->effects, camera->visible_layers, p_scenario, p_viewport, p_shadow_atlas, RID(), -1, p_screen_lod_threshold); + _render_scene(&camera_data, p_render_buffers, environment, camera->effects, camera->visible_layers, p_scenario, p_viewport, p_shadow_atlas, RID(), -1, p_screen_lod_threshold, true, r_render_info); #endif } @@ -2578,7 +2548,7 @@ void RendererSceneCull::_scene_cull(CullData &cull_data, InstanceCullResult &cul #define HIDDEN_BY_VISIBILITY_CHECKS (visibility_flags == InstanceData::FLAG_VISIBILITY_DEPENDENCY_HIDDEN_CLOSE_RANGE || visibility_flags == InstanceData::FLAG_VISIBILITY_DEPENDENCY_HIDDEN) #define LAYER_CHECK (cull_data.visible_layers & idata.layer_mask) #define IN_FRUSTUM(f) (cull_data.scenario->instance_aabbs[i].in_frustum(f)) -#define VIS_RANGE_CHECK ((idata.visibility_index == -1) || _visibility_range_check(cull_data.scenario->instance_visibility[idata.visibility_index], cull_data.cam_transform.origin, cull_data.visibility_cull_data->viewport_mask) == 0) +#define VIS_RANGE_CHECK ((idata.visibility_index == -1) || _visibility_range_check(cull_data.scenario->instance_visibility[idata.visibility_index], cull_data.cam_transform.origin, cull_data.visibility_viewport_mask) == 0) #define VIS_PARENT_CHECK ((idata.parent_array_index == -1) || ((cull_data.scenario->instance_data[idata.parent_array_index].flags & InstanceData::FLAG_VISIBILITY_DEPENDENCY_NEEDS_CHECK) == InstanceData::FLAG_VISIBILITY_DEPENDENCY_HIDDEN_CLOSE_RANGE)) #define VIS_CHECK (visibility_check < 0 ? (visibility_check = (visibility_flags != InstanceData::FLAG_VISIBILITY_DEPENDENCY_NEEDS_CHECK || (VIS_RANGE_CHECK && VIS_PARENT_CHECK))) : visibility_check) #define OCCLUSION_CULLED (cull_data.occlusion_buffer != nullptr && (cull_data.scenario->instance_data[i].flags & InstanceData::FLAG_IGNORE_OCCLUSION_CULLING) == 0 && cull_data.occlusion_buffer->is_occluded(cull_data.scenario->instance_aabbs[i].bounds, cull_data.cam_transform.origin, inv_cam_transform, *cull_data.camera_matrix, z_near)) @@ -2792,7 +2762,7 @@ void RendererSceneCull::_scene_cull(CullData &cull_data, InstanceCullResult &cul } } -void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_camera_data, RID p_render_buffers, RID p_environment, RID p_force_camera_effects, 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_lod_threshold, bool p_using_shadows) { +void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_camera_data, RID p_render_buffers, RID p_environment, RID p_force_camera_effects, 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_lod_threshold, bool p_using_shadows, RendererScene::RenderInfo *r_render_info) { Instance *render_reflection_probe = instance_owner.getornull(p_reflection_probe); //if null, not rendering to it Scenario *scenario = scenario_owner.getornull(p_scenario); @@ -2808,12 +2778,12 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c RENDER_TIMESTAMP("Visibility Dependencies"); - VisibilityCullData visibility_cull_data; if (scenario->instance_visibility.get_bin_count() > 0) { if (!scenario->viewport_visibility_masks.has(p_viewport)) { scenario_add_viewport_visibility_mask(scenario->self, p_viewport); } + VisibilityCullData visibility_cull_data; visibility_cull_data.scenario = scenario; visibility_cull_data.viewport_mask = scenario->viewport_visibility_masks[p_viewport]; visibility_cull_data.camera_position = p_camera_data->main_transform.origin; @@ -2924,6 +2894,7 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c cull_data.render_reflection_probe = render_reflection_probe; cull_data.occlusion_buffer = RendererSceneOcclusionCull::get_singleton()->buffer_get_ptr(p_viewport); cull_data.camera_matrix = &p_camera_data->main_projection; + cull_data.visibility_viewport_mask = scenario->viewport_visibility_masks.has(p_viewport) ? scenario->viewport_visibility_masks[p_viewport] : 0; //#define DEBUG_CULL_TIME #ifdef DEBUG_CULL_TIME uint64_t time_from = OS::get_singleton()->get_ticks_usec(); @@ -3136,7 +3107,7 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c } RENDER_TIMESTAMP("Render Scene "); - scene_render->render_scene(p_render_buffers, p_camera_data, scene_cull_result.geometry_instances, scene_cull_result.light_instances, scene_cull_result.reflections, scene_cull_result.voxel_gi_instances, scene_cull_result.decals, scene_cull_result.lightmaps, p_environment, camera_effects, p_shadow_atlas, occluders_tex, p_reflection_probe.is_valid() ? RID() : scenario->reflection_atlas, p_reflection_probe, p_reflection_probe_pass, p_screen_lod_threshold, render_shadow_data, max_shadows_used, render_sdfgi_data, cull.sdfgi.region_count, &sdfgi_update_data); + scene_render->render_scene(p_render_buffers, p_camera_data, scene_cull_result.geometry_instances, scene_cull_result.light_instances, scene_cull_result.reflections, scene_cull_result.voxel_gi_instances, scene_cull_result.decals, scene_cull_result.lightmaps, p_environment, camera_effects, p_shadow_atlas, occluders_tex, p_reflection_probe.is_valid() ? RID() : scenario->reflection_atlas, p_reflection_probe, p_reflection_probe_pass, p_screen_lod_threshold, render_shadow_data, max_shadows_used, render_sdfgi_data, cull.sdfgi.region_count, &sdfgi_update_data, r_render_info); for (uint32_t i = 0; i < max_shadows_used; i++) { render_shadow_data[i].instances.clear(); @@ -3173,7 +3144,6 @@ RID RendererSceneCull::_render_get_environment(RID p_camera, RID p_scenario) { void RendererSceneCull::render_empty_scene(RID p_render_buffers, RID p_scenario, RID p_shadow_atlas) { #ifndef _3D_DISABLED - Scenario *scenario = scenario_owner.getornull(p_scenario); RID environment; @@ -3681,25 +3651,6 @@ void RendererSceneCull::_update_dirty_instance(Instance *p_instance) { RSG::storage->base_update_dependency(mesh, &p_instance->dependency_tracker); } - } else if (p_instance->base_type == RS::INSTANCE_IMMEDIATE) { - RID mat = RSG::storage->immediate_get_material(p_instance->base); - - if (!(!mat.is_valid() || RSG::storage->material_casts_shadows(mat))) { - can_cast_shadows = false; - } - - if (mat.is_valid() && RSG::storage->material_is_animated(mat)) { - is_animated = true; - } - - if (mat.is_valid()) { - _update_instance_shader_parameters_from_material(isparams, p_instance->instance_shader_parameters, mat); - } - - if (mat.is_valid()) { - RSG::storage->material_update_dependency(mat, &p_instance->dependency_tracker); - } - } else if (p_instance->base_type == RS::INSTANCE_PARTICLES) { bool cast_shadows = false; @@ -3817,10 +3768,7 @@ bool RendererSceneCull::free(RID p_rid) { } if (camera_owner.owns(p_rid)) { - Camera *camera = camera_owner.getornull(p_rid); - camera_owner.free(p_rid); - memdelete(camera); } else if (scenario_owner.owns(p_rid)) { Scenario *scenario = scenario_owner.getornull(p_rid); @@ -3836,7 +3784,6 @@ bool RendererSceneCull::free(RID p_rid) { scene_render->free(scenario->reflection_atlas); scenario_owner.free(p_rid); RendererSceneOcclusionCull::get_singleton()->remove_scenario(p_rid); - memdelete(scenario); } else if (RendererSceneOcclusionCull::get_singleton()->is_occluder(p_rid)) { RendererSceneOcclusionCull::get_singleton()->free_occluder(p_rid); @@ -3860,7 +3807,6 @@ bool RendererSceneCull::free(RID p_rid) { update_dirty_instances(); //in case something changed this instance_owner.free(p_rid); - memdelete(instance); } else { return false; } |