-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Add a custom render phase example #16916
base: main
Are you sure you want to change the base?
Conversation
bf96be6
to
c37b089
Compare
The generated |
The generated |
The generated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great start. I think it would be cool if this did something more notable like an outline. I don't have many specific comments, other than I think it would be nice if we had a way to demonstrate a custom draw command here, but it's difficult for me to think what that would be. The only other thing is that we should demonstrate the cold specialization and retained bin pattern once those are settled, but this is also an issue with our other existing examples and out of scope here. This is going to be sooo helpful to share I think and we can def iterate more, tysm for doing this.
Yeah, an outline would be cool, but it would require a lot more code and the example is already really long. It's for the same reason I used a sorted phase and didn't use cold specialization. It made the code even more complicated. IIRC we already have an example showing a custom draw command. If not, we could set the shader color from a uniform that is bound in a custom command. Shouldn't be too hard to add to this example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've run the example on an m1 mac and previously used this example (plus a custom post_process) to implement outlines.
I think the outlines are probably more than this PR should sustain, I like that it stops at rendering to the view as that's a concrete jumping-off point for anyone who wants to get started.
The example shows off a lot of useful concepts already. The only real downside I see is that adding hdr to the camera will break it due to the color attachment format (maybe worth changing in a future PR).
The miri CI failure was a github network request issue, so I've moved it to ready-for-final since all other ci is passing and it now has two reviews. |
Okay I'm convinced, it's definitely better to start small.
It's the custom phase item example which this one kinda overlaps with. I don't think we need to make this an everything example, just interacting with some of the more complex retained rendering stuff we've added recently is on my radar as conspicuously missing from our examples atm. This is covering a huge gap though so let's def just start here! |
//! Sometimes, you may want to only draw a subset of meshes before or after the builtin phase. In | ||
//! those situations you need to write your own phase. | ||
//! | ||
//! This example showcases how writing a custom phase to draw a stencil of a bevy mesh could look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to google it but could only find some vague definitions; what is a 'stencil' in this context?
I'm not sure what i'm looking for when looking at the red cube
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It refers to essentially drawing the shape of the mesh. It's a bit of graphics programming terminology, but it's useful when you want to mask out something or want to create outlines. It's not really the purpose of the example though. It was just to have something a bit more concrete since it's most likely the most common use case for a custom phase.
} | ||
} | ||
|
||
impl GetBatchData for StencilPipeline { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the batching do in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's part of the future docs improvements I want to do, but the docs on the trait explain what is going on a bit more and I didn't want to just copy paste the doc, but maybe I should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super helpful example!
As a rendering noob, most of it made sense to me (the only thing I didn't understand is the batching logic and how it's used)
Objective
Solution
Showcase
Notes
More docs to explain what is going on is still needed but the example works and can already help some people.
We might want to consider using a batched phase and cold specialization in the future, but the example is already complex enough as it is.