rafx

Rafx

Rafx is a multi-backend renderer that prioritizes performance, flexibility, and productivity. It optionally integrates with the distill asset pipeline to provide workflows and tools suitable for real-world projects with multidisciplinary teams.

This crate contains several layers:

Rafx also provides tools for building shaders and assets.

Documentation

Build Status

Sci-fi Base Screenshot

Editor

Amazon Lumberyard Bistro Screenshot

Amazon Lumberyard Bistro scene (Original assets: https://developer.nvidia.com/orca/amazon-lumberyard-bistro)

Video of Renderer in Use

[^ Video of this renderer running on iOS hardware](https://www.youtube.com/watch?v=Ks_HQbejHE4)

Screenshot of render with real-world assets

Screenshot of LDTK tilemap integration

(Tilemap screenshot is an imported ldtk project file)

Current Support:

Rafx supports most mainstream platforms. Proprietary platforms can be supported by adding an additional backend.

Platform Vulkan Metal DX12 GL ES 3.0 (4,5,6)
Windows  
macOS  
Linux ✅ (1)     ✅ (1)
iOS   🟥 (3)
Android 🟨 (2)     🟥 (3)
WebGL (6)      

Caveats:

  1. Some backend/driver/window manager combinations might not work. Most recently tested with Ubuntu 20.04 LTS.
  2. Android might work with vulkan but has not been tested. (It likely can be made to work)
  3. Mobile OpenGL devices might work but may need improvements to create the initial OpenGL graphics context.
  4. Limitations in the OpenGL ES 3.0 API prevent full implementation. The main demo does not fully work in GL ES 2.0/3.0.
  5. OpenGL ES 3.0 backend still uses 2.0 paths for some functionality. There is room for improvement!
  6. OpenGL/WebGL will not receive much improvement/support going forward.

Please keep in mind, this crate is still in pre-0.1.0 status!

Roadmap

This crate will use semantic versioning rules after 0.1.0 of this project has been published. The 0.0.x versions do not follow semantic versioning rules.

Safety

Rafx is unsafe because hardware-accelerated rendering is fundamentally unsafe. However, we reserve usage of the unsafe keyword for when an operation can produce undefined behavior for reasons other than interacting with the GPU. Please see these documents for more detail:

Prerequisites

CMake must be available on your path. It is used by SDL2 in the demo and by upstream crates used within the shader pipeline.

Running the Demo

The demo should be run from within the demo directory of the repository. These commands should clone the repo and run the demo.

git clone https://github.com/aclysma/rafx.git
cd rafx
cd demo
cargo run --bin demo --release --features "[BACKEND_FEATURE]"

BACKEND_FEATURE should either be rafx-vulkan, rafx-metal, or some other backend.

Running in release reduces logging and disables GPU validation. The first time it will load more slowly because it has to import the assets, including a GLTF mesh with large textures. Using profile overrides to optimize upstream crates is highly recommeneded. Asset processing is extremely slow in debug mode. (i.e. 30s instead of 2s)

Demo Features

Tools

The renderer includes a few tools for processing shaders and packing data in a binary blob.

There is also a blender add-on that works, but is still being prototyped and is not yet documented.

Shader Processor

This tool parses GLSL and produces matching rust code. This makes working with descriptor sets easier and safer!

Diagram illustrating that shaders are processed into .metal, .spirv, etc.

The shader processor produces the following assets artifacts

The shader package can be loaded as an asset and contains everything needed to load a compiled shader.

Packaging Assets

This tool currently is only useful for packing assets.

Blender Add-On

There is also a blender addon that implements workflows for larger levels and exports a custom format that avoids duplicating shared asset data. While it functions, it is still early in implementation and not yet documented.

Video of slice-based level editing in Blender

[^ Video of slice-based level editing in Blender](https://www.youtube.com/watch?v=N6s40XwAghE)

This video shows a scene with >5k objects, 1M+ verts being loaded at once in blender and sliced into multiple smaller pieces on an M1 mac mini.

Features

Crates

FAQ

Q: Why am I getting mysterious panics from a bincode serializer

A: Assets are imported and serialized via serde to bincode. If any of these structs are modified, the asset needs to be reimported. The “proper” fix is to bump the importer’s version, which will force re-importing affected assets. However, deleting .assets_db is an easy fix. In general to avoid this, we should not commit modifications to these structs without also bumping the importer version numbers.

License

Licensed under either of

at your option.

Upstream Dependencies

The demo/fonts directory contains several fonts under their own licenses:

The assets/blender directory contains some shaders from from https://freepbr.com, available under its own license

The skyboxes are from:

assets/ldtk contains sample data from LDTK level editor (MIT):

Some dependencies may be licensed under other terms. These licenses include “ISC”, “CC0-1.0”, “BSD-2-Clause”, “BSD-3-Clause”, and “Zlib”. This is validated on a best-effort basis in every CI run using cargo-deny.

Acknowledgements

Rafx benefits from many great ideas and projects!

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

See LICENSE-APACHE and LICENSE-MIT.