diff options
Diffstat (limited to 'servers/visual/visual_server_scene.cpp')
-rw-r--r-- | servers/visual/visual_server_scene.cpp | 654 |
1 files changed, 28 insertions, 626 deletions
diff --git a/servers/visual/visual_server_scene.cpp b/servers/visual/visual_server_scene.cpp index 11a9c8c9c1..cd68c14de8 100644 --- a/servers/visual/visual_server_scene.cpp +++ b/servers/visual/visual_server_scene.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -156,58 +156,6 @@ void *VisualServerScene::_instance_pair(void *p_self, OctreeElementID, Instance return gi_probe->lights.insert(A); } -#if 0 - if (A->base_type==INSTANCE_PORTAL) { - - ERR_FAIL_COND_V( B->base_type!=INSTANCE_PORTAL,NULL ); - - A->portal_info->candidate_set.insert(B); - B->portal_info->candidate_set.insert(A); - - self->_portal_attempt_connect(A); - //attempt to conncet portal A (will go through B anyway) - //this is a little hackish, but works fine in practice - - } else if (A->base_type==INSTANCE_GI_PROBE || B->base_type==INSTANCE_GI_PROBE) { - - if (B->base_type==INSTANCE_GI_PROBE) { - SWAP(A,B); - } - - ERR_FAIL_COND_V(B->base_type!=INSTANCE_GI_PROBE_SAMPLER,NULL); - B->gi_probe_sampler_info->gi_probes.insert(A); - - } else if (A->base_type==INSTANCE_ROOM || B->base_type==INSTANCE_ROOM) { - - if (B->base_type==INSTANCE_ROOM) - SWAP(A,B); - - ERR_FAIL_COND_V(! ((1<<B->base_type)&INSTANCE_GEOMETRY_MASK ),NULL); - - B->auto_rooms.insert(A); - A->room_info->owned_autoroom_geometry.insert(B); - - self->_instance_validate_autorooms(B); - - - } else { - - if (B->base_type==INSTANCE_LIGHT) { - - SWAP(A,B); - } else if (A->base_type!=INSTANCE_LIGHT) { - return NULL; - } - - - A->light_info->affected.insert(B); - B->lights.insert(A); - B->light_cache_dirty=true; - - - } -#endif - return NULL; } void VisualServerScene::_instance_unpair(void *p_self, OctreeElementID, Instance *p_A, int, OctreeElementID, Instance *p_B, int, void *udata) { @@ -269,57 +217,6 @@ void VisualServerScene::_instance_unpair(void *p_self, OctreeElementID, Instance gi_probe->lights.erase(E); } -#if 0 - if (A->base_type==INSTANCE_PORTAL) { - - ERR_FAIL_COND( B->base_type!=INSTANCE_PORTAL ); - - - A->portal_info->candidate_set.erase(B); - B->portal_info->candidate_set.erase(A); - - //after disconnecting them, see if they can connect again - self->_portal_attempt_connect(A); - self->_portal_attempt_connect(B); - - } else if (A->base_type==INSTANCE_GI_PROBE || B->base_type==INSTANCE_GI_PROBE) { - - if (B->base_type==INSTANCE_GI_PROBE) { - SWAP(A,B); - } - - ERR_FAIL_COND(B->base_type!=INSTANCE_GI_PROBE_SAMPLER); - B->gi_probe_sampler_info->gi_probes.erase(A); - - } else if (A->base_type==INSTANCE_ROOM || B->base_type==INSTANCE_ROOM) { - - if (B->base_type==INSTANCE_ROOM) - SWAP(A,B); - - ERR_FAIL_COND(! ((1<<B->base_type)&INSTANCE_GEOMETRY_MASK )); - - B->auto_rooms.erase(A); - B->valid_auto_rooms.erase(A); - A->room_info->owned_autoroom_geometry.erase(B); - - }else { - - - - if (B->base_type==INSTANCE_LIGHT) { - - SWAP(A,B); - } else if (A->base_type!=INSTANCE_LIGHT) { - return; - } - - - A->light_info->affected.erase(B); - B->lights.erase(A); - B->light_cache_dirty=true; - - } -#endif } RID VisualServerScene::scenario_create() { @@ -467,125 +364,6 @@ void VisualServerScene::instance_set_base(RID p_instance, RID p_base) { } } instance->materials.clear(); - -#if 0 - if (instance->light_info) { - - if (instance->scenario && instance->light_info->D) - instance->scenario->directional_lights.erase( instance->light_info->D ); - rasterizer->free(instance->light_info->instance); - memdelete(instance->light_info); - instance->light_info=NULL; - } - - - - if ( instance->room ) { - - instance_set_room(p_instance,RID()); - /* - if((1<<instance->base_type)&INSTANCE_GEOMETRY_MASK) - instance->room->room_info->owned_geometry_instances.erase(instance->RE); - else if (instance->base_type==INSTANCE_PORTAL) { - print_line("freeing portal, is it there? "+itos(instance->room->room_info->owned_portal_instances.(instance->RE))); - instance->room->room_info->owned_portal_instances.erase(instance->RE); - } else if (instance->base_type==INSTANCE_ROOM) - instance->room->room_info->owned_room_instances.erase(instance->RE); - else if (instance->base_type==INSTANCE_LIGHT) - instance->room->room_info->owned_light_instances.erase(instance->RE); - - instance->RE=NULL;*/ - } - - - - - - - if (instance->portal_info) { - - _portal_disconnect(instance,true); - memdelete(instance->portal_info); - instance->portal_info=NULL; - - } - - if (instance->gi_probe_info) { - - while(instance->gi_probe_info->owned_instances.size()) { - - Instance *owned=instance->gi_probe_info->owned_instances.front()->get(); - owned->gi_probe=NULL; - owned->data.gi_probe=NULL; - owned->data.gi_probe_octree_xform=NULL; - owned->BLE=NULL; - instance->gi_probe_info->owned_instances.pop_front(); - } - - memdelete(instance->gi_probe_info); - instance->gi_probe_info=NULL; - - } - - if (instance->scenario && instance->octree_id) { - instance->scenario->octree.erase( instance->octree_id ); - instance->octree_id=0; - } - - - if (instance->room_info) { - - for(List<Instance*>::Element *E=instance->room_info->owned_geometry_instances.front();E;E=E->next()) { - - Instance *owned = E->get(); - owned->room=NULL; - owned->RE=NULL; - } - for(List<Instance*>::Element *E=instance->room_info->owned_portal_instances.front();E;E=E->next()) { - - _portal_disconnect(E->get(),true); - Instance *owned = E->get(); - owned->room=NULL; - owned->RE=NULL; - } - - for(List<Instance*>::Element *E=instance->room_info->owned_room_instances.front();E;E=E->next()) { - - Instance *owned = E->get(); - owned->room=NULL; - owned->RE=NULL; - } - - if (instance->room_info->disconnected_child_portals.size()) { - ERR_PRINT("BUG: Disconnected portals remain!"); - } - memdelete(instance->room_info); - instance->room_info=NULL; - - } - - if (instance->particles_info) { - - rasterizer->free( instance->particles_info->instance ); - memdelete(instance->particles_info); - instance->particles_info=NULL; - - } - - if (instance->gi_probe_sampler_info) { - - while (instance->gi_probe_sampler_info->owned_instances.size()) { - - instance_geometry_set_gi_probe_sampler(instance->gi_probe_sampler_info->owned_instances.front()->get()->self,RID()); - } - - if (instance->gi_probe_sampler_info->sampled_light.is_valid()) { - rasterizer->free(instance->gi_probe_sampler_info->sampled_light); - } - memdelete( instance->gi_probe_sampler_info ); - instance->gi_probe_sampler_info=NULL; - } -#endif } instance->base_type = VS::INSTANCE_NONE; @@ -646,64 +424,6 @@ void VisualServerScene::instance_set_base(RID p_instance, RID p_base) { if (scenario) _instance_queue_update(instance, true, true); - -#if 0 - if (rasterizer->is_mesh(p_base)) { - instance->base_type=INSTANCE_MESH; - instance->data.morph_values.resize( rasterizer->mesh_get_morph_target_count(p_base)); - instance->data.materials.resize( rasterizer->mesh_get_surface_count(p_base)); - } else if (rasterizer->is_multimesh(p_base)) { - instance->base_type=INSTANCE_MULTIMESH; - } else if (rasterizer->is_immediate(p_base)) { - instance->base_type=INSTANCE_IMMEDIATE; - } else if (rasterizer->is_particles(p_base)) { - instance->base_type=INSTANCE_PARTICLES; - instance->particles_info=memnew( Instance::ParticlesInfo ); - instance->particles_info->instance = rasterizer->particles_instance_create( p_base ); - } else if (rasterizer->is_light(p_base)) { - - instance->base_type=INSTANCE_LIGHT; - instance->light_info = memnew( Instance::LightInfo ); - instance->light_info->instance = rasterizer->light_instance_create(p_base); - if (instance->scenario && rasterizer->light_get_type(p_base)==LIGHT_DIRECTIONAL) { - - instance->light_info->D = instance->scenario->directional_lights.push_back(instance->self); - } - - } else if (room_owner.owns(p_base)) { - instance->base_type=INSTANCE_ROOM; - instance->room_info = memnew( Instance::RoomInfo ); - instance->room_info->room=room_owner.get(p_base); - } else if (portal_owner.owns(p_base)) { - - instance->base_type=INSTANCE_PORTAL; - instance->portal_info = memnew(Instance::PortalInfo); - instance->portal_info->portal=portal_owner.get(p_base); - } else if (gi_probe_owner.owns(p_base)) { - - instance->base_type=INSTANCE_GI_PROBE; - instance->gi_probe_info=memnew(Instance::BakedLightInfo); - instance->gi_probe_info->gi_probe=gi_probe_owner.get(p_base); - - //instance->portal_info = memnew(Instance::PortalInfo); - //instance->portal_info->portal=portal_owner.get(p_base); - } else if (gi_probe_sampler_owner.owns(p_base)) { - - - instance->base_type=INSTANCE_GI_PROBE_SAMPLER; - instance->gi_probe_sampler_info=memnew( Instance::BakedLightSamplerInfo); - instance->gi_probe_sampler_info->sampler=gi_probe_sampler_owner.get(p_base); - - //instance->portal_info = memnew(Instance::PortalInfo); - //instance->portal_info->portal=portal_owner.get(p_base); - - } else { - ERR_EXPLAIN("Invalid base RID for instance!") - ERR_FAIL(); - } - - instance_dependency_map[ p_base ].insert( instance->self ); -#endif } } void VisualServerScene::instance_set_scenario(RID p_instance, RID p_scenario) { @@ -894,8 +614,6 @@ void VisualServerScene::instance_attach_skeleton(RID p_instance, RID p_skeleton) void VisualServerScene::instance_set_exterior(RID p_instance, bool p_enabled) { } -void VisualServerScene::instance_set_room(RID p_instance, RID p_room) { -} void VisualServerScene::instance_set_extra_visibility_margin(RID p_instance, real_t p_margin) { } @@ -910,7 +628,7 @@ Vector<ObjectID> VisualServerScene::instances_cull_aabb(const Rect3 &p_aabb, RID int culled = 0; Instance *cull[1024]; - culled = scenario->octree.cull_AABB(p_aabb, cull, 1024); + culled = scenario->octree.cull_aabb(p_aabb, cull, 1024); for (int i = 0; i < culled; i++) { @@ -978,21 +696,6 @@ void VisualServerScene::instance_geometry_set_flag(RID p_instance, VS::InstanceF switch (p_flags) { - case VS::INSTANCE_FLAG_CAST_SHADOW: { - if (p_enabled == true) { - instance->cast_shadows = VS::SHADOW_CASTING_SETTING_ON; - } else { - instance->cast_shadows = VS::SHADOW_CASTING_SETTING_OFF; - } - - instance->base_material_changed(); // to actually compute if shadows are visible or not - - } break; - case VS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS: { - - instance->visible_in_all_rooms = p_enabled; - - } break; case VS::INSTANCE_FLAG_USE_BAKED_LIGHT: { instance->baked_light = p_enabled; @@ -1001,6 +704,12 @@ void VisualServerScene::instance_geometry_set_flag(RID p_instance, VS::InstanceF } } void VisualServerScene::instance_geometry_set_cast_shadows_setting(RID p_instance, VS::ShadowCastingSetting p_shadow_casting_setting) { + + Instance *instance = instance_owner.get(p_instance); + ERR_FAIL_COND(!instance); + + instance->cast_shadows = p_shadow_casting_setting; + instance->base_material_changed(); // to actually compute if shadows are visible or not } void VisualServerScene::instance_geometry_set_material_override(RID p_instance, RID p_material) { @@ -1048,16 +757,10 @@ void VisualServerScene::_update_instance(Instance *p_instance) { VSG::storage->particles_set_emission_transform(p_instance->base, p_instance->transform); } - if (p_instance->aabb.has_no_surface()) + if (p_instance->aabb.has_no_surface()) { return; - -#if 0 - if (p_instance->base_type == VS::INSTANCE_PARTICLES) { - - rasterizer->particles_instance_set_transform( p_instance->particles_info->instance, p_instance->data.transform ); } -#endif if ((1 << p_instance->base_type) & VS::INSTANCE_GEOMETRY_MASK) { InstanceGeometryData *geom = static_cast<InstanceGeometryData *>(p_instance->base_data); @@ -1070,58 +773,12 @@ void VisualServerScene::_update_instance(Instance *p_instance) { } } } -#if 0 - else if (p_instance->base_type == INSTANCE_ROOM) { - - p_instance->room_info->affine_inverse=p_instance->data.transform.affine_inverse(); - } else if (p_instance->base_type == INSTANCE_GI_PROBE) { - - Transform scale; - scale.basis.scale(p_instance->gi_probe_info->gi_probe->octree_aabb.size); - scale.origin=p_instance->gi_probe_info->gi_probe->octree_aabb.pos; - //print_line("scale: "+scale); - p_instance->gi_probe_info->affine_inverse=(p_instance->data.transform*scale).affine_inverse(); - } - -#endif p_instance->mirror = p_instance->transform.basis.determinant() < 0.0; Rect3 new_aabb; -#if 0 - if (p_instance->base_type==INSTANCE_PORTAL) { - - //portals need to be transformed in a special way, so they don't become too wide if they have scale.. - Transform portal_xform = p_instance->data.transform; - portal_xform.basis.set_axis(2,portal_xform.basis.get_axis(2).normalized()); - - p_instance->portal_info->plane_cache=Plane( p_instance->data.transform.origin, portal_xform.basis.get_axis(2)); - int point_count=p_instance->portal_info->portal->shape.size(); - p_instance->portal_info->transformed_point_cache.resize(point_count); - - AABB portal_aabb; - for(int i=0;i<point_count;i++) { - - Point2 src = p_instance->portal_info->portal->shape[i]; - Vector3 point = portal_xform.xform(Vector3(src.x,src.y,0)); - p_instance->portal_info->transformed_point_cache[i]=point; - if (i==0) - portal_aabb.pos=point; - else - portal_aabb.expand_to(point); - } - - portal_aabb.grow_by(p_instance->portal_info->portal->connect_range); - - new_aabb = portal_aabb; - - } else { -#endif new_aabb = p_instance->transform.xform(p_instance->aabb); -#if 0 - } -#endif p_instance->transformed_aabb = new_aabb; @@ -1148,33 +805,6 @@ void VisualServerScene::_update_instance(Instance *p_instance) { pairable = true; } -#if 0 - - if (p_instance->base_type == VS::INSTANCE_PORTAL) { - - pairable_mask=(1<<INSTANCE_PORTAL); - pairable=true; - } - - if (p_instance->base_type == VS::INSTANCE_GI_PROBE_SAMPLER) { - - pairable_mask=(1<<INSTANCE_GI_PROBE); - pairable=true; - } - - - if (!p_instance->room && (1<<p_instance->base_type)&VS::INSTANCE_GEOMETRY_MASK) { - - base_type|=VS::INSTANCE_ROOMLESS_MASK; - } - - if (p_instance->base_type == VS::INSTANCE_ROOM) { - - pairable_mask=INSTANCE_ROOMLESS_MASK; - pairable=true; - } -#endif - // not inside octree p_instance->octree_id = p_instance->scenario->octree.create(p_instance, new_aabb, 0, pairable, base_type, pairable_mask); @@ -1187,23 +817,6 @@ void VisualServerScene::_update_instance(Instance *p_instance) { p_instance->scenario->octree.move(p_instance->octree_id, new_aabb); } -#if 0 - if (p_instance->base_type==INSTANCE_PORTAL) { - - _portal_attempt_connect(p_instance); - } - - if (!p_instance->room && (1<<p_instance->base_type)&INSTANCE_GEOMETRY_MASK) { - - _instance_validate_autorooms(p_instance); - } - - if (p_instance->base_type == INSTANCE_ROOM) { - - for(Set<Instance*>::Element *E=p_instance->room_info->owned_autoroom_geometry.front();E;E=E->next()) - _instance_validate_autorooms(E->get()); - } -#endif } void VisualServerScene::_update_instance_aabb(Instance *p_instance) { @@ -1238,15 +851,6 @@ void VisualServerScene::_update_instance_aabb(Instance *p_instance) { new_aabb = VSG::storage->particles_get_aabb(p_instance->base); } break; -#if 0 - - case VisualServer::INSTANCE_PARTICLES: { - - new_aabb = rasterizer->particles_get_aabb(p_instance->base); - - - } break; -#endif case VisualServer::INSTANCE_LIGHT: { new_aabb = VSG::storage->light_get_aabb(p_instance->base); @@ -1263,49 +867,6 @@ void VisualServerScene::_update_instance_aabb(Instance *p_instance) { } break; -#if 0 - case VisualServer::INSTANCE_ROOM: { - - Room *room = room_owner.get( p_instance->base ); - ERR_FAIL_COND(!room); - new_aabb=room->bounds.get_aabb(); - - } break; - case VisualServer::INSTANCE_PORTAL: { - - Portal *portal = portal_owner.get( p_instance->base ); - ERR_FAIL_COND(!portal); - for (int i=0;i<portal->shape.size();i++) { - - Vector3 point( portal->shape[i].x, portal->shape[i].y, 0 ); - if (i==0) { - - new_aabb.pos=point; - new_aabb.size.z=0.01; // make it not flat for octree - } else { - - new_aabb.expand_to(point); - } - } - - } break; - case VisualServer::INSTANCE_GI_PROBE: { - - BakedLight *gi_probe = gi_probe_owner.get( p_instance->base ); - ERR_FAIL_COND(!gi_probe); - new_aabb=gi_probe->octree_aabb; - - } break; - case VisualServer::INSTANCE_GI_PROBE_SAMPLER: { - - BakedLightSampler *gi_probe_sampler = gi_probe_sampler_owner.get( p_instance->base ); - ERR_FAIL_COND(!gi_probe_sampler); - float radius = gi_probe_sampler->params[VS::BAKED_LIGHT_SAMPLER_RADIUS]; - - new_aabb=AABB(Vector3(-radius,-radius,-radius),Vector3(radius*2,radius*2,radius*2)); - - } break; -#endif default: {} } @@ -1739,98 +1300,17 @@ void VisualServerScene::_render_scene(const Transform p_cam_transform, const Cam reflection_probe_cull_count = 0; -//light_samplers_culled=0; + //light_samplers_culled=0; -/* print_line("OT: "+rtos( (OS::get_singleton()->get_ticks_usec()-t)/1000.0)); + /* print_line("OT: "+rtos( (OS::get_singleton()->get_ticks_usec()-t)/1000.0)); print_line("OTO: "+itos(p_scenario->octree.get_octant_count())); //print_line("OTE: "+itos(p_scenario->octree.get_elem_count())); print_line("OTP: "+itos(p_scenario->octree.get_pair_count())); */ -/* STEP 3 - PROCESS PORTALS, VALIDATE ROOMS */ - -// compute portals -#if 0 - exterior_visited=false; - exterior_portal_cull_count=0; - - if (room_cull_enabled) { - for(int i=0;i<cull_count;i++) { - - Instance *ins = instance_cull_result[i]; - ins->last_render_pass=render_pass; - - if (ins->base_type!=INSTANCE_PORTAL) - continue; - - if (ins->room) - continue; - - ERR_CONTINUE(exterior_portal_cull_count>=MAX_EXTERIOR_PORTALS); - exterior_portal_cull_result[exterior_portal_cull_count++]=ins; - - } - - room_cull_count = p_scenario->octree.cull_point(camera->transform.origin,room_cull_result,MAX_ROOM_CULL,NULL,(1<<INSTANCE_ROOM)|(1<<INSTANCE_PORTAL)); - - - Set<Instance*> current_rooms; - Set<Instance*> portal_rooms; - //add to set - for(int i=0;i<room_cull_count;i++) { - - if (room_cull_result[i]->base_type==INSTANCE_ROOM) { - current_rooms.insert(room_cull_result[i]); - } - if (room_cull_result[i]->base_type==INSTANCE_PORTAL) { - //assume inside that room if also inside the portal.. - if (room_cull_result[i]->room) { - portal_rooms.insert(room_cull_result[i]->room); - } - - SWAP(room_cull_result[i],room_cull_result[room_cull_count-1]); - room_cull_count--; - i--; - } - } - - //remove from set if it has a parent room or BSP doesn't contain - for(int i=0;i<room_cull_count;i++) { - Instance *r = room_cull_result[i]; - - //check inside BSP - Vector3 room_local_point = r->room_info->affine_inverse.xform( camera->transform.origin ); + /* STEP 3 - PROCESS PORTALS, VALIDATE ROOMS */ + //removed, will replace with culling - if (!portal_rooms.has(r) && !r->room_info->room->bounds.point_is_inside(room_local_point)) { - - current_rooms.erase(r); - continue; - } - - //check parent - while (r->room) {// has parent room - - current_rooms.erase(r); - r=r->room; - } - - } - - if (current_rooms.size()) { - //camera is inside a room - // go through rooms - for(Set<Instance*>::Element *E=current_rooms.front();E;E=E->next()) { - _cull_room(camera,E->get()); - } - - } else { - //start from exterior - _cull_room(camera,NULL); - - } - } - -#endif /* STEP 4 - REMOVE FURTHER CULLED OBJECTS, ADD LIGHTS */ for (int i = 0; i < cull_count; i++) { @@ -1898,71 +1378,6 @@ void VisualServerScene::_render_scene(const Transform p_cam_transform, const Cam } else if ((1 << ins->base_type) & VS::INSTANCE_GEOMETRY_MASK && ins->visible && ins->cast_shadows != VS::SHADOW_CASTING_SETTING_SHADOWS_ONLY) { keep = true; -#if 0 - bool discarded=false; - - if (ins->draw_range_end>0) { - - float d = cull_range.nearp.distance_to(ins->data.transform.origin); - if (d<0) - d=0; - discarded=(d<ins->draw_range_begin || d>=ins->draw_range_end); - - - } - - if (!discarded) { - - // test if this geometry should be visible - - if (room_cull_enabled) { - - - if (ins->visible_in_all_rooms) { - keep=true; - } else if (ins->room) { - - if (ins->room->room_info->last_visited_pass==render_pass) - keep=true; - } else if (ins->auto_rooms.size()) { - - - for(Set<Instance*>::Element *E=ins->auto_rooms.front();E;E=E->next()) { - - if (E->get()->room_info->last_visited_pass==render_pass) { - keep=true; - break; - } - } - } else if(exterior_visited) - keep=true; - } else { - - keep=true; - } - - - } - - - if (keep) { - // update cull range - float min,max; - ins->transformed_aabb.project_range_in_plane(cull_range.nearp,min,max); - - if (min<cull_range.min) - cull_range.min=min; - if (max>cull_range.max) - cull_range.max=max; - - if (ins->sampled_light && ins->sampled_light->gi_probe_sampler_info->last_pass!=render_pass) { - if (light_samplers_culled<MAX_LIGHT_SAMPLERS) { - light_sampler_cull_result[light_samplers_culled++]=ins->sampled_light; - ins->sampled_light->gi_probe_sampler_info->last_pass=render_pass; - } - } - } -#endif InstanceGeometryData *geom = static_cast<InstanceGeometryData *>(ins->base_data); @@ -2058,13 +1473,13 @@ void VisualServerScene::_render_scene(const Transform p_cam_transform, const Cam //check shadow.. - if (light && p_shadow_atlas.is_valid() && VSG::storage->light_has_shadow(E->get()->base)) { - lights_with_shadow[directional_shadow_count++] = E->get(); + if (light) { + if (p_shadow_atlas.is_valid() && VSG::storage->light_has_shadow(E->get()->base)) { + lights_with_shadow[directional_shadow_count++] = E->get(); + } + //add to list + directional_light_ptr[directional_light_count++] = light->instance; } - - //add to list - - directional_light_ptr[directional_light_count++] = light->instance; } VSG::scene_render->set_directional_shadow_count(directional_shadow_count); @@ -2185,20 +1600,7 @@ void VisualServerScene::_render_scene(const Transform p_cam_transform, const Cam else environment = scenario->fallback_environment; -#if 0 - /* STEP 6 - SAMPLE BAKED LIGHT */ - - bool islinear =false; - if (environment.is_valid()) { - islinear = rasterizer->environment_is_fx_enabled(environment,VS::ENV_FX_SRGB); - } - - for(int i=0;i<light_samplers_culled;i++) { - - _process_sampled_light(camera->transform,light_sampler_cull_result[i],islinear); - } -#endif - /* STEP 7 - PROCESS GEOMETRY AND DRAW SCENE*/ + /* STEP 6 - PROCESS GEOMETRY AND DRAW SCENE*/ VSG::scene_render->render_scene(p_cam_transform, p_cam_projection, p_cam_orthogonal, (RasterizerScene::InstanceBase **)instance_cull_result, cull_count, light_instance_cull_result, light_cull_count + directional_light_count, reflection_probe_instance_cull_result, reflection_probe_cull_count, environment, p_shadow_atlas, scenario->reflection_atlas, p_reflection_probe, p_reflection_probe_pass); } @@ -2645,11 +2047,11 @@ static float _get_normal_advance(const Vector3 &p_normal) { return 1.0 / normal.dot(unorm); } -void VisualServerScene::_bake_gi_probe_light(const GIProbeDataHeader *header, const GIProbeDataCell *cells, InstanceGIProbeData::LocalData *local_data, const uint32_t *leaves, int leaf_count, const InstanceGIProbeData::LightCache &light_cache, int sign) { +void VisualServerScene::_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) { - int light_r = int(light_cache.color.r * light_cache.energy * 1024.0) * sign; - int light_g = int(light_cache.color.g * light_cache.energy * 1024.0) * sign; - int light_b = int(light_cache.color.b * light_cache.energy * 1024.0) * sign; + int light_r = int(light_cache.color.r * light_cache.energy * 1024.0) * p_sign; + int light_g = int(light_cache.color.g * light_cache.energy * 1024.0) * p_sign; + int light_b = int(light_cache.color.b * light_cache.energy * 1024.0) * p_sign; float limits[3] = { float(header->width), float(header->height), float(header->depth) }; Plane clip[3]; @@ -2685,7 +2087,7 @@ void VisualServerScene::_bake_gi_probe_light(const GIProbeDataHeader *header, co uint64_t us = OS::get_singleton()->get_ticks_usec(); - for (int i = 0; i < leaf_count; i++) { + for (int i = 0; i < p_leaf_count; i++) { uint32_t idx = leaves[i]; @@ -2750,7 +2152,7 @@ void VisualServerScene::_bake_gi_probe_light(const GIProbeDataHeader *header, co float local_radius = light_cache.radius * light_cache.transform.basis.get_axis(2).length(); - for (int i = 0; i < leaf_count; i++) { + for (int i = 0; i < p_leaf_count; i++) { uint32_t idx = leaves[i]; @@ -3278,8 +2680,9 @@ void VisualServerScene::render_probes() { void VisualServerScene::_update_dirty_instance(Instance *p_instance) { - if (p_instance->update_aabb) + if (p_instance->update_aabb) { _update_instance_aabb(p_instance); + } if (p_instance->update_materials) { @@ -3469,7 +2872,6 @@ bool VisualServerScene::free(RID p_rid) { Instance *instance = instance_owner.get(p_rid); - instance_set_room(p_rid, RID()); instance_set_scenario(p_rid, RID()); instance_set_base(p_rid, RID()); instance_geometry_set_material_override(p_rid, RID()); |