bevy/crates
Marco Buono 91c467ebfc
Gate diffuse and specular transmission behind shader defs (#11627)
# Objective

- Address #10338

## Solution

- When implementing specular and diffuse transmission, I inadvertently
introduced a performance regression. On high-end hardware it is barely
noticeable, but **for lower-end hardware it can be pretty brutal**. If I
understand it correctly, this is likely due to use of masking by the GPU
to implement control flow, which means that you still pay the price for
the branches you don't take;
- To avoid that, this PR introduces new shader defs (controlled via
`StandardMaterialKey`) that conditionally include the transmission
logic, that way the shader code for both types of transmission isn't
even sent to the GPU if you're not using them;
- This PR also renames ~~`STANDARDMATERIAL_NORMAL_MAP`~~ to
`STANDARD_MATERIAL_NORMAL_MAP` for consistency with the naming
convention used elsewhere in the codebase. (Drive-by fix)

---

## Changelog

- Added new shader defs, set when using transmission in the
`StandardMaterial`:
  - `STANDARD_MATERIAL_SPECULAR_TRANSMISSION`;
  - `STANDARD_MATERIAL_DIFFUSE_TRANSMISSION`;
  - `STANDARD_MATERIAL_SPECULAR_OR_DIFFUSE_TRANSMISSION`.
- Fixed performance regression caused by the introduction of
transmission, by gating transmission shader logic behind the newly
introduced shader defs;
- Renamed ~~`STANDARDMATERIAL_NORMAL_MAP`~~ to
`STANDARD_MATERIAL_NORMAL_MAP` for consistency;

## Migration Guide

- If you were using `#ifdef STANDARDMATERIAL_NORMAL_MAP` on your shader
code, make sure to update the name to `STANDARD_MATERIAL_NORMAL_MAP`;
(with an underscore between `STANDARD` and `MATERIAL`)
2024-02-02 15:01:56 +00:00
..
bevy_a11y resolve all internal ambiguities (#10411) 2024-01-09 19:08:15 +00:00
bevy_animation Replace the cubic_spline_interpolation macro with a generic function (#11605) 2024-01-29 19:50:30 +00:00
bevy_app Expressively define plugins using functions (#11080) 2024-01-27 02:40:15 +00:00
bevy_asset Fix AssetTransformer breaking LabeledAssets (#11626) 2024-02-02 14:57:31 +00:00
bevy_audio Optional override for global spatial scale (#10419) 2024-01-25 16:29:35 +00:00
bevy_core Adding derive Reflect for tick structs (#11641) 2024-02-01 16:11:32 +00:00
bevy_core_pipeline RenderGraph Labelization (#10644) 2024-01-31 14:51:19 +00:00
bevy_derive Reexport winit::platform::android::activity::* in bevy_winit (#11011) 2023-12-19 20:15:03 +00:00
bevy_diagnostic Replace DiagnosticId by DiagnosticPath (#9266) 2024-01-20 15:42:51 +00:00
bevy_dylib Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_dynamic_plugin Mark DynamicPluginLoadError internal error types as source (#11618) 2024-01-30 23:37:00 +00:00
bevy_ecs Adding derive Reflect for tick structs (#11641) 2024-02-01 16:11:32 +00:00
bevy_ecs_compile_fail_tests Dynamic queries and builder API (#9774) 2024-01-16 19:16:49 +00:00
bevy_encase_derive Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_gilrs Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_gizmos RenderAssetPersistencePolicy → RenderAssetUsages (#11399) 2024-01-30 13:22:10 +00:00
bevy_gltf RenderAssetPersistencePolicy → RenderAssetUsages (#11399) 2024-01-30 13:22:10 +00:00
bevy_hierarchy Make the MapEntities trait generic over Mappers, and add a simpler EntityMapper (#11428) 2024-01-28 19:51:46 +00:00
bevy_input Fix cyclic dep (#11523) 2024-01-25 17:44:32 +00:00
bevy_internal Add Accessibility plugin to default plugins docs (#11512) 2024-01-28 10:04:43 +00:00
bevy_log move once from bevy_log to bevy_utils, to allow for it's use in bevy_ecs (#11419) 2024-01-19 06:07:41 +00:00
bevy_macro_utils Bump toml_edit in build-template-pages tool (#11342) 2024-01-16 05:23:18 +00:00
bevy_macros_compile_fail_tests Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_math Rename RayTest to RayCast (#11635) 2024-02-02 15:01:04 +00:00
bevy_mikktspace Enable the unsafe_op_in_unsafe_fn lint (#11591) 2024-01-28 23:18:11 +00:00
bevy_pbr Gate diffuse and specular transmission behind shader defs (#11627) 2024-02-02 15:01:56 +00:00
bevy_ptr bevy_ptr: fix unsafe_op_in_unsafe_fn lint (#11610) 2024-01-30 23:37:29 +00:00
bevy_reflect Add the ability to manually create ParsedPaths (+ cleanup) (#11029) 2024-02-01 19:22:40 +00:00
bevy_reflect_compile_fail_tests bevy_reflect: Type parameter bounds (#9046) 2024-01-28 16:24:03 +00:00
bevy_render RenderGraph Labelization (#10644) 2024-01-31 14:51:19 +00:00
bevy_scene Make the MapEntities trait generic over Mappers, and add a simpler EntityMapper (#11428) 2024-01-28 19:51:46 +00:00
bevy_sprite RenderAssetPersistencePolicy → RenderAssetUsages (#11399) 2024-01-30 13:22:10 +00:00
bevy_tasks Fix wrong transmuted type in TaskPool::scope_with_executor_inner (#11455) 2024-01-21 18:08:45 +00:00
bevy_text RenderAssetPersistencePolicy → RenderAssetUsages (#11399) 2024-01-30 13:22:10 +00:00
bevy_time Add paused run condition (#11313) 2024-01-12 22:18:57 +00:00
bevy_transform refactor: Simplify lifetimes for Commands and related types (#11445) 2024-01-22 15:35:42 +00:00
bevy_ui RenderGraph Labelization (#10644) 2024-01-31 14:51:19 +00:00
bevy_utils impl Borrow and AsRef for CowArc (#11616) 2024-01-30 14:27:53 +00:00
bevy_window Update cursor.rs (#11617) 2024-01-30 16:34:17 +00:00
bevy_winit Cleanup bevy winit (#11489) 2024-01-28 21:09:23 +00:00