View Issue Details

IDProjectCategoryView StatusLast Update
0005172The Dark ModCodingpublic22.11.2021 14:04
Reporterstgatilov Assigned Tostgatilov  
PrioritynormalSeverityminorReproducibilityN/A
Status assignedResolutionopen 
Product VersionTDM 2.08 
Target VersionTDM 2.11 
Summary0005172: Improve interaction culling: case when player-visible object is not visible from light
DescriptionThe engine does not cull away some shadows when it can.

Consider a typical scenario of two large rooms with one small open portal between them,
Suppose that an object is near the common wall between rooms, but far from the portal on this wall.
If the object is behind the wall, then player does not see it, and in most cases its shadow is culled away.

If the object is in front of the wall but the light source is behind the wall, then its shadow is also not visible.
In fact, in this case the light does not light the object at all.
The engine can detect this by seeing that light rays cannot pass into the object's area through the portal.
It seems that such interaction is not culled away, which is an opportunity for improvement.
Additional InformationExplained on dev forums:
  https://forums.thedarkmod.com/index.php?/topic/20195-performance-regression-shadowhide/&do=findComment&comment=442331
TagsNo tags attached.

Relationships

related to 0005084 resolvedstgatilov Interaction culling and Shadowhide WIP performance 

Activities

stgatilov

stgatilov

13.12.2020 17:32

administrator   ~0013120

The reason such culling is not done is that traditional stencil shadows are not cast from front surfaces:

    // if we have a prelight model that includes all the shadows for the major world occluders,
    // we can limit the area references to those visible through the portals from the light center.
    // We can't do this in the normal case, because shadows are cast from back facing triangles, which
    // may be in areas not directly visible to the light projection center.
    if ( light->parms.prelightModel && r_useLightPortalFlow.GetBool() && light->lightShader->LightCastsShadows() ) {
        light->world->FlowLightThroughPortals( light );
    } else {
        // push these points down the BSP tree into areas
        light->world->PushFrustumIntoTree( NULL, light, light->inverseBaseLightProject, bounds_zeroOneCube );
    }

Suppose there is a wall between areaA and areaB, with light in areaA.
The light sees the front side of the wall in areaA, which he won't cull away no matter what, but it does not drop shadows.
The back side of the wall is in areaB, which cast the shadows. But the light does not see it: it is occluded by the wall and not visible through portals.

Pretty sad.
stgatilov

stgatilov

22.12.2020 18:13

administrator   ~0013176

I think the line here must be crossed between closed (solid) and open (sheet) surfaces.

If an entity is composed of closed surfaces, then we can cull away its interaction if the entity is not visible from the light (shadow-casting one, of course).

The "if" above is not entirely right: it checks for prelightModel, which is the precomputed shadow for all world-area surfaces. In reality, area surfaces are not closed in most cases, thus it is not correct to prune them as suggested. However, most of the models are closed, and it is entirely OK to prune their interactions away, which could yield noticeable improvement in some cases.

So the idea is to store "closed" bit for surfaces and models, and do both branches here:
  FlowLightThroughPortals should decide which closed entities to consider for interactions
  PushFrustumIntoTree should decide which non-closed entities to consider for interactions
The problem is that this piece of code only decides which AREAs are visible by lights, not entities.
Moreover, it is done only when light position changes: it is not done every frame.

Perhaps it would make sense to run the same portal flow in idRenderWorldLocal::CreateLightDefInteractions.
Instead of simply taking all entities in all areas, go through portals and take only light-visible entities among closed ones.
Non-closed entities should be handled separately, e.g. by traversing areas -> entities.
stgatilov

stgatilov

26.03.2021 12:33

administrator   ~0013805

This forum thread shows that a lot of models are not closed enough:
  https://forums.thedarkmod.com/index.php?/topic/20850-improving-shadow-mapping-for-210/&do=findComment&comment=458348
(or we don't be able to detect it)

Issue History

Date Modified Username Field Change
09.03.2020 04:31 stgatilov New Issue
09.03.2020 04:31 stgatilov Status new => assigned
09.03.2020 04:31 stgatilov Assigned To => stgatilov
09.03.2020 04:32 stgatilov Relationship added related to 0005084
21.03.2020 17:43 stgatilov Target Version => TDM 2.09
05.12.2020 12:35 stgatilov Target Version TDM 2.09 => TDM 2.10
13.12.2020 17:32 stgatilov Note Added: 0013120
22.12.2020 18:13 stgatilov Note Added: 0013176
26.03.2021 12:33 stgatilov Note Added: 0013805
22.11.2021 14:04 stgatilov Target Version TDM 2.10 => TDM 2.11