mirror of
https://github.com/bevyengine/bevy
synced 2024-11-23 05:03:47 +00:00
44928e0df4
# Objective
<img width="1920" alt="Screenshot 2023-04-26 at 01 07 34"
src="https://user-images.githubusercontent.com/418473/234467578-0f34187b-5863-4ea1-88e9-7a6bb8ce8da3.png">
This PR adds both diffuse and specular light transmission capabilities
to the `StandardMaterial`, with support for screen space refractions.
This enables realistically representing a wide range of real-world
materials, such as:
- Glass; (Including frosted glass)
- Transparent and translucent plastics;
- Various liquids and gels;
- Gemstones;
- Marble;
- Wax;
- Paper;
- Leaves;
- Porcelain.
Unlike existing support for transparency, light transmission does not
rely on fixed function alpha blending, and therefore works with both
`AlphaMode::Opaque` and `AlphaMode::Mask` materials.
## Solution
- Introduces a number of transmission related fields in the
`StandardMaterial`;
- For specular transmission:
- Adds logic to take a view main texture snapshot after the opaque
phase; (in order to perform screen space refractions)
- Introduces a new `Transmissive3d` phase to the renderer, to which all
meshes with `transmission > 0.0` materials are sent.
- Calculates a light exit point (of the approximate mesh volume) using
`ior` and `thickness` properties
- Samples the snapshot texture with an adaptive number of taps across a
`roughness`-controlled radius enabling “blurry” refractions
- For diffuse transmission:
- Approximates transmitted diffuse light by using a second, flipped +
displaced, diffuse-only Lambertian lobe for each light source.
## To Do
- [x] Figure out where `fresnel_mix()` is taking place, if at all, and
where `dielectric_specular` is being calculated, if at all, and update
them to use the `ior` value (Not a blocker, just a nice-to-have for more
correct BSDF)
- To the _best of my knowledge, this is now taking place, after
964340cdd
. The fresnel mix is actually "split" into two parts in our
implementation, one `(1 - fresnel(...))` in the transmission, and
`fresnel()` in the light implementations. A surface with more
reflectance now will produce slightly dimmer transmission towards the
grazing angle, as more of the light gets reflected.
- [x] Add `transmission_texture`
- [x] Add `diffuse_transmission_texture`
- [x] Add `thickness_texture`
- [x] Add `attenuation_distance` and `attenuation_color`
- [x] Connect values to glTF loader
- [x] `transmission` and `transmission_texture`
- [x] `thickness` and `thickness_texture`
- [x] `ior`
- [ ] `diffuse_transmission` and `diffuse_transmission_texture` (needs
upstream support in `gltf` crate, not a blocker)
- [x] Add support for multiple screen space refraction “steps”
- [x] Conditionally create no transmission snapshot texture at all if
`steps == 0`
- [x] Conditionally enable/disable screen space refraction transmission
snapshots
- [x] Read from depth pre-pass to prevent refracting pixels in front of
the light exit point
- [x] Use `interleaved_gradient_noise()` function for sampling blur in a
way that benefits from TAA
- [x] Drill down a TAA `#define`, tweak some aspects of the effect
conditionally based on it
- [x] Remove const array that's crashing under HLSL (unless a new `naga`
release with https://github.com/gfx-rs/naga/pull/2496 comes out before
we merge this)
- [ ] Look into alternatives to the `switch` hack for dynamically
indexing the const array (might not be needed, compilers seem to be
decent at expanding it)
- [ ] Add pipeline keys for gating transmission (do we really want/need
this?)
- [x] Tweak some material field/function names?
## A Note on Texture Packing
_This was originally added as a comment to the
`specular_transmission_texture`, `thickness_texture` and
`diffuse_transmission_texture` documentation, I removed it since it was
more confusing than helpful, and will likely be made redundant/will need
to be updated once we have a better infrastructure for preprocessing
assets_
Due to how channels are mapped, you can more efficiently use a single
shared texture image
for configuring the following:
- R - `specular_transmission_texture`
- G - `thickness_texture`
- B - _unused_
- A - `diffuse_transmission_texture`
The `KHR_materials_diffuse_transmission` glTF extension also defines a
`diffuseTransmissionColorTexture`,
that _we don't currently support_. One might choose to pack the
intensity and color textures together,
using RGB for the color and A for the intensity, in which case this
packing advice doesn't really apply.
---
## Changelog
- Added a new `Transmissive3d` render phase for rendering specular
transmissive materials with screen space refractions
- Added rendering support for transmitted environment map light on the
`StandardMaterial` as a fallback for screen space refractions
- Added `diffuse_transmission`, `specular_transmission`, `thickness`,
`ior`, `attenuation_distance` and `attenuation_color` to the
`StandardMaterial`
- Added `diffuse_transmission_texture`, `specular_transmission_texture`,
`thickness_texture` to the `StandardMaterial`, gated behind a new
`pbr_transmission_textures` cargo feature (off by default, for maximum
hardware compatibility)
- Added `Camera3d::screen_space_specular_transmission_steps` for
controlling the number of “layers of transparency” rendered for
transmissive objects
- Added a `TransmittedShadowReceiver` component for enabling shadows in
(diffusely) transmitted light. (disabled by default, as it requires
carefully setting up the `thickness` to avoid self-shadow artifacts)
- Added support for the `KHR_materials_transmission`,
`KHR_materials_ior` and `KHR_materials_volume` glTF extensions
- Renamed items related to temporal jitter for greater consistency
## Migration Guide
- `SsaoPipelineKey::temporal_noise` has been renamed to
`SsaoPipelineKey::temporal_jitter`
- The `TAA` shader def (controlled by the presence of the
`TemporalAntiAliasSettings` component in the camera) has been replaced
with the `TEMPORAL_JITTER` shader def (controlled by the presence of the
`TemporalJitter` component in the camera)
- `MeshPipelineKey::TAA` has been replaced by
`MeshPipelineKey::TEMPORAL_JITTER`
- The `TEMPORAL_NOISE` shader def has been consolidated with
`TEMPORAL_JITTER`
5.1 KiB
5.1 KiB
Cargo Features
Bevy exposes many features to customise the engine. Enabling them add functionalities but often come at the cost of longer compilation times and extra dependencies.
Default Features
The default feature set enables most of the expected features of a game engine, like rendering in both 2D and 3D, asset loading, audio and UI. To help reduce compilation time, consider disabling default features and enabling only those you need.
feature name | description |
---|---|
android_shared_stdcxx | Enable using a shared stdlib for cxx on Android |
animation | Enable animation support, and glTF animation loading |
bevy_animation | Provides animation functionality |
bevy_asset | Provides asset functionality |
bevy_audio | Provides audio functionality |
bevy_core_pipeline | Provides cameras and other basic render pipeline features |
bevy_gilrs | Adds gamepad support |
bevy_gizmos | Adds support for rendering gizmos |
bevy_gltf | glTF support |
bevy_pbr | Adds PBR rendering |
bevy_render | Provides rendering functionality |
bevy_scene | Provides scene functionality |
bevy_sprite | Provides sprite functionality |
bevy_text | Provides text functionality |
bevy_ui | A custom ECS-driven UI framework |
bevy_winit | winit window and input backend |
default_font | Include a default font, containing only ASCII characters, at the cost of a 20kB binary size increase |
hdr | HDR image format support |
ktx2 | KTX2 compressed texture support |
multi-threaded | Enables multithreaded parallelism in the engine. Disabling it forces all engine tasks to run on a single thread. |
png | PNG image format support |
tonemapping_luts | Include tonemapping Look Up Tables KTX2 files. If everything is pink, you need to enable this feature or change the Tonemapping method on your Camera2dBundle or Camera3dBundle . |
vorbis | OGG/VORBIS audio format support |
webgl2 | Enable some limitations to be able to use WebGL2. If not enabled, it will default to WebGPU in Wasm. Please refer to the WebGL2 and WebGPU section of the examples README for more information on how to run Wasm builds with WebGPU. |
x11 | X11 display server support |
zstd | For KTX2 supercompression |
Optional Features
feature name | description |
---|---|
accesskit_unix | Enable AccessKit on Unix backends (currently only works with experimental screen readers and forks.) |
asset_processor | Enables the built-in asset processor for processed assets. |
async-io | Use async-io's implementation of block_on instead of futures-lite's implementation. This is preferred if your application uses async-io. |
basis-universal | Basis Universal compressed texture support |
bevy_ci_testing | Enable systems that allow for automated testing on CI |
bevy_dynamic_plugin | Plugin for dynamic loading (using libloading) |
bmp | BMP image format support |
dds | DDS compressed texture support |
debug_glam_assert | Enable assertions in debug builds to check the validity of parameters passed to glam |
detailed_trace | Enable detailed trace event logging. These trace events are expensive even when off, thus they require compile time opt-in |
dynamic_linking | Force dynamic linking, which improves iterative compile times |
embedded_watcher | Enables watching in memory asset providers for Bevy Asset hot-reloading |
exr | EXR image format support |
file_watcher | Enables watching the filesystem for Bevy Asset hot-reloading |
flac | FLAC audio format support |
glam_assert | Enable assertions to check the validity of parameters passed to glam |
jpeg | JPEG image format support |
minimp3 | MP3 audio format support (through minimp3) |
mp3 | MP3 audio format support |
pbr_transmission_textures | Enable support for transmission-related textures in the StandardMaterial , at the risk of blowing past the global, per-shader texture limit on older/lower-end GPUs |
pnm | PNM image format support, includes pam, pbm, pgm and ppm |
serialize | Enable serialization support through serde |
shader_format_glsl | Enable support for shaders in GLSL |
shader_format_spirv | Enable support for shaders in SPIR-V |
subpixel_glyph_atlas | Enable rendering of font glyphs using subpixel accuracy |
symphonia-aac | AAC audio format support (through symphonia) |
symphonia-all | AAC, FLAC, MP3, MP4, OGG/VORBIS, and WAV audio formats support (through symphonia) |
symphonia-flac | FLAC audio format support (through symphonia) |
symphonia-isomp4 | MP4 audio format support (through symphonia) |
symphonia-vorbis | OGG/VORBIS audio format support (through symphonia) |
symphonia-wav | WAV audio format support (through symphonia) |
tga | TGA image format support |
trace | Tracing support |
trace_chrome | Tracing support, saving a file in Chrome Tracing format |
trace_tracy | Tracing support, exposing a port for Tracy |
trace_tracy_memory | Tracing support, with memory profiling, exposing a port for Tracy |
wav | WAV audio format support |
wayland | Wayland display server support |
webp | WebP image format support |
wgpu_trace | Save a trace of all wgpu calls |
zlib | For KTX2 supercompression |