A high-performance renderer to render glTF models that use the `KHR_materials_transmission` and `KHR_materials_volume` extensions.

Overview

This is a high-performance renderer designed among other things to render glTF models that use the KHR_materials_transmission and KHR_materials_volume extensions.

It can:

  • Handle rough transmissive materials such as frosted glass.
  • Approximate refracted light through transmissive models that specify a thickness.
  • Attenuate light via Beer's law.

It wasn't easy working out how to render these models. While the glTF extension READMEs as fairly extensive, I had to look through the code of the glTF-Sample-Viewer to work out implementation details.

Transmissive materials that are totally smooth and do not have a volume can be rendered without any super special tricks via pre-multiplied alpha and additive blending. Transmissive materials with any kind of roughness or volume are quite a bit trickier.

The main trick I realised from reading over the code from the glTF-Sample-Viewer is that you need to render or blit all the rendered diffuse objects to a second framebuffer texture, which you then sample in a seperate pass for all the transmissive objects. If you want to handle rough transmissive objects then you need to generate a mip-chain for this sampled texture, as rougher objects need to fetch the transmitted light of the pixels behind them in a 'blurrier' way.

In my shader code, this is done via two functions (these I did mostly copy from the gltf-Sample-Viewer). The first, ibl_volume_refraction is only ran once per pixel. It handles fetching the transmitted light from the sampled framebuffer and attenuating it.

The second, the transmission_btdf is ran once per light and handles light that is scattered through the model and out onto the other side. This only effects materials that are a bit rough.

Running

Clone https://github.com/KhronosGroup/glTF-Sample-Models into this directory as run with:

cargo run -- <gltf-sample-model-name>

transmission-renderer 0.1.0

USAGE:
    transmission-renderer [FLAGS] [OPTIONS] <gltf-sample-model-name>

FLAGS:
        --external-model    Render a model external to the glTF-Sample-Models directory, in which case the full path
                            needs to be specified
    -h, --help              Prints help information
        --log-leaks         Log allocator leaks on shutdown. Off by default because it makes panics hard to debug
    -V, --version           Prints version information

OPTIONS:
        --roughness-override <roughness-override>
            Override the default roughness factor of the model. Doesn't effect models that use a
texture for roughness

    -s, --scale <scale>                              A scale factor to be applied to the model [default: 1.0]

ARGS:
    <gltf-sample-model-name>    The name of the model inside the glTF-Sample-Models directory to
render

For some cool examples:

cargo run -- DragonAttenuation --roughness-override 0.25

cargo run -- IridescentDishWithOlives --scale 5

cargo run -- MosquitoInAmber --scale 20

cargo run -- AttenuationTest --scale 0.1

Shader Compiling

I'm using my own project, rust-gpu-cli-builder to build the shader module as I prefer this to using a build script. The arguments that I use to build it are:

--target spirv-unknown-spv1.3 --capabilities RuntimeDescriptorArray --extensions SPV_EXT_descriptor_indexing

Other Fun Stuff

Oh, it also features

  • Shader written entirely in https://github.com/EmbarkStudios/rust-gpu.
  • Basic frustum culling via a compute shader and vkCmdDrawIndexedIndirectCount.
  • A depth pre-pass setup where at max 2 full screens of fragments are processed (1 screen of opaque and 1 of transmissive objects on top).
Issues
Owner
Ashley
Graphics programmer and occasional gamedev living in Berlin, DE
Ashley
Pixel-Perfect, 2D Renderer for Bevy that Seamlessly Targets Desktop and Web

bevy_retro ( Screenshot of Bounty Bros. game made with Bevy Retro and Skip'n Go ) Bevy Retro is a 2D, pixel-perfect renderer for Bevy that can target

Katharos Technology 142 Nov 24, 2021
Text Renderer written in Rust using HarfBuzz for shaping, FreeType for rasterization and OpenGL for rendering.

Provok Text Renderer written in Rust using HarfBuzz for shaping, FreeType for rasterization and OpenGL for rendering. Input Provok is fed with a JSON

Ossama Hjaji 53 Oct 31, 2021
Rust-based replacement for the default Minecraft renderer

wgpu-mc ?? A blazing fast alternative renderer for Minecraft Intro WebGPU is a new web specification designed to provide modern graphics and compute c

Birb 21 Nov 23, 2021
High performance Rust ECS library

Legion aims to be a feature rich high performance Entity component system (ECS) library for Rust game projects with minimal boilerplate. Getting Start

Amethyst Engine 1.2k Nov 25, 2021
A interactive and fun to use memory game written in Rust

memg - Memory Game memg is a interactive and fun to use memory game written in rust Installation Make sure you have rust installed. Use this official

null 4 Sep 9, 2021
A Bevy plugin to use Kira for game audio

Bevy Kira audio This bevy plugin is intended to try integrating Kira into Bevy. The end goal would be to replace or update bevy_audio, if Kira turns o

Niklas Eicker 57 Nov 22, 2021
Easy to use game engine

arcana Arcana is a game engine built with focus on ease of use without compromising on level of control. Getting started Starting writing a game is as

Zakarum 0 Oct 27, 2021
A single-threaded polling-based Rust async executor suitable for use in games, embedded systems or WASM.

simple async local executor An Enlightware® software. Overview A single-threaded polling-based executor suitable for use in games, embedded systems or

Enlightware GmbH 9 Nov 23, 2021
GDDB is a superfast in-memory database designed for use in Godot

GDDB GDDB is a superfast in-memory database designed for use in Godot. This database aims to provide an easy frontend to an efficient in-memory databa

Richard Patching 3 Oct 17, 2021
Victorem - easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust.

Victorem Easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust. Example Cargo.toml [dependencies] vict

Victor Winbringer 18 Nov 8, 2021
A Rust wrapper and bindings of Allegro 5 game programming library

RustAllegro A thin Rust wrapper of Allegro 5. Game loop example extern crate allegro; extern crate allegro_font; use allegro::*; use allegro_font::*;

null 68 Nov 24, 2021
RTS game/engine in Rust and WebGPU

What is this? A real time strategy game/engine written with Rust and WebGPU. Eventually it will be able to run in a web browser thanks to WebGPU. This

Thomas SIMON 231 Nov 24, 2021
A curated list of wgpu code and resources.

Awesome wgpu A curated list of wgpu code and resources. PRs welcome. About wgpu https://github.com/gfx-rs/wgpu-rs matrix chat https://matrix.to/#/#wgp

Roman Frołow 200 Nov 24, 2021
grr and rust-gpu pbr rendering

grr-gltf Barebone gltf viewer using grr and rust-gpu. Currently only supports a single gltf model! Assets These files need to be downloaded and placed

Markus Siglreithmaier 28 Nov 24, 2021
A no-frills Tetris implementation written in Rust with the Piston game engine, and Rodio for music.

rustris A no-frills Tetris implementation written in Rust with the Piston game engine, and Rodio for music. (C) 2020 Ben Cantrick. This code is distri

Ben Cantrick 12 Nov 19, 2021
Scion is a tiny 2D game library built on top of wgpu, winit and legion.

Scion is a 2D game library made in rust. Please note that this project is in its first milestones and is subject to change according to convience need

Jérémy Thulliez 74 Nov 22, 2021
The Bloat-Free Browser Game in Rust but in C and in UEFI

rust-browser-game but in UEFI instead of browser quick start deps rust gnu-efi gcc make build process $ make running after building everything you wil

bit6tream 10 Oct 11, 2021
Tiny cross-platform webview library for C/C++/Golang. Uses WebKit (Gtk/Cocoa) and Edge (Windows)

webview A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUIs. Also, there are Rust bindings, Python bindings, Ni

webview 9.1k Nov 22, 2021
Bevy plugin helping with asset loading and organisation

Bevy asset loader This Bevy plugin reduces boilerplate when loading game assets. The crate offers the AssetCollection trait and can automatically load

Niklas Eicker 36 Nov 14, 2021