Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable rendering of unseen tilemap layers #1373

Open
cosmiccoincidence opened this issue Dec 3, 2023 · 3 comments
Open

Disable rendering of unseen tilemap layers #1373

cosmiccoincidence opened this issue Dec 3, 2023 · 3 comments
Labels
Bounty: 20 dollars 💰 Value of the bounty. Do not put this tag without the bounty tag. Difficulty: hard 🌵 Things are getting spiky ! Feature A new system or other feature. Tilemaps Tasks related to the tilemap system or its connectors.

Comments

@cosmiccoincidence
Copy link
Member

Summary

If we cant seen them, why render them? Disable rendering of unseen tilemap layers.

Goal

If a tile and all of its 8 neighbors (4 sides + 4 corners) have an occupied "turf" layer, do not render the following layers:

  • plenums
  • pipes
  • disposals
  • wires
@cosmiccoincidence cosmiccoincidence added Feature A new system or other feature. Tilemaps Tasks related to the tilemap system or its connectors. Difficulty: medium 🥼 For those that already have some understanding of the code base. labels Dec 3, 2023
@stilnat
Copy link
Contributor

stilnat commented Dec 3, 2023

I suggest creating a "render system" for that, on the same models of other systems, specially for custom rendering.
Note that occlusion culling is not an option as Unity does not support it natively for dynamic objects.
Doing it efficiently is actually pretty difficult I think.
An option could be the following :

  • run frequently (maybe once every frame) the following algorithm :
  • Get approximately all visible tiles by the player (a bit more is better than not enough)
  • For each tile, check if it has turf, if yes, continue, otherwise, mark all its neighbours as "should render"
  • deactivate all tiles (under turf) that are not marked as should render.

Another option would be to compute a full "should render" map at game start, and update it each time a player remove or add a turf, but we should be careful with that because it involves using server data, fine if can use data already sent, less fine if we have to send some just for that.

could also imagine reducing the work load by splitting the computation over multiple frame, first checking tiles very close to player, and then the one further. Putting difficulty hard on this one.

Also since we said we're trying to use a bit more bounties, this task probably deserve one. Any other efficient solution is welcomed.

@stilnat stilnat added Difficulty: hard 🌵 Things are getting spiky ! Bounty: 20 dollars 💰 Value of the bounty. Do not put this tag without the bounty tag. and removed Difficulty: medium 🥼 For those that already have some understanding of the code base. labels Dec 3, 2023
@cosmiccoincidence
Copy link
Member Author

@stilnat outdated branch used deferred rendering, which has not been ported yet. I believe occlusion culling would be possible with that.

@stilnat
Copy link
Contributor

stilnat commented Dec 4, 2023

So I read about deferred rendering, take my words with a pinch of salt because I do not know much about this stuff. I believe deferred rendering does not have any impact on which geometry is rendered. It's a shading screen space method, so it only cares about visible portions of objects, hence maybe the confusion, I'm not sure if this data is easily retrievable.

Also according to Wikipedia :

In the field of 3D computer graphics, deferred shading is a screen-space shading technique that is performed on a second rendering pass, after the vertex and pixel shaders are rendered.

Wikipedia clearly say the technique is used after rendering all geometry, so it should not impact at all the number of rendered vertices.

Regarding dynamic occlusion culling, Unity say this :

You can use occlusion culling to occlude Dynamic GameObjects, but Dynamic GameObjects cannot occlude other GameObjects. If your Project generates Scene geometry at runtime, then Unity’s built-in occlusion culling is not suitable for your Project.

Our turf object are dynamics, hence there's no built in Unity solution for that. From what I've read about dynamic occlusion culling, it's an open problem, there's no single fit all solution. In our case, we are lucky that our geometry is extremely simple (squares of same size), so the algorithm I suggested above might be enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bounty: 20 dollars 💰 Value of the bounty. Do not put this tag without the bounty tag. Difficulty: hard 🌵 Things are getting spiky ! Feature A new system or other feature. Tilemaps Tasks related to the tilemap system or its connectors.
Projects
None yet
Development

No branches or pull requests

2 participants