Parallax mapping shaders (relief and POM) for the bevy game engine

Overview

Bevy parallax mapping

parallax mapping is a graphical effect adding the impression of depth to simple 2d textures by moving the texture's pixel around according to the viewport's perspective.

This is NOT a "parallax" à la Super Mario World. This is intended for 3D rendering. This technic has been used with success in the Demon's Souls Bluepoint remake.

This crate adds a custom material that extends the default bevy PBR material with parallax mapping. The ParallaxMaterial asset is a straight copy of bevy's PBR material with the addition of the height_map: Handle<Image> filed (it's not Option since you might as well use the default shader if there is no height maps).

height_map is a greyscale image representing the height of the object at the specific pixel.

ParallaxMaterial allows selecting the algorithm used for parallaxing. By setting the algorithm field to the ParallaxAlgo of your choosing, you may opt into using Relief Mapping. By default, ParallaxMaterial uses the Parallax Occlusion Mapping (POM) method. (see the shader source code for explanation on what the algorithms do)

Examples

This repo contains two examples. to modify ParallaxMaterial values dynamically at run time, add the inspector-def feature flag.

cargo run --example <example_name> --features "inspector-def"
  • earth3d: a spinning view of the earth. Takes advantage of height map, but also of all the bevy PBR fields. This a good demonstration of bevy's capabilities.
    You can orbit the earth by holding down the right mouse button, and zoom in/out with the mouse wheel.
parallax_mapping3-2022-09-09.mp4
  • cube: A spinning cube with a parallaxed material in a basic 3d scene, mouse left click to switch point of view.
parallax_mapping2-2022-09-08.mp4

Bugs and limitations

  • This doesn't implement silhouetting, so the meshes's silhouette will not change with the height map
    • As a result, height maps that are top-heavy should be favored (tree bark, bricks)
  • This doesn't implement self-shadowing, resulting in potentially surprising sharp cutoffs
    • self-shadowing is described in the sunblackcat article, but bevy's lighting system requires handling several light types and multiple light sources at once, which is more complex than I can handle right now.
  • The height map is inverted from the more common usage

Literature

The code is basically copied from the sunblackcat implementation linked on Wikipedia.

Optimization leads include:

  1. https://www.diva-portal.org/smash/get/diva2:831762/FULLTEXT01.pdf
  2. https://www.gamedevs.org/uploads/quadtree-displacement-mapping-with-height-blending.pdf
  3. https://developer.nvidia.com/gpugems/gpugems3/part-i-geometry/chapter-4-next-generation-speedtree-rendering
  4. https://old.reddit.com/r/GraphicsProgramming/comments/pgkogk/whatever_happened_to_quadtree_displacement_mapping/

Note that (1) says that (2) is slower than POM, while (3) is beyond out-of-scope for a small opensource crate (unless you want to pay me).

TODO

License

Earth images in assets/earth are public domain and taken from Wikimedia. I edited them myself, you are free to re-use the edited version however you want without restrictions.

  • height map: elevation_water.png and elevation_surface.png adjust the values to highlight different topological features of earth, the normal_map.jpg is also derived from it.
  • albedo (aka base color) is a scalled-down version of the 2002 Nasa blue marble earth satellite view using a equirectangular projection. metallic_roughness.png and base_color.jpg are derived from that image.
  • emissive texture is from the 2012 Nasa blue marble project. It's a night time satellite view of earth.
  • An alternative higher-quality height map is available at: https://commons.wikimedia.org/wiki/File:Srtm_ramp2.world.21600x10800.jpg

Copyright of code and assets go to their respective authors.

Original code is copyright © 2022 Nicola Papale

This software is licensed under Apache 2.0.

You might also like...
Inspector plugin for the bevy game engine
Inspector plugin for the bevy game engine

bevy-inspector-egui This crate provides the ability to annotate structs with a #[derive(Inspectable)], which opens a debug interface using egui where

Crossterm plugin for the bevy game engine
Crossterm plugin for the bevy game engine

What is bevy_crossterm? bevy_crossterm is a Bevy plugin that uses crossterm as a renderer. It provides custom components and events which allow users

Concise Reference Book for the Bevy Game Engine

Unofficial Bevy Cheat Book Click here to read the book! Concise reference to programming in the Bevy game engine. Covers useful syntax, features, prog

Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions
Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions

Introduction Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions. (hand interaction with boxes missing

A physics lib for the bevy game engine based on physme

physimple Physimple aims to be the simplest(and capable) physics engine(currently for bevy) WARNING Beware for breaking changes with each update for n

An immediate mode 2D drawing API for Bevy game engine

Bevy Canvas API prototype An unofficial immediate mode 2D drawing API for Bevy game engine. Check the documentation or the examples to know how to use

Simple RUST game with the Bevy Engine

Simple RUST Game using the Bevy Engine YouTube videos for this code base: Episode 1 - Rust Game Development tutorial from Scratch with Bevy Engine Epi

A vdom-free reactive UI lib for the bevy game engine

ui4 ui4 is my fourth major attempt at making a UI dataflow library for the Bevy game engine. More specifically, it's a vdom-less UI library which uses

Hanabi — a particle system plugin for the Bevy game engine.

Hanabi — a particle system plugin for the Bevy game engine

Comments
  • Asset dump

    Asset dump

    earth3d demo

    https://user-images.githubusercontent.com/26321040/189361740-1a0876d2-9b39-49f3-a8cb-8837601b5b39.mp4

    cube demo

    https://user-images.githubusercontent.com/26321040/189361802-3db6aa98-fa7f-4440-b5a7-20d73a36ac23.mp4

    opened by nicopap 0
Owner
Nicola Papale
Mulintex developer favoring the Rust programming language
Nicola Papale
Minecraft-esque voxel engine prototype made with the bevy game engine. Pending bevy 0.6 release to undergo a full rewrite.

vx_bevy A voxel engine prototype made using the Bevy game engine. Goals and features Very basic worldgen Animated chunk loading (ala cube world) Optim

Lucas Arriesse 125 Dec 31, 2022
Bevy Simple Portals is a Bevy game engine plugin aimed to create portals.

Portals for Bevy Bevy Simple Portals is a Bevy game engine plugin aimed to create portals. Those portals are (for now) purely visual and can be used t

Sélène Amanita 11 May 28, 2023
3d Cellular Automata using WGPU in Rust (for the web and using compute shaders)

3D-Cellular-Automata-WGPU 3d Cellular Automata using WGPU in Rust (for the web and using compute shaders) The branches are very messy... I recommend y

null 18 Dec 18, 2022
2d Endless Runner Game made with Bevy Game Engine

Cute-runner A 2d Endless Runner Game made with Bevy Game Engine. Table of contents Project Infos Usage Screenshots Disclaimer Project Infos Date: Sept

JoaoMarinho 2 Jul 15, 2022
A game of snake written in Rust using the Bevy game engine, targeting WebGL2

Snake using the Bevy Game Engine Prerequisites cargo install cargo-make Build and serve WASM version Set your local ip address in Makefile.toml (loca

Michael Dorst 0 Dec 26, 2021
A game made in one week for the Bevy engine's first game jam

¿Quien es el MechaBurro? An entry for the first Bevy game jam following the theme of "Unfair Advantage." It was made in one week using the wonderful B

mike 20 Dec 23, 2022
A Client/Server game networking plugin using QUIC, for the Bevy game engine.

Bevy Quinnet A Client/Server game networking plugin using QUIC, for the Bevy game engine. Bevy Quinnet QUIC as a game networking protocol Features Roa

Gilles Henaux 65 Feb 20, 2023
Plotting library for the Bevy game engine with a focus on esthetics and interactivity

Plotting library for the Bevy game engine with a focus on esthetics and interactivity. It can handle both data points (see the "minimal", "markers", a

Eli 40 Dec 25, 2022
A simple-to-use input manager for the Bevy game engine that empowers players and makes accessibility easy.

Bevy Ineffable A simple-to-use input manager for the Bevy game engine that empowers players and makes accessibility easy. Core tenets Make accessibili

Jazarro 10 Mar 2, 2024
Basic first-person fly camera for the Bevy game engine

bevy_flycam A basic first-person fly camera for Bevy 0.4 Controls WASD to move horizontally SPACE to ascend LSHIFT to descend ESC to grab/release curs

Spencer Burris 85 Dec 23, 2022