Commit graph

429 commits

Author SHA1 Message Date
Marco Buono
da772b84f2 Make each consecutive spiral smaller 2023-05-11 03:11:11 -03:00
Marco Buono
cd3e7f16f3 Rename sample offsets to spiral offsets for clarity, use upper case naming convention 2023-05-11 02:40:45 -03:00
Marco Buono
721ce68e9c Tweak how fast number of taps grows with blur intensity 2023-05-11 02:38:07 -03:00
Marco Buono
9650ee9bd1 Remove note about conditionally disabling normalization with TAA (doesn't work very well) 2023-05-11 02:29:47 -03:00
Marco Buono
dfd204abd1 Tweak color normalization to work properly with new blur intensity calculation 2023-05-11 02:23:05 -03:00
Marco Buono
1b3338138e Make blur radius scale correctly with distance 2023-05-11 02:14:41 -03:00
Marco Buono
a1e06c745c Move pixel mesh out of loop, don't vary it by frame if TAA is disabled 2023-05-11 02:01:38 -03:00
Marco Buono
c81c57c222 Make blur 50% less blurry 2023-05-11 01:52:53 -03:00
Marco Buono
54cfc26afb Make number of taps increase faster with blur intensity 2023-05-11 01:51:29 -03:00
Marco Buono
0dbec526e7 Only compute interleaved_gradient_noise() once 2023-05-11 01:43:32 -03:00
Marco Buono
44da7267e6 Allow multiple rotated spiral taps, extract max taps constant 2023-05-11 01:41:41 -03:00
Marco Buono
0d817e0c62 Add TAA shaderdef, don't vary noise with time if TAA is disabled 2023-05-11 00:38:37 -03:00
Marco Buono
20b223c556 Merge branch 'main' into transmission 2023-05-11 00:01:40 -03:00
François
71842c5ac9
Webgpu support (#8336)
# Objective

- Support WebGPU
- alternative to #5027 that doesn't need any async / await
- fixes #8315 
- Surprise fix #7318

## Solution

### For async renderer initialisation 

- Update the plugin lifecycle:
  - app builds the plugin
    - calls `plugin.build`
    - registers the plugin
  - app starts the event loop
- event loop waits for `ready` of all registered plugins in the same
order
    - returns `true` by default
- then call all `finish` then all `cleanup` in the same order as
registered
  - then execute the schedule

In the case of the renderer, to avoid anything async:
- building the renderer plugin creates a detached task that will send
back the initialised renderer through a mutex in a resource
- `ready` will wait for the renderer to be present in the resource
- `finish` will take that renderer and place it in the expected
resources by other plugins
- other plugins (that expect the renderer to be available) `finish` are
called and they are able to set up their pipelines
- `cleanup` is called, only custom one is still for pipeline rendering

### For WebGPU support

- update the `build-wasm-example` script to support passing `--api
webgpu` that will build the example with WebGPU support
- feature for webgl2 was always enabled when building for wasm. it's now
in the default feature list and enabled on all platforms, so check for
this feature must also check that the target_arch is `wasm32`

---

## Migration Guide

- `Plugin::setup` has been renamed `Plugin::cleanup`
- `Plugin::finish` has been added, and plugins adding pipelines should
do it in this function instead of `Plugin::build`
```rust
// Before
impl Plugin for MyPlugin {
    fn build(&self, app: &mut App) {
        app.insert_resource::<MyResource>
            .add_systems(Update, my_system);

        let render_app = match app.get_sub_app_mut(RenderApp) {
            Ok(render_app) => render_app,
            Err(_) => return,
        };

        render_app
            .init_resource::<RenderResourceNeedingDevice>()
            .init_resource::<OtherRenderResource>();
    }
}

// After
impl Plugin for MyPlugin {
    fn build(&self, app: &mut App) {
        app.insert_resource::<MyResource>
            .add_systems(Update, my_system);
    
        let render_app = match app.get_sub_app_mut(RenderApp) {
            Ok(render_app) => render_app,
            Err(_) => return,
        };
    
        render_app
            .init_resource::<OtherRenderResource>();
    }

    fn finish(&self, app: &mut App) {
        let render_app = match app.get_sub_app_mut(RenderApp) {
            Ok(render_app) => render_app,
            Err(_) => return,
        };
    
        render_app
            .init_resource::<RenderResourceNeedingDevice>();
    }
}
```
2023-05-04 22:07:57 +00:00
Marco Buono
447a0a1c2e Merge branch 'main' into transmission 2023-05-02 00:09:38 -03:00
Airing
4d54ce14aa
Updated to wgpu 0.16.0, wgpu-hal 0.16.0 and naga 0.12.0 (#8446)
# Objective

- Updated to wgpu 0.16.0 and wgpu-hal 0.16.0

---

## Changelog

1. Upgrade wgpu to 0.16.0 and  wgpu-hal to 0.16.0
2. Fix the error in native when using a filterable
`TextureSampleType::Float` on a multisample `BindingType::Texture`.
([https://github.com/gfx-rs/wgpu/pull/3686](https://github.com/gfx-rs/wgpu/pull/3686))

---------

Co-authored-by: François <mockersf@gmail.com>
2023-04-26 15:34:23 +00:00
Marco Buono
5f2516d974 Add additional quality tweaks to mask the firefly artifacts 2023-04-26 00:14:03 -03:00
Marco Buono
d47fe5bc2a Add one more sample offset 2023-04-25 23:57:02 -03:00
Marco Buono
a0535deb49 Use interleaved_gradient_noise() instead of screen_space_dither() 2023-04-25 22:19:55 -03:00
Marco Buono
94e3099bd8 Correctly use min() instead of max() to avoid 300 texture taps 2023-04-25 02:25:08 -03:00
Marco Buono
95a15d5bde Update index of refraction docs 2023-04-25 00:09:14 -03:00
Marco Buono
e25b7fea3a Update section on texture packing 2023-04-25 00:00:35 -03:00
Marco Buono
3862e82df5 Merge branch 'main' into transmission 2023-04-24 23:36:48 -03:00
Marco Buono
580f4af803 Reuse fog implementation to implement transmission attenuation 2023-04-24 23:32:17 -03:00
Marco Buono
50b32da4c8 Modify fog functions to take fog as an argument 2023-04-24 23:24:34 -03:00
Marco Buono
23711c8d3e Add attenuation_distance and attenuation_color material attributes 2023-04-24 23:23:54 -03:00
IceSentry
3f6367d584
Handle vertex_uvs if they are present in default prepass fragment shader (#8330)
# Objective

- Enabling AlphaMode::Opaque in the shader_prepass example crashes. The
issue seems to be that enabling opaque also generates vertex_uvs

Fixes https://github.com/bevyengine/bevy/issues/8273

## Solution

- Use the vertex_uvs in the shader if they are present
2023-04-23 08:07:15 +00:00
ira
6b774c0fda
Compute vertex_count for indexed meshes on GpuMesh (#8460)
# Objective

Compute the `vertex_count` for indexed meshes as well as non-indexed
meshes.

I will need this in a future PR based on #8427 that adds a gizmo
component that draws the normals of a mesh when attached to an entity
([branch](https://github.com/devil-ira/bevy/compare/instanced-line-rendering...devil-ira:bevy:instanced-line-rendering-normals)).

<details><summary>Example image</summary>
<p>


![image](https://user-images.githubusercontent.com/29694403/233789526-cb5feb47-0aa7-4e69-90a2-e31ec24aadff.png)

</p>
</details> 

## Solution

Move `vertex_count` field from `GpuBufferInfo::NonIndexed` to `GpuMesh`

## Migration Guide

`vertex_count` is now stored directly on `GpuMesh` instead of
`GpuBufferInfo::NonIndexed`.
2023-04-22 17:28:58 +00:00
Robert Swain
d8102a0a04
bevy_pbr: Do not cull meshes without Aabbs from cascades (#8444)
# Objective

- Mesh entities should cast shadows when not having Aabbs and having
NoFrustumCulling
- Fixes #8442 

## Solution

- Mesh entities with NoFrustumCulling get no automatic Aabbs added
- Point and spot lights do not cull mesh entities for their shadow
mapping if they do not have an Aabb, but directional lights do
- Make directional lights not cull mesh entities from cascades if the do
not have Aabbs. So no Aabb as a consequence of a NoFrustumCulling
component will mean that those mesh entities are not culled and so are
visible to the light.

---

## Changelog

- Fixed: Mesh entities with NoFrustumCulling will cast shadows for
directional light shadow maps
2023-04-20 01:43:24 +00:00
Marco Buono
b1db977176 Use depth prepass data to reject values that are in front of the current fragment 2023-04-19 02:08:50 -03:00
Nicola Papale
c488b7089c
Fix pbr shader breaking on missing UVs (#8412)
# Objective

Fix #8409

Since `in` doesn't have a `uv` field when `VERTEX_UVS` is not defined,
it shouldn't be accessed outside of related `#ifdef`s
2023-04-17 06:22:34 +00:00
Marco Buono
c38255e505 Improve diffuse_transmission documentation 2023-04-16 18:49:15 -03:00
Marco Buono
ef04badefb Add documentation aliases 2023-04-16 18:43:45 -03:00
Marco Buono
545019a9b8 Fix lint error 2023-04-16 18:29:09 -03:00
Marco Buono
fd65d4bcd7 Make refraction math for environment map more accurate 2023-04-16 17:54:13 -03:00
Marco Buono
5bfe6bb342 Fallback to (specular) transmitted environment light when there's no transmitted background 2023-04-16 17:11:57 -03:00
Marco Buono
294a677b20 Introduce FallbackImageZero 2023-04-16 16:17:23 -03:00
Marco Buono
13b1e596e9 Scale thickness with mesh transform (using average of X, Y and Z scales) 2023-04-16 16:00:21 -03:00
Marco Buono
727a89dbe7 Add support for a configurable number of transmissive steps 2023-04-16 15:58:52 -03:00
Marco Buono
272b696d78 Add transmission, thickness and diffuse transmission textures 2023-04-16 12:20:16 -03:00
Marco Buono
08e7416b7f Fix additional documentation links 2023-04-16 11:13:01 -03:00
Marco Buono
b7a6ff40a9 Fix documentation link 2023-04-16 04:14:31 -03:00
Marco Buono
927cfa24fc Add ability to independently suppress shadows in diffuse transmission lobe 2023-04-16 01:09:26 -03:00
Marco Buono
e2b816bc7c Add second Lambertian lobe-based diffuse transmission to PBR shader 2023-04-15 23:57:24 -03:00
Marco Buono
cfd58599a0 Allow transmission with AlphaMode::Opaque materials 2023-04-15 19:42:18 -03:00
Marco Buono
0feafb2463 Add diffuse_transmission property to StandardMaterial 2023-04-15 19:40:33 -03:00
Marco Buono
0a11954c70 Merge branch 'main' into transmission 2023-04-15 18:34:28 -03:00
Nicola Papale
8df014fbaf
Add parallax mapping to bevy PBR (#5928)
# Objective

Add a [parallax mapping] shader to bevy. Please note that
this is a 3d technique, NOT a 2d sidescroller feature.

## Solution

- Add related fields to `StandardMaterial`
- update the pbr shader
- Add an example taking advantage of parallax mapping

A pre-existing implementation exists at:
https://github.com/nicopap/bevy_mod_paramap/

The implementation is derived from:

https://web.archive.org/web/20150419215321/http://sunandblackcat.com/tipFullView.php?l=eng&topicid=28

Further discussion on literature is found in the `bevy_mod_paramap`
README.

### Limitations

- The mesh silhouette isn't affected by the depth map.
- The depth of the pixel does not reflect its visual position, resulting
  in artifacts for depth-dependent features such as fog or SSAO
- GLTF does not define a height map texture, so somehow the user will
  always need to work around this limitation, though [an extension is in
  the works][gltf]

### Future work

- It's possible to update the depth in the depth buffer to follow the
  parallaxed texture. This would enable interop with depth-based
  visual effects, it also allows `discard`ing pixels of materials when
  computed depth is higher than the one in depth buffer
- Cheap lower quality single-sample method using [offset limiting]
- Add distance fading, to disable parallaxing (relatively expensive)
  on distant objects
- GLTF extension to allow defining height maps. Or a workaround
  implemented through a blender plugin to the GLTF exporter that
  uses the `extras` field to add height map.
- [Quadratic surface vertex attributes][oliveira_3] to enable parallax
  mapping on bending surfaces and allow clean silhouetting.
- noise based sampling, to limit the pancake artifacts.
- Cone mapping ([GPU gems], [Simcity (2013)][simcity]). Requires
  preprocessing, increase depth map size, reduces sample count greatly.
- [Quadtree parallax mapping][qpm] (also requires preprocessing)
- Self-shadowing of parallax-mapped surfaces by modifying the shadow map
- Generate depth map from normal map [link to slides], [blender
question]


https://user-images.githubusercontent.com/26321040/223563792-dffcc6ab-70e8-4ff9-90d1-b36c338695ad.mp4

[blender question]:
https://blender.stackexchange.com/questions/89278/how-to-get-a-smooth-curvature-map-from-a-normal-map
[link to slides]:
https://developer.download.nvidia.com/assets/gamedev/docs/nmap2displacement.pdf
[oliveira_3]:
https://www.inf.ufrgs.br/~oliveira/pubs_files/Oliveira_Policarpo_RP-351_Jan_2005.pdf
[GPU gems]:
https://developer.nvidia.com/gpugems/gpugems3/part-iii-rendering/chapter-18-relaxed-cone-stepping-relief-mapping
[simcity]:
https://community.simtropolis.com/omnibus/other-games/building-and-rendering-simcity-2013-r247/
[offset limiting]:
https://raw.githubusercontent.com/marcusstenbeck/tncg14-parallax-mapping/master/documents/Parallax%20Mapping%20with%20Offset%20Limiting%20-%20A%20Per-Pixel%20Approximation%20of%20Uneven%20Surfaces.pdf
[gltf]: https://github.com/KhronosGroup/glTF/pull/2196
[qpm]:
https://www.gamedevs.org/uploads/quadtree-displacement-mapping-with-height-blending.pdf

---

## Changelog

- Add a `depth_map` field to the `StandardMaterial`, it is a grayscale
  image where white represents bottom and black the top. If `depth_map`
  is set, bevy's pbr shader will use it to do [parallax mapping] to
  give an increased feel of depth to the material. This is similar to a
  displacement map, but with infinite precision at fairly low cost.
- The fields `parallax_mapping_method`, `parallax_depth_scale` and
  `max_parallax_layer_count` allow finer grained control over the
  behavior of the parallax shader.
- Add the `parallax_mapping` example to show off the effect.

[parallax mapping]: https://en.wikipedia.org/wiki/Parallax_mapping

---------

Co-authored-by: Robert Swain <robert.swain@gmail.com>
2023-04-15 10:25:14 +00:00
Jannik Obermann
d47bb3e6e9
Sync pbr_types.wgsl StandardMaterial values (#8380)
# Objective

The default StandardMaterial values of `pbr_material.rs` and
`pbr_types.wgsl` are out of sync.
I think they are out of sync since
https://github.com/bevyengine/bevy/pull/7664.

## Solution

Adapt the values: `metallic = 0.0`, `perceptual_roughness = 0.5`.
2023-04-14 05:52:57 +00:00
Marco Buono
d158e733e7 Rename transmissive to is_transmissive 2023-04-10 01:56:47 -03:00