Skip to content

Commit 25227bb

Browse files
nicopapcart
andauthored
0.11 Section: Parallax mapping (#664)
Co-authored-by: Carter Anderson <[email protected]>
1 parent cdc90bb commit 25227bb

7 files changed

+150
-2
lines changed
Binary file not shown.

content/news/2023-07-07-bevy-0.11/index.md

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,95 @@ Since our last release a few months ago we've added a _ton_ of new features, bug
1515

1616
<!-- more -->
1717

18-
* **Feature**: description
19-
*
18+
* **Parallax mapping**: Materials now support an optional depth map, giving
19+
flat surfaces a feel of depth through parallaxing the material's textures.
20+
21+
## Parallax Mapping
22+
23+
<div class="release-feature-authors">author: @nicopap</div>
24+
25+
Bevy now supports parallax mapping and depth maps. Parallax mapping puts normal
26+
maps to shame when it comes to giving "illusion of depth" to a material. The top half of this video uses parallax mapping plus a normal map, whereas the bottom half only uses a normal map:
27+
28+
<video controls loop><source alt="a rotating view of the earth, the top half of the screen uses parallax mapping, while the bottom half does not" src="earth-parallax.webm" type="video/webm"/></video>
29+
<div style="font-size: 1.0rem" class="release-feature-authors">earth view, elevation & night view by NASA (public domain)</div>
30+
31+
Notice how it is not merely the shading of pixels that changes, but their
32+
actual position on screen. The mountaintops hide mountain ridges behind
33+
themselves. High mountains move faster than coastal areas.
34+
35+
Parallax mapping moves pixels according to the perspective and depth on the
36+
surface of the geometry. Adding true 3D depth to flat surfaces.
37+
38+
All of that, without adding a single vertex to the geometry. The whole globe
39+
has exactly 648 vertices. Unlike a more primitive shader, such as displacement
40+
mapping, parallax mapping only requires an additional grayscale image, called
41+
the `depth_map`.
42+
43+
Games often use parallax mapping for cobblestones or brick walls, so
44+
let's make a brick wall in Bevy! First, we spawn a mesh:
45+
46+
```rust
47+
commands.spawn(PbrBundle {
48+
mesh: meshes.add(shape::Box::new(30.0, 10.0, 1.0).into()),
49+
material: materials.add(StandardMaterial {
50+
base_color: Color::WHITE,
51+
..default()
52+
}),
53+
..default()
54+
});
55+
```
56+
57+
![A 3D desert scene with two flat white walls and a pebble path winding between them](parallax_mapping_none.jpg)
58+
59+
Of course, it's just a flat white box, we didn't add any texture.
60+
So let's add a normal map:
61+
62+
```rust
63+
normal_map_texture: Some(assets.load("normal_map.png")),
64+
```
65+
66+
![The same scene with normal maps](parallax_mapping_normals.jpg)
67+
68+
This is much better. The shading changes according to the light direction too!
69+
However, the specular highlights on the corner are overbearing, almost noisy.
70+
71+
Let's see how a depth map can help:
72+
73+
```rust
74+
depth_map: Some(assets.load("depth_map.png")),
75+
```
76+
77+
![The same scene with a depth texture](parallax_mapping_depth.jpg)
78+
79+
We eliminated the noise! There is also that sweet 3D feel reminiscent of
80+
90's games pre-rendered cinematic sequences.
81+
82+
So what's going on, why does parallax mapping eliminate the ugly specular
83+
lights on the wall?
84+
85+
This is because parallax mapping insets the ridges between bricks, so that they
86+
are occluded by the bricks themselves.
87+
88+
![Illustration of the previous paragraph](ridge-light-view-1.svg)
89+
90+
Since normal maps do not "move" the shaded areas, merely shade them
91+
differently, we get those awkward specular highlights. With parallax mapping,
92+
they are gone.
93+
94+
![A montage of the three preceding images, contrasting each effect](parallax_mapping_compare.jpg)
95+
96+
Parallax mapping in Bevy is still very limited. The most painful aspect is that
97+
it is not a standard glTF feature, meaning that the depth texture needs to be
98+
programmatically added to materials if they came from a GLTF file.
99+
100+
Additionally, parallax mapping is incompatible with the temporal antialiasing
101+
shader, doesn't work well on curved surfaces, and doesn't affect object's
102+
silhouettes.
103+
104+
However, those are not fundamental limitations of parallax mapping, and may be
105+
fixed in the future.
106+
20107
## WebGPU Support
21108

22109
## Deref Derive Attribute
Loading
Loading
Loading
Loading
Lines changed: 61 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)