bevy/crates/bevy_pbr/src
Patrick Walton 1c765c9ae7
Add support for specular tints and maps per the KHR_materials_specular glTF extension. (#14069)
This commit allows specular highlights to be tinted with a color and for
the reflectance and color tint values to vary across a model via a pair
of maps. The implementation follows the [`KHR_materials_specular`] glTF
extension. In order to reduce the number of samplers and textures in the
default `StandardMaterial` configuration, the maps are gated behind the
`pbr_specular_textures` Cargo feature.

Specular tinting is currently unsupported in the deferred renderer,
because I didn't want to bloat the deferred G-buffers. A possible fix
for this in the future would be to make the G-buffer layout more
configurable, so that specular tints could be supported on an opt-in
basis. As an alternative, Bevy could force meshes with specular tints to
render in forward mode. Both of these solutions require some more
design, so I consider them out of scope for now.

Note that the map is a *specular* map, not a *reflectance* map. In Bevy
and Filament terms, the reflectance values in the specular map range
from [0.0, 0.5], rather than [0.0, 1.0]. This is an unfortunate
[`KHR_materials_specular`] specification requirement that stems from the
fact that glTF is specified in terms of a specular strength model, not
the reflectance model that Filament and Bevy use. A workaround, which is
noted in the `StandardMaterial` documentation, is to set the
`reflectance` value to 2.0, which spreads the specular map range from
[0.0, 1.0] as normal.

The glTF loader has been updated to parse the [`KHR_materials_specular`]
extension. Note that, unless the non-default `pbr_specular_textures` is
supplied, the maps are ignored. The `specularFactor` value is applied as
usual. Note that, as with the specular map, the glTF `specularFactor` is
twice Bevy's `reflectance` value.

This PR adds a new example, `specular_tint`, which demonstrates the
specular tint and map features. Note that this example requires the
[`KHR_materials_specular`] Cargo feature.

[`KHR_materials_specular`]:
https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_specular

## Changelog

### Added

* Specular highlights can now be tinted with the `specular_tint` field
in `StandardMaterial`.
* Specular maps are now available in `StandardMaterial`, gated behind
the `pbr_specular_textures` Cargo feature.
* The `KHR_materials_specular` glTF extension is now supported, allowing
for customization of specular reflectance and specular maps. Note that
the latter are gated behind the `pbr_specular_textures` Cargo feature.
2025-01-26 20:38:46 +00:00
..
atmosphere Procedural atmospheric scattering (#16314) 2025-01-23 22:52:46 +00:00
cluster Implement basic clustered decal projectors. (#17315) 2025-01-26 20:13:39 +00:00
decal Implement basic clustered decal projectors. (#17315) 2025-01-26 20:13:39 +00:00
deferred Add support for specular tints and maps per the KHR_materials_specular glTF extension. (#14069) 2025-01-26 20:38:46 +00:00
light Procedural atmospheric scattering (#16314) 2025-01-23 22:52:46 +00:00
light_probe Implement basic clustered decal projectors. (#17315) 2025-01-26 20:13:39 +00:00
lightmap Move hashbrown and foldhash out of bevy_utils (#17460) 2025-01-23 16:46:08 +00:00
meshlet Move hashbrown and foldhash out of bevy_utils (#17460) 2025-01-23 16:46:08 +00:00
prepass Implement basic clustered decal projectors. (#17315) 2025-01-26 20:13:39 +00:00
render Add support for specular tints and maps per the KHR_materials_specular glTF extension. (#14069) 2025-01-26 20:38:46 +00:00
ssao Procedural atmospheric scattering (#16314) 2025-01-23 22:52:46 +00:00
ssr Move Resource trait to its own file (#17469) 2025-01-21 19:47:08 +00:00
volumetric_fog Move Resource trait to its own file (#17469) 2025-01-21 19:47:08 +00:00
components.rs Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
extended_material.rs Forward decals (port of bevy_contact_projective_decals) (#16600) 2025-01-15 02:31:30 +00:00
fog.rs Remove all deprecated code (#16338) 2025-01-05 20:33:39 +00:00
lib.rs Implement basic clustered decal projectors. (#17315) 2025-01-26 20:13:39 +00:00
material_bind_groups.rs Move hashbrown and foldhash out of bevy_utils (#17460) 2025-01-23 16:46:08 +00:00
material.rs Move hashbrown and foldhash out of bevy_utils (#17460) 2025-01-23 16:46:08 +00:00
mesh_material.rs Revert default mesh materials (#15930) 2024-10-15 19:47:40 +00:00
parallax.rs
pbr_material.rs Add support for specular tints and maps per the KHR_materials_specular glTF extension. (#14069) 2025-01-26 20:38:46 +00:00
wireframe.rs Fix a few typos (#17292) 2025-01-10 22:48:30 +00:00