Skip to content

balintkissdev/3d-renderer-rust

Repository files navigation

Real-time 3D renderer with OpenGL 4/WebGL2 written in Rust

Build

A hardware-accelerated 3D renderer written in Rust. Runs using OpenGL 4.3 as graphics API on desktop and WebGL2 on WebAssembly.

Click here for C++ version of this project

Demo

Table of Contents

Try it out!

Motivation

This project is a demonstration of my expertise to use the Rust programming language to write cross-platform 3D graphical applications that run both on desktop (Windows, Linux) and on the web with WebAssembly. The project showcases confident usage of the following technologies:

  • Rust
  • 3D graphics programming with OpenGL 4 and WebGL2 (based on OpenGL ES 3.0)
  • Immediate mode overlay GUI using egui (as opposed to retained mode GUI frameworks like Qt)
  • Building for WebAssembly using webpack
  • HTML bindings into Rust binary
  • Advanced cargo features (crate patching)

Future additions will include Direct3D, Vulkan rendering backends and additional post-processing effects.

Features

  • 3D model display from OBJ file format
  • Fly-by FPS camera movement
  • Skybox display using cube-map
  • Directional light with ADS (Ambient, Diffuse, Specular) lighting (Phong shading)
  • Live browser demo
  • HTML controls interacting with the 3D scene
  • Pure Rust dependencies without relying on C/C++ library bindings

Requirements

Desktop executable requires an OpenGL 4.3 compatible graphics adapter to run. Check if your hardware supports OpenGL 4.3 and have the latest graphics driver installed.

Web browser live demo requires support of WebGL2.

Dependencies are automatically downloaded by cargo.

Build instructions

  1. Make sure you have the latest stable version of Rust and cargo installed, following the instructions on https://www.rust-lang.org/tools/install

  2. Clone the repository

git clone https://github.com/balintkissdev/3d-renderer-rust.git
cd 3d-renderer-rust
  1. Compile and execute the release build
cargo run --release

WebAssembly build

Web build requires Node.js and npm as package manager. The recommended way to install npm is using a Node version manager like nvm.

Use npm to install Node package dependencies:

npm install

Build the web application (there's no need to install wasm-pack separately, because it is automatically downloaded locally by webpack):

npm run build

Run the web application by serving it on live server:

npm run serve

You can access the application at http://localhost:8080.

Usage

Use keyboard and mouse to navigate the 3D environment.

  • Movement: W, A, S, D
  • Mouse look: Right-click and drag
  • Ascend: Spacebar
  • Descend: C

Modify UI controls to change properties of the 3D model display. Browser demo also has HTML controls.

Resources