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

Layer support in renderer #1645

Merged
merged 28 commits into from May 23, 2024
Merged

Conversation

heinezen
Copy link
Member

@heinezen heinezen commented May 3, 2024

Adds support for multi-mesh objects in the level 2 renderer as well as sorting by layers.

Terrain rendering

  • Gamestate
    • Create example terrain layouts
    • New test terrain asset
  • Renderer
    • Split terrain chunk into multiple meshes
    • Render meshes individually

Layer support

  • Sort animation layer definitions by layer position when loading assets
  • Split animation layers into multiple meshes
  • Render meshes individually
  • Sort renderables by layer position in render pass

@heinezen heinezen added improvement Enhancement of an existing component area: renderer Concerns our graphics renderer lang: c++ Done in C++ code labels May 3, 2024
@heinezen heinezen marked this pull request as draft May 3, 2024 19:13
@heinezen heinezen force-pushed the feature/multi-terrain-mesh branch from 9117cfc to 5a0d62e Compare May 3, 2024 19:33
@heinezen heinezen force-pushed the feature/multi-terrain-mesh branch from afd633f to a340443 Compare May 8, 2024 23:07
@heinezen heinezen added the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label May 8, 2024
@SFTbot SFTbot removed the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label May 8, 2024
@heinezen heinezen changed the title Layer support for level 2 renderer Layer support in renderer May 8, 2024
@heinezen heinezen marked this pull request as ready for review May 8, 2024 23:40
@heinezen heinezen requested a review from TheJJ May 8, 2024 23:41
@heinezen
Copy link
Member Author

heinezen commented May 8, 2024

@TheJJ There might be a better approach to do layer support, so your input would be nice to have. In this PR, I added layer suppport into the level 1 renderer (in RenderPass), but there might be a case for moving it to the level 2 renderer.

Here are some advantages/disadvantages I see with each approach:

Layer support in Level 1 (this PR)

  • Easy to use (sorting into layers works automatically)
  • Layer support is available for all render passes by default (however, only world and terrain stages in level 2 use layers)
  • Introduces some complexity and overhead that might slow down rendering pipeline
    • more if statements to check for various things
    • overhead for keeping renderables sorted

Layer support in Level 2

We could do this by emulating each layer with an individual render pass per layer. These passes would all target the same framebuffer.

  • Less complexity in level 1
  • Maybe code duplication because layers would have to be managed by each render stage
  • We have to avoid binding the framebuffer too often because this operation is super expensive

@heinezen heinezen force-pushed the feature/multi-terrain-mesh branch from a340443 to 52663d6 Compare May 9, 2024 00:03
@BluntSlapp
Copy link

LG2M

Copy link
Member

@TheJJ TheJJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome!

@TheJJ TheJJ merged commit 1904244 into SFTtech:master May 23, 2024
13 checks passed
@TheJJ
Copy link
Member

TheJJ commented May 23, 2024

let's use this working approach for now, but some thoughts on the alternative:

having this approach now certailiny works, and we can optimize it further.
i think the more logical approach would be to have something layer-like in both renderer levels.

since the only real layer users are objects (town center e.g.) and the terrain, they can do multiple layer1-passes to draw their layers. to reduce the code duplication when we use layer2-managed render passes, some minimal support (or "optional" activation of it) in layer1 could then be used by layer2 code.

to bind the framebuffer too often, the resulting layer1 instructions somehow have to be batched. which was our long-term idea anyway. so we submit everything (and have it i memory, yes, maybe one chunk after the other?) and optimize and order it, then draw it to the framebuffer with minimal binding switches (also for textures, shaders, ...).

nevertheless as a first step this is approach is good, and as we progress we'll see what we can keep as generalization in layer1 and what should move to layer2, then well converge to the best™ solution i hope :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: renderer Concerns our graphics renderer improvement Enhancement of an existing component lang: c++ Done in C++ code
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants