View Issue Details

IDProjectCategoryView StatusLast Update
0006546The Dark ModCodingpublic28.07.2024 19:48
Reporterstgatilov Assigned Tostgatilov  
PrioritynormalSeverityfeatureReproducibilityN/A
Status assignedResolutionopen 
Target VersionTDM 2.13 
Summary0006546: Proper system for measuring light factor of bodies
DescriptionThere is so-called "light awareness system" which is used to measure how lit are various objects (e.g. guard bodies).
The value is later used in AI code to decide whether AI sees the object or not.
This system ignores projection/falloff textures and shadows.

The goal is to implement a system on CPU which would compute light value the same way as rendering shaders do it.
TagsNo tags attached.

Relationships

related to 0003584 resolvedgrayman Object Illumination code is wrong 

Activities

stgatilov

stgatilov

08.07.2024 20:36

administrator   ~0016789

First I committed generic and minor fixes/improvements, completely unrelated to the problem:
  r10808 Fixed bug in idWinding::ClearFree.
  r10809 Fixed self-assignment in idList and idHashIndex.
  r10810 idRenderWorldLocal::TraceAll: quickly retunr false for zero-length rays.
  r10811 Support TF_DEFAULT filtering in CPU-side idImage sampling.
  r10812 Added idList::FillZero method + converted some usages.

The following commits contain generic but more involved improvements:
  r10813 Support debug polygons with depthtest = false.
  r10814 Added idRenderWorld::DebugFilledBox method.
  r10815 Implemented exponential search algorithm.
  r10816 Exposed cubemap sampling on CPU as idImage::Sample method.
  r10817 Added a way to make image CPU-resident during runtime.
  r10818 Refactor loading particle collisions texture using new defer mechanism.
  r10819 Implemented generic Poisson sampling.
I tested this stuff independently, it should work fine =)

Finally some commits specific to the new system:
  r10820 Added idRenderModel::GetLoadVersion method to detect model reloads.
  r10821 Now it is possible to generate point samples on idRenderModel.
  r10822 Added LightEstimateSystem + LightQuerySystem to track light intensity at various objects.
The last is the main one: it adds both halves of the huge system.

The testmap is here:
  r17085 Added test map for debugging LightEstimateSystem.

So the new stuff is in trunk now, and it is possible to enable it by setting "g_lightQuotientAlgo 1".
However, I have not enabled it as new default yet.
I'm afraid I'll have to review all the usages because the new system work correctly only if you continuously "track" entities.
And the old system seems to enjoy quering intensity at random instant moments and doing nothing after that.

Debug visualization is controlled by cvar "g_showLIghtQuotient".
Also there are various settings in cvars "g_les*".
stgatilov

stgatilov

15.07.2024 10:14

administrator   ~0016795

Some generic fixes and improvements of LES:
  r10827 Set residency IR_BOTH if image is not found => defaulted.
  r10828 idRenderWorld::TraceAll now passes RenderEntity handle into filter too.
  r10832 Save/restore Light Estimate System.

And some commits for integration:
  r10829 Updated default track duration from 300 ms to 10 sec.
  r10833 Always track dead/unconscious AI bodies and dropped melee weapons in LES.

I tried looking the code which uses GetLightQuotient, and there are just too many nested usages.
That's why I concentrate on the cases where it is actually requested all the time, and they are:
  1) dead/KOed AI bodies
  2) dropped melee weapons
  3) alive AIs

Cases 1,2 should be covered now since they are simply tracked all the time.
Case 3 is partly covered by default track duration larger than visual stim period, the first stim will most likely return zero value though.

P.S. I have noticed that there are tons of non-entity queries into the old LAS.
Replacing them with the new LES will be hard =(
stgatilov

stgatilov

20.07.2024 08:41

administrator   ~0016799

I looked into non-entity queries into LAS:

LAS.queryLightingAlongBestLine:
    Only used in idEntity::GetLightQuotient, which I replaced completely

LAS.queryLightingAlongLine:

    idAI::GetMaximumObservationDistanceForPoints(p1, p2) -> float
        CanSeePositionExt(pos, fov, lit) -> bool
            script canSeePositionExt
                never used with lit = true
            (there are other C++ usages with lit = false)

    idEntity::GetLightQuotient
        This is completely replaced

    CDarkmodAASHidingSpotFinder::TestHidingPoint(TONS of args)
        This whole class is dead because cv_ai_search_type = 4

    CSearchManager::GetNextSearchSpot(Search*, idAI*, idVec3&)
        Only used when canSearchCooperatively = 0, which is non-skelly undead, spiders, non-humanoids.

So it seems that all queries into LAS were disabled, except for rare monsters.
I guess people simply don't bother about how properly these monsters search, since they are not sentient.
I think we can simply drop illumination check in this case, then they should behave like humaniods I believe.
stgatilov

stgatilov

20.07.2024 10:28

administrator   ~0016800

Last edited: 20.07.2024 12:18

Oops, I think I missed some more usages of GetMaximumObservationDistanceForPoints.

    CanSeeTargetPoint(pt, entity, lit)
        CanSeeRope
        State::OnVisualStim in case of door
    GetObservationPosition(pt)
        script getObservationPosition
            used by observer_ai script
        CSearchManager::JoinSearch if destination is unreachable

In case of doors/ropes, I can probably support "light of this point on this entity" query.

(TEST EDIT)
stgatilov

stgatilov

28.07.2024 17:24

administrator   ~0016806

Last edited: 28.07.2024 19:48

More commits:
  r10834 g_lightQuotientAlgo is now global cvar, and we can disable LAS completely.
  r10835 Now LightQuerySystem processes queries in parallel using job system.
  r10836 Disabled parallel LightQuerySystem processing.
  r10837 Accelerate bounding box check in TraceAll, don't instantiate dynamic models for it.
  r10844 Set g_lightQuotientAlgo 1 by default.

So the new system is now enabled, and works for entities (bodies, weapons).
Also I believe I redirected point queries from LAS to entity queries in the new system (ropes, doors).

I don't remember if any queries to LAS remain, but now it is easy to check: "g_lightQuotientAlgo 2" prints warnings on such queries.

Issue History

Date Modified Username Field Change
25.06.2024 07:23 stgatilov New Issue
25.06.2024 07:23 stgatilov Status new => assigned
25.06.2024 07:23 stgatilov Assigned To => stgatilov
02.07.2024 00:27 nbohr1more Relationship added related to 0003584
08.07.2024 20:36 stgatilov Note Added: 0016789
15.07.2024 10:14 stgatilov Note Added: 0016795
20.07.2024 08:41 stgatilov Note Added: 0016799
20.07.2024 10:28 stgatilov Note Added: 0016800
20.07.2024 12:18 stgatilov Note Edited: 0016800
28.07.2024 17:24 stgatilov Note Added: 0016806
28.07.2024 19:48 stgatilov Note Edited: 0016806