bevy/crates
Robert Swain c061ec33c8 bevy_pbr2: Fix clustering for orthographic projections (#3316)
# Objective

PBR lighting was broken in the new renderer when using orthographic projections due to the way the depth slicing works for the clusters. Fix it.

## Solution

- The default orthographic projection near plane is 0.0. The perspective projection depth slicing does a division by the near plane which gives a floating point NaN and the clustering all breaks down.
- Orthographic projections have a linear depth mapping, so it made intuitive sense to me to do depth slicing with a linear mapping too. The alternative I saw was to try to handle the near plane being at 0.0 and using the exponential depth slicing, but that felt like a hack that didn't make sense.
- As such, I have added code that detects whether the projection is orthographic based on `projection[3][3] == 1.0` and then implemented the orthographic mapping case throughout (when computing cluster AABBs, and when mapping a view space position (or light) to a cluster id in both the rust and shader code).

## Screenshots
Before:
![before](https://user-images.githubusercontent.com/302146/145847278-5b1bca74-fbad-4cc5-8b49-384f6a377fdc.png)
After:
<img width="1392" alt="Screenshot 2021-12-13 at 16 36 53" src="https://user-images.githubusercontent.com/302146/145847314-6f3a2035-5d87-4896-8032-0c3e35e15b7d.png">
Old renderer (slightly lighter due to slight difference in configured intensity):
<img width="1392" alt="Screenshot 2021-12-13 at 16 42 23" src="https://user-images.githubusercontent.com/302146/145847391-6a5e6fe0-22da-4fc1-a6c7-440543689a63.png">
2021-12-14 23:42:35 +00:00
..
bevy_app Update dependencies ron winit& fix cargo-deny lists (#3244) 2021-12-09 20:14:00 +00:00
bevy_asset Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
bevy_audio Remove wasm audio feature flag for 2021 (#3000) 2021-11-11 01:17:38 +00:00
bevy_core Rename fixed timestep state and add a test (#3260) 2021-12-12 21:26:40 +00:00
bevy_core_pipeline Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
bevy_derive Merge New Renderer 2021-11-22 23:57:42 -08:00
bevy_diagnostic Update to edition 2021 on master (#3028) 2021-10-27 00:12:14 +00:00
bevy_dylib Update to edition 2021 on master (#3028) 2021-10-27 00:12:14 +00:00
bevy_dynamic_plugin Update to edition 2021 on master (#3028) 2021-10-27 00:12:14 +00:00
bevy_ecs Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
bevy_ecs_compile_fail_tests Fix clippy lints for 1.57 (#3238) 2021-12-02 23:40:37 +00:00
bevy_gilrs Update to edition 2021 on master (#3028) 2021-10-27 00:12:14 +00:00
bevy_gltf Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
bevy_input Documented and tested Axis<T> (#3276) 2021-12-11 23:31:46 +00:00
bevy_internal Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
bevy_log Merge New Renderer 2021-11-22 23:57:42 -08:00
bevy_macro_utils Fix path used by macro not considering that we can use a sub-crate (#3178) 2021-11-29 23:10:31 +00:00
bevy_math Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
bevy_pbr bevy_pbr2: Fix clustering for orthographic projections (#3316) 2021-12-14 23:42:35 +00:00
bevy_reflect Update dependencies ron winit& fix cargo-deny lists (#3244) 2021-12-09 20:14:00 +00:00
bevy_render Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
bevy_scene Update dependencies ron winit& fix cargo-deny lists (#3244) 2021-12-09 20:14:00 +00:00
bevy_sprite Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
bevy_tasks Add readme to errors crate and clean up cargo files (#3125) 2021-11-13 23:06:48 +00:00
bevy_text Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
bevy_transform Add despawn_children (#2903) 2021-12-09 20:42:44 +00:00
bevy_ui Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
bevy_utils Merge New Renderer 2021-11-22 23:57:42 -08:00
bevy_window Update dependencies ron winit& fix cargo-deny lists (#3244) 2021-12-09 20:14:00 +00:00
bevy_winit Update dependencies ron winit& fix cargo-deny lists (#3244) 2021-12-09 20:14:00 +00:00
crevice Fix clippy lints for 1.57 (#3238) 2021-12-02 23:40:37 +00:00