Skip to content

TrackedRenderPass driven RenderPhases #7080

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

Closed

Conversation

kurtkuehnert
Copy link
Contributor

@kurtkuehnert kurtkuehnert commented Jan 3, 2023

Objective

The current code for creating render passes and executing render phases is quite boilerplate-heavy and repetitive.

I have experimented with further improving the API, based on the proposal by @cart (posted in #7043 (comment)):

// This would create and set up a TrackedRenderPass, which would set the viewport, if it is
// configured on the camera. "pass" would need to be a wrapper over TrackedRenderPass.
let pass = camera.begin_render_pass(render_context, view_entity);
pass.render_phase(opaque_phase, world);

Solution

This PR comprises two changes:

1. The RenderPhases are now executed directly using the TrackedRenderPass, with the API described above.

  • Therefore, each TrackedRenderPass is associated with a view_entity.
  • Additionally, this alleviates the need to pass around the view_entitys in the render method of Draw functions. Instead, they can be accessed directly from the TrackedRenderPass if they are needed.
old
opaque_phase.render(&mut pass, world, view_entity);

new
pass.render_phase(opaque_phase, world);

2. I have added a TrackedRenderPass::create_for_camera method, that sets up the render pass based on the camera view and depth target.

  • This is an attempt to create a method similar to the one proposed by @cart.
let pass = camera.begin_render_pass(render_context, view_entity);
vs
let pass = TrackedRenderPass::create_for_camera(
    render_context,
    "main_alpha_mask_pass_3d",
    view_entity,
    target,
    Operations {
        load: LoadOp::Load,
        store: true,
    },
    Some(depth),
    Some(Operations {
        load: LoadOp::Load,
        store: true,
    }),
    &camera.viewport,
);
  • This method replaces the setup for the 2d and 3d pass but is not general enough to accommodate the shadow and the UI pass as well.

I think that 1. is a good idea because from what I have gathered a TrackedRenderPass is always associated with a view_entity anyway.

IMO, 2. is less ideal and I am interested if you have got a better idea. There are just too many different components at play that might or might not be required. I still believe that setting up the render attachments in a way that is simpler and more clear is a worthwhile goal though.


Changelog

Todo

Migration Guide

Todo

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Jan 3, 2023
@kurtkuehnert kurtkuehnert force-pushed the camera_tracked_render_pass branch from 26234c8 to 0ee2d18 Compare January 4, 2023 08:34
@james7132 james7132 self-requested a review January 6, 2023 04:05
@kurtkuehnert kurtkuehnert mentioned this pull request Jan 16, 2023
3 tasks
@kurtkuehnert
Copy link
Contributor Author

Please take a look at #7227 instead.

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 C-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants