Skip to content

[Merged by Bors] - Remove the early exit to make sure the prepass textures are cleared - #7891

Closed
geieredgar wants to merge 1 commit into
bevyengine:mainfrom
geieredgar:always-run-prepass
Closed

geieredgar wants to merge 1 commit into
bevyengine:mainfrom
geieredgar:always-run-prepass

Conversation

@geieredgar

@geieredgar geieredgar commented Mar 4, 2023 •

Copy link
Copy Markdown
Contributor

Objective

Solution

  • Remove the early exit to make sure the prepass textures are cleared.

@alice-i-cecile alice-i-cecile added this to the 0.10 milestone Mar 4, 2023
@JMS55

JMS55 commented Mar 4, 2023

Copy link
Copy Markdown
Contributor

The fix seems to work. I'm somewhat confused on the concept though. Say you have a camera with DepthPrepass, but don't have any meshes with prepass_enabled. What happens both in terms of what depth textures get generated, and how the main pass uses it?

@geieredgar

geieredgar commented Mar 4, 2023 •

Copy link
Copy Markdown
Contributor Author

With this we always begin a RenderPass, which will clear the specified color and depth attachments (the prepass specific textures). If there are no meshes, there are no draw calls so the textures will stay in their cleared state. Previously, because we exited early, no render pass was started so the textures stayed in their old state from the previous frame.

@geieredgar geieredgar changed the title Remove the early exit to make sure the depth buffer is cleared Remove the early exit to make sure the prepass textures are cleared Mar 4, 2023
@JMS55

JMS55 commented Mar 4, 2023

Copy link
Copy Markdown
Contributor

That much makes sense to me. What confuses me is, what happens in the main pass then? Presumably it has an empty depth texture, which seems like it would cause problems?

@geieredgar

geieredgar commented Mar 4, 2023 •

Copy link
Copy Markdown
Contributor Author

The depth texture is cleared with the value 0.0, which I assume is the depth value at the far plane. So fragments inside the frustum should always pass the depth test, assuming the depth test is set to greater or equal (if the depth of the near plane is positive). If that is the case, it should not cause any issues.

@JMS55 JMS55 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

After reading up on how depth testing works, this lgtm now :)

@IceSentry IceSentry left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I originally had the if there to avoid unnecessary work, but I guess it's not that much code that ends up running when these are empty anyway.

@JMS55

JMS55 commented Mar 4, 2023

Copy link
Copy Markdown
Contributor

The alternative to this would be to set a flag so that the main pass clears the depth texture itself. I don't think that's worth it, this is an unlikely situation to come up anyways.

@robtfm robtfm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i think this is fine. the node won't get this far if no prepass_enabled materials are used as the query above will not match (no RenderPhase would be added), so there won't be a perf impact for no-prepass use cases.

@robtfm

robtfm commented Mar 4, 2023

Copy link
Copy Markdown
Contributor

set a flag so that the main pass clears the depth texture itself

yes updating the camera's depth load op would be better so we don't need to check for all possible prepass markers in the core_3d node. something to bear in mind for if we move the rendergraph to a pure schedule.

@superdump superdump added the A-Rendering Drawing game state to the screen label Mar 4, 2023

@superdump superdump left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

bors r+

bors Bot pushed a commit that referenced this pull request Mar 4, 2023
…7891)

# Objective

- Fixes #7888.

## Solution

- Remove the early exit to make sure the prepass textures are cleared.
@bors bors Bot changed the title Remove the early exit to make sure the prepass textures are cleared [Merged by Bors] - Remove the early exit to make sure the prepass textures are cleared Mar 4, 2023
@bors bors Bot closed this Mar 4, 2023
ProfLander pushed a commit to Lander-Rust/bevy that referenced this pull request Mar 19, 2023
…evyengine#7891)

# Objective

- Fixes bevyengine#7888.

## Solution

- Remove the early exit to make sure the prepass textures are cleared.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prepass should run even when phases are empty

6 participants