Skip to content

CPU Raytracer implemented in unity using Unity physics engine.

Notifications You must be signed in to change notification settings

narenragu/Raytracing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unity CPU Raytracer

Background

I've always been interested in Computer Graphics and the math that goes into rendering a 3D scene, so I decided to create my own raytracer in Unity as an excercise.

Rays are cast using Unity physics engine and colliders.

Features

  • 3 Types of lights with intensity and range controls
    • Directional
    • Point
    • Ambient
  • Shadows
  • Glass
    • Refraction
    • IOR controls per object
  • Metal
  • Specular Reflections
  • Texture Mapping
  • [Optimize] flag to render half of pixels every other frame to improve realtime performance
  • Render resolution controls independent of viewport resolution

Limitations

  • All rendered objects must use a mesh collider in order for texture mapping to work
  • [Unity Materials Raytracer] component must be disabled and enabled when adding new mesh collider objects in runtime
  • All rendered objects must have a [Raytraced Material Properties] component
  • Transparency for non-glass materials is not implemented
  • Roughness (scattering) is not implemented for glass
  • Performance is not great due to being a purely CPU based implementation

Screenshots and Videos

All of the below GIFs are captured realtime, in editor

Notes

This project was created and tested on an M2 Macbook Pro 14 running MacOS. At 160x90 raytracing render resolution, the project averaged ~25-30 fps in editor with [Optimize] flag enabled. At 320x180 raytracing render resolution, the project averaged ~10-15 fps in editor with [Optimize] flag enabled.

Resources

Below is a short list of websites I referenced in order to create this implementation:

About

CPU Raytracer implemented in unity using Unity physics engine.

Topics

Resources

Stars

Watchers

Forks