Merge pull request #51092 from lawnjelly/portals_preview_globals

Portals - disable frustum culling gizmos with preview camera
This commit is contained in:
Rémi Verschelde 2021-07-31 10:53:45 +02:00 committed by GitHub
commit 3875cdaec4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 19 deletions

View file

@ -994,7 +994,7 @@ int PortalRenderer::cull_convex_implementation(const Vector3 &p_point, const Vec
return out_count;
}
out_count = _tracer.trace_globals(planes, p_result_array, out_count, p_result_max, p_mask);
out_count = _tracer.trace_globals(planes, p_result_array, out_count, p_result_max, p_mask, _override_camera);
return out_count;
}

View file

@ -228,36 +228,56 @@ void PortalTracer::cull_statics(const VSRoom &p_room, const LocalVector<Plane> &
} // for n through statics
}
int PortalTracer::trace_globals(const LocalVector<Plane> &p_planes, VSInstance **p_result_array, int first_result, int p_result_max, uint32_t p_mask) {
int PortalTracer::trace_globals(const LocalVector<Plane> &p_planes, VSInstance **p_result_array, int first_result, int p_result_max, uint32_t p_mask, bool p_override_camera) {
uint32_t num_globals = _portal_renderer->get_num_moving_globals();
int current_result = first_result;
for (uint32_t n = 0; n < num_globals; n++) {
const PortalRenderer::Moving &moving = _portal_renderer->get_moving_global(n);
if (!p_override_camera) {
for (uint32_t n = 0; n < num_globals; n++) {
const PortalRenderer::Moving &moving = _portal_renderer->get_moving_global(n);
#ifdef PORTAL_RENDERER_STORE_MOVING_RIDS
// debug check the instance is valid
void *vss_instance = VSG::scene->_instance_get_from_rid(moving.instance_rid);
// debug check the instance is valid
void *vss_instance = VSG::scene->_instance_get_from_rid(moving.instance_rid);
if (vss_instance) {
if (vss_instance) {
#endif
if (test_cull_inside(moving.exact_aabb, p_planes, false)) {
if (VSG::scene->_instance_cull_check(moving.instance, p_mask)) {
p_result_array[current_result++] = moving.instance;
if (test_cull_inside(moving.exact_aabb, p_planes, false)) {
if (VSG::scene->_instance_cull_check(moving.instance, p_mask)) {
p_result_array[current_result++] = moving.instance;
// full up?
if (current_result >= p_result_max) {
return current_result;
// full up?
if (current_result >= p_result_max) {
return current_result;
}
}
}
}
#ifdef PORTAL_RENDERER_STORE_MOVING_RIDS
} else {
WARN_PRINT("vss instance is null " + PortalRenderer::_addr_to_string(moving.instance));
}
} else {
WARN_PRINT("vss instance is null " + PortalRenderer::_addr_to_string(moving.instance));
}
#endif
}
}
} // if not override camera
else {
// If we are overriding the camera there is a potential problem in the editor:
// gizmos BEHIND the override camera will not be drawn.
// As this should be editor only and performance is not critical, we will just disable
// frustum culling for global objects when the camera is overriden.
for (uint32_t n = 0; n < num_globals; n++) {
const PortalRenderer::Moving &moving = _portal_renderer->get_moving_global(n);
if (VSG::scene->_instance_cull_check(moving.instance, p_mask)) {
p_result_array[current_result++] = moving.instance;
// full up?
if (current_result >= p_result_max) {
return current_result;
}
}
}
} // if override camera
return current_result;
}

View file

@ -105,7 +105,7 @@ public:
void trace(PortalRenderer &p_portal_renderer, const Vector3 &p_pos, const LocalVector<Plane> &p_planes, int p_start_room_id, TraceResult &r_result);
// globals are handled separately as they don't care about the rooms
int trace_globals(const LocalVector<Plane> &p_planes, VSInstance **p_result_array, int first_result, int p_result_max, uint32_t p_mask);
int trace_globals(const LocalVector<Plane> &p_planes, VSInstance **p_result_array, int first_result, int p_result_max, uint32_t p_mask, bool p_override_camera);
void set_depth_limit(int p_limit) { _depth_limit = p_limit; }