Author Topic: Exclusion mask update timing  (Read 103 times)

frozenempire

  • Full Member
  • ***
  • Posts: 233
    • View Profile
    • The Frozen Empire
Exclusion mask update timing
« on: September 13, 2020, 12:26:32 PM »
Hi,

Maybe you can throw some light on an issue I'm having trouble with...

In my game there comes a point where I need to instantiate some objects that should be excluded from the global snow effect (game characters)

After they are instantiated, on that frame where that happens, they appear in the scene _with_ snow covering.
On the next frame, they are excluded from the snow correctly.
I would like that on the 1st frame they appear, they are excluded from the snow correctly...

If I understand correctly, the renderer.isVisible property is used to determine which objects are added to the command buffer (during preCull) and I suspect this isVisible property is only updated for a renderer by the built-in engine upon actual culling... hence the frame delay...

So I tried an alternative approach, instantiate the object at a very small scale (so it is visible to the camera and gets included in the exclusion list), and then increase the scale the following frame.
However it still appears that in the frame where the scale is increased, the snow exclusion mask is still a frame behind so I get the same effect.
I'm also calling RefreshExcludedObjects on the frame where they are instantiated, but it didn't solve it.

Hopefully I've described the issue clearly enough.
If you have any suggestions about how to get the exclusion mask up to date on the frame where new objects are instantiated, then I would be grateful.

Many thanks

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6214
    • View Profile
Re: Exclusion mask update timing
« Reply #1 on: September 14, 2020, 06:37:20 PM »
Hi,
Try latest version (download it again). The RefreshExcludedObjects now accepts a second argument which you can use to force the system ignore the isVisible status during the first frames after the refresh.
Let me know if that solves the issue.

frozenempire

  • Full Member
  • ***
  • Posts: 233
    • View Profile
    • The Frozen Empire
Re: Exclusion mask update timing
« Reply #2 on: September 14, 2020, 11:05:30 PM »
Thanks I'll check that out...

I do have a slight concern that it will mean that ALL exclusion meshes will get rendered during that force and there are a lot (>8000!), causing a spike....

But let me test and I'll get back to you

Many thanks

frozenempire

  • Full Member
  • ***
  • Posts: 233
    • View Profile
    • The Frozen Empire
Re: Exclusion mask update timing
« Reply #3 on: September 15, 2020, 12:14:39 AM »
Well the mod does ensure the exclusion list is up to date on the same scan...

...but as suspected, there is a significant frame spike whilst it renders ALL the >8000 renderers (only about 50-100 are visible in the camera at a time).

I'm only ever adding/removing a few at any time from the total list, so to rescan the whole lot, or to temporarily make the whole lot visible isn't really a viable solution for my case.

I'm now considering how to implement a custom visibility function that doesn't rely upon r.isVisible

Something along the lines of:
- Manually adding/removing renderers to the exclusion list when I instantiate/destroy, rather than rescanning the whole scene each time
- Keeping track of which renderers are surrounding the camera within a certain distance and only testing those for visibilty using something like GeometryUtility.TestPlanesAABB(planes, r.bounds) which can be done during precull for any objects that might have been added during the frame

I'll let you know how I get on, but do share any other thoughts you might have on how to achieve it without a frame spike

Appreciate your support, many thanks

« Last Edit: September 15, 2020, 07:35:31 AM by frozenempire »

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6214
    • View Profile
Re: Exclusion mask update timing
« Reply #4 on: September 15, 2020, 08:00:30 AM »
Hm, yes - that's a previsible side effect. Sure, one option would be to pass an optional list of renderers to the RefreshExcludedObjects method - that would be more granular and effective.