Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Layers/xrRender/r__dsgraph_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,9 @@ void R_dsgraph_structure::build_subspace()
for (u32 o_it = 0; o_it < lstRenderables.size(); o_it++)
{
ISpatial* spatial = lstRenderables[o_it];
if (o.is_main_pass)
// Re-detect the sector only when it was invalidated by a move (spatial_move). Static objects keep
// their cached sector and skip the 2 ray_query casts entirely - this is the bulk of per-frame rays.
if (o.is_main_pass && (spatial->GetSpatialData().type & STYPEFLAG_INVALIDSECTOR))
{
const auto& entity_pos = spatial->spatial_sector_point();
const auto sector_id = detect_sector(entity_pos);
Expand Down
8 changes: 6 additions & 2 deletions src/Layers/xrRender_R2/r2_R_calculate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,12 @@ void CRender::Calculate()
g_pGamePersistent->SpatialSpace.q_sphere(spatial_lights, 0, STYPE_LIGHTSOURCE, Device.vCameraPosition, EPS_L);
for (auto spatial : spatial_lights)
{
const auto& entity_pos = spatial->spatial_sector_point();
spatial->spatial_updatesector(dsgraph_main.detect_sector(entity_pos));
if (spatial->GetSpatialData().type & STYPEFLAG_INVALIDSECTOR)
{
const auto& entity_pos = spatial->spatial_sector_point();
spatial->spatial_updatesector(dsgraph_main.detect_sector(entity_pos));
}

const auto sector_id = spatial->GetSpatialData().sector_id;
if (sector_id == IRender_Sector::INVALID_SECTOR_ID)
continue; // disassociated from S/P structure
Expand Down
10 changes: 8 additions & 2 deletions src/xrCDB/ISpatial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,13 @@ void SpatialBase::spatial_move()
ZoneScoped;
if (spatial.node_ptr)
{
//*** somehow it was determined that object has been moved
spatial.type |= STYPEFLAG_INVALIDSECTOR;
//*** invalidate the cached sector only on a meaningful move, so stationary/jittering
//*** objects don't force a per-frame sector raycast (see r__dsgraph_build sector detection)
//*** adopted from xray-monolith
if (last_sector_point.distance_to_sqr(spatial_sector_point()) > 1.f)
{
spatial.type |= STYPEFLAG_INVALIDSECTOR;
}

//*** check if we are supposed to correct it's spatial location
if (spatial_inside())
Expand All @@ -119,6 +124,7 @@ void SpatialBase::spatial_move()
void SpatialBase::spatial_updatesector_internal(IRender_Sector::sector_id_t sector_id)
{
ZoneScoped;
last_sector_point = spatial_sector_point();
spatial.type &= ~STYPEFLAG_INVALIDSECTOR;
if (sector_id != IRender_Sector::INVALID_SECTOR_ID)
spatial.sector_id = sector_id;
Expand Down
2 changes: 2 additions & 0 deletions src/xrCDB/ISpatial.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class XRCDB_API XR_NOVTABLE SpatialBase : public virtual ISpatial
SpatialData spatial;

private:
// Point at which the sector was last (re)detected.
Fvector last_sector_point{};
void spatial_updatesector_internal(IRender_Sector::sector_id_t sector_id);

public:
Expand Down
Loading