Skip to content

bewerner/miniRT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Title_Image

Contents

Introduction
Features
Rendered Scenes
Dependencies
Installation
Usage
Controls
Scene file format
Assets

Introduction

This project started out as a team project at 42 Heilbronn Coding School together with nmihaile. While the original subject asks for a simple CPU Raytracer, we wanted to learn more about graphics programming and try to create something more complex with openGL for the GPU.

After concluding the team project, I continued to work on making it more physically accurate using Blender Cycles as a reference, restructure things, add more features and create new scenes. I probably spent the most time on my multiple importance sampling implementation for the HDRi environment maps. It's capable of rendering nice looking scenes, but it's very much a naive and hacky implementation. The same goes for many of the more complex parts of the program, but I'm happy with how it turned out in the end and looking forward to learn more in the future.

Features

  • HDRi Enviromnemnt Maps illuminate the scene using multiple importance sampling.
  • Material properties (Roughness, Metallic, Base Color) can be values or textures
  • Normal Maps
  • Point Lights (with radius)
  • Primitives: Sphere, Cylinder, Hyperboloid and Plane



  • Reflections and Bounce Light (glossy/diffuse bounces)



  • AgX color mapping (I created my own 3D LUT using Blender)



  • Viewport Shading Modes: Render, Solid and Normal (with Blender-like Gizmo)



  • Adaptive renderscale during viewport navigation to ensure smooth FPS



Rendered Scenes

road.rt
road

metal.rt
metal

ocean.rt
ocean

poker.rt
poker

poker2.rt
poker2

wireframe_cube.rt
wireframe_cube

infinity_mirror.rt
infinity_mirror

random_materials.rt
random_materials

rainbow.rt
rainbow

checkerboard.rt
checkerboard

soft_light.rt
soft_light

caleidoscope.rt
caleidoscope
   ( hold to animate )

Comparing with Blender Cycles

left is Cycles, right is miniRT


Roughness from 0.0 to 1.0

Cycles

miniRT


Metallic from 0.0 to 1.0

Cycles

miniRT


IOR (Index of Refraction) from 1.0 to 2.0

Cycles

miniRT


Dependencies

Debian / Ubuntu

sudo apt update
sudo apt install build-essential libx11-dev libglfw3-dev libglfw3 xorg-dev

Arch (x11)

sudo pacman -S glfw-x11

Arch (wayland)

sudo pacman -S glfw-wayland

MacOS

brew install glfw

Installation

git clone https://github.com/bewerner/miniRT.git
cd miniRT
make

Usage

./miniRT path_to_scene_file.rt

Controls

Movement

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀Key⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀Description⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
W, A, S, D Move around
E or Space Move up
C or Shift Move down
Right Mouse Button and drag Look around
Scroll Wheel up/down Increase/decrease movement speed
M Toggle mouse input (if there are issues)

Camera

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀Key⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀Description⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
F Toggle depth of field
R Reset camera view
Numpad 1, Numpad 3, Numpad 7 Axial view
P Print camera info

General

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀Key⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀Description⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
Tab Cycle through shading modes (Render, Solid, Normal)
V Cycle through color view transforms (AgX, Standard, Raw)
G Toggle gizmo in render mode
I / K Increase/decrease render scale
O Save screenshot
Esc Quit

Scene file format

The .rt scene file format describes the scene with identifiers followed by their specific parameters. Parameters and sections marked with * are optional.

Positions and directions are specified as vec3. (X/Y/Z values as floats)
Colors are generally specified as u8vec3 (R/G/B values beween 0-255).
Some color parameters can alternatively be mapped to a texture.
Others are specified as float or int.

Camera

ID    position    view-direction    field of view (horizontal)    f-stop*    focus-distance*
C     vec3        vec3              float                         float      float

Ambient

Single color ambient or HDRi environment map

ID    strength    color
A     float       u8vec3/filepath_to_environment_map.hdr

Point light

ID    position    power (in watts)    color     radius*
l     vec3        float               u8vec3    float

Render settings

ID    max diffuse bounces    max glossy bounces    max_samples*
R     int                    int                   int

Window size

ID    width    height
W     int      int

Textures

There are two types of textures: image texture and 3D checkerboard texture.
Images textures are limited to 10 per scene and overall textures are limited to 100 per scene.
Textures are defined with the tex identifier and can be referenced by their name in any material.

Image texture

ID     name        type     path
tex    any_name    image    filepath_to_image_file

Checker texture

ID     name        type       scale    color_1    color_2
tex    any_name    checker    float    u8vec3     u8vec3

Materials

Materials are defined with the mat identifier and can be referenced by their name in any object.
Materials are limited to 100 per scene.
Transmission is not implemented. It does nothing, but a value has to be provided.
Emission is not really properly implemented but it has an effect.

Material

ID     name        base color        metallic          roughness         IOR      transmission    emission_strength    emission_color
mat    any_name    u8vec3/texture    u8vec3/texture    u8vec3/texture    float    float           float                u8vec3

Primitives

If a primitive has no material, a default material will be used. If a primitive has no color, it's material color will be used. UV-scale takes one float to uniformly scale the UV or a vec2 to scale width and height individually.

Plane

ID    origin    normal    color*    material*    uv-scale*
pl    vec3      vec3      u8vec3    material     float/vec2

Sphere

ID    origin    diameter    color*    material*    uv-scale*
sp    vec3      flaot       u8vec3    material     float/vec2

Cylinder

ID    origin    orientation    diameter    height    color*    material*    uv-scale*
cy    vec3      vec3           float       float     u8vec3    material     float/vec2

Hyperboloid

ID    origin    orientation    height    a        b        c        shape    color*    material*    uv-scale*
sp    vec3      vec3           float     float    float    float    float    u8vec3    material     float/vec2

I also included the Blender Python Script I used to create these scenes in Blender and export them into the .rt file format. It's incomplete though and still requires some manual edits and additions. To use it, change the output_file_path on top.

Assets

HDRi Environment Maps

from Poly Haven:

PBR Material Textures

from ambientCG:

from 3D Textures:

from cgbookcase

from Free PBR