bevy/crates
Carter Anderson b6e46a73cd Rework ViewTarget to better support post processing (#6415)
# Objective

Post processing effects cannot read and write to the same texture. Currently they must own their own intermediate texture and redundantly copy from that back to the main texture. This is very inefficient.

Additionally, working with ViewTarget is more complicated than it needs to be, especially when working with HDR textures. 

## Solution

`ViewTarget` now stores two copies of the "main texture". It uses an atomic value to track which is currently the "main texture" (this interior mutability is necessary to accommodate read-only RenderGraph execution). 

`ViewTarget` now has a `post_process_write` method, which will return a source and destination texture. Each call to this method will flip between the two copies of the "main texture".

```rust
let post_process = render_target.post_process_write();
let source_texture = post_process.source;
let destination_texture = post_process.destination;
```
The caller _must_ read from the source texture and write to the destination texture, as it is assumed that the destination texture will become the new "main texture".


For simplicity / understandability `ViewTarget` is now a flat type. "hdr-ness" is a property of the `TextureFormat`. The internals are fully private in the interest of providing simple / consistent apis. Developers can now easily access the main texture by calling `view_target.main_texture()`.

HDR ViewTargets no longer have an "ldr texture" with `TextureFormat::bevy_default`. They _only_ have their two "hdr" textures. This simplifies the mental model.  All we have is the "currently active hdr texture" and the "other hdr texture", which we flip between for post processing effects.

The tonemapping node has been rephrased to use this "post processing pattern". The blit pass has been removed, and it now only runs a pass when HDR is enabled. Notably, both the input and output texture are assumed to be HDR. This means that tonemapping behaves just like any other "post processing effect". It could theoretically be moved anywhere in the "effect chain" and continue to work.

In general, I think these changes will make the lives of people making post processing effects much easier. And they better position us to start building higher level / more structured  "post processing effect stacks".

---

## Changelog

- `ViewTarget` now stores two copies of the "main texture". Calling `ViewTarget::post_process_write` will flip between copies of the main texture.
2022-10-31 20:22:18 +00:00
..
bevy_animation add ReflectAsset and ReflectHandle (#5923) 2022-10-28 20:42:33 +00:00
bevy_app Unique plugin (#6411) 2022-10-31 16:12:19 +00:00
bevy_asset Rename Handle::as_weak() to cast_weak() (#5321) 2022-10-28 22:43:14 +00:00
bevy_audio Add a way to toggle AudioSink (#6321) 2022-10-31 15:57:51 +00:00
bevy_core add ReflectAsset and ReflectHandle (#5923) 2022-10-28 20:42:33 +00:00
bevy_core_pipeline Rework ViewTarget to better support post processing (#6415) 2022-10-31 20:22:18 +00:00
bevy_derive Bump Version after Release (#5576) 2022-08-05 02:03:05 +00:00
bevy_diagnostic Add Exponential Moving Average into diagnostics (#4992) 2022-10-24 13:46:37 +00:00
bevy_dylib Bump Version after Release (#5576) 2022-08-05 02:03:05 +00:00
bevy_dynamic_plugin Bump Version after Release (#5576) 2022-08-05 02:03:05 +00:00
bevy_ecs Remove outdated uses of single-tuple bundles (#6406) 2022-10-29 18:15:28 +00:00
bevy_ecs_compile_fail_tests fix: specify required trybuild patch version (#6333) 2022-10-25 10:21:31 +00:00
bevy_encase_derive Bump Version after Release (#5576) 2022-08-05 02:03:05 +00:00
bevy_gilrs feat: add GamepadInfo, expose gamepad names (#6342) 2022-10-24 14:33:50 +00:00
bevy_gltf fix nightly clippy warnings (#6395) 2022-10-28 21:03:01 +00:00
bevy_hierarchy Add methods to Query<&Children> and Query<&Parent> to iterate over descendants and ancestors (#6185) 2022-10-31 15:57:50 +00:00
bevy_input Derive Reflect + FromReflect for input types (#6232) 2022-10-26 19:52:20 +00:00
bevy_internal Unique plugin (#6411) 2022-10-31 16:12:19 +00:00
bevy_log Update tracing-chrome to 0.6.0 (#6398) 2022-10-28 21:51:38 +00:00
bevy_macro_utils fix nightly clippy warnings (#6395) 2022-10-28 21:03:01 +00:00
bevy_math add serialize feature to bevy_transform (#6379) 2022-10-31 16:12:15 +00:00
bevy_mikktspace Bump Version after Release (#5576) 2022-08-05 02:03:05 +00:00
bevy_pbr Freeing memory held by visible entities vector (#3009) 2022-10-31 15:36:08 +00:00
bevy_ptr Bump Version after Release (#5576) 2022-08-05 02:03:05 +00:00
bevy_reflect add ReflectDefault to std types (#6429) 2022-10-31 16:35:22 +00:00
bevy_render Rework ViewTarget to better support post processing (#6415) 2022-10-31 20:22:18 +00:00
bevy_scene bevy_scene: Serialize entities to map (#6416) 2022-10-31 16:35:18 +00:00
bevy_sprite Remove outdated uses of single-tuple bundles (#6406) 2022-10-29 18:15:28 +00:00
bevy_tasks fix nightly clippy warnings (#6395) 2022-10-28 21:03:01 +00:00
bevy_text Rename Handle::as_weak() to cast_weak() (#5321) 2022-10-28 22:43:14 +00:00
bevy_time Add FromReflect for Timer (#6422) 2022-10-30 16:02:31 +00:00
bevy_transform add serialize feature to bevy_transform (#6379) 2022-10-31 16:12:15 +00:00
bevy_ui Remove outdated uses of single-tuple bundles (#6406) 2022-10-29 18:15:28 +00:00
bevy_utils Remove Sync bound from Local (#5483) 2022-09-12 04:15:55 +00:00
bevy_window Fix return_after_run example (#6420) 2022-10-31 16:35:20 +00:00
bevy_winit do not set cursor grab on window creation if not asked for (#6381) 2022-10-31 16:12:18 +00:00