Skip to content

kshitijl/tinyrenderer-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

what is it

Pure CPU software renderer written in Rust, following Dmitry V. Sokolov's tinyrenderer course.

can I run it?

Yes! I mean probably. It works on my 2021 M1 MacBook Pro. I might have hardcoded things that won't work on other systems.

You'll need the rust toolchain and just installed. Then:

git clone https://github.com/kshitijl/tinyrenderer-rs.git
cd tinyrenderer-rs
just launch

How do I install just?

After installing rust, do cargo install just.

Things I could implement but didn't

  1. Parallelize using rayon or maybe crossbeam. Figure out how to avoid a lot of contention writing to the depth buffer (and, by extension, at that location in the color buffer). Or maybe just parallelize over all the pixels within one triangle -- those will never contend for the color nor depth buffer because they're different pixels (thanks to Joe Ardent for this insight!).
  2. Rewrite the game logic using hecs. Or roll my own mini ECS.
  3. Keep score and health, then draw them to screen by implementing some kind of font rendering. Maybe Hershey fonts (thanks Dave Long for that reference!).
  4. When the player dies, show a "YOU DIED" message and restart with a new randomly generated world.
  5. When the player wins by uncovering all exhibits, show a short victory sequence.
  6. Guards should not pass through walls. They should pathfind instead.
  7. Play sound effects when: guards enter Alarmed mode, an exhibit is uncovered, damage is taken, we enter FPS mode.
  8. Menu for selecting difficulty level.
  9. Fix the AWFUL clipping in FPS mode when we get too close to walls. This probably involves clipping triangles properly against the view frustum to generate new vertices.
  10. Draw a real player character instead of just a white bouncing model.
  11. Keep the camera behind the player in topdown mode so we can always see them.
  12. Keep the player model from clipping into walls.
  13. Fix the object frustum culling: right now, an object is culled if all of its AABB corners fall outside the frustum. But this incorrectly culls objects that have portions visible inside the frustum, like large walls. Instead, we must check for view frustum instersection.

show me the good stuff! SHOW ME the GOOOOOD stuff it makes

Here's a teaser of the end state:

Video here. Sorry it's a Youtube short! I guess they automatically do that if your video meets certain criteria. Sad.

Here is the journey of this renderer so far:

Test checkerboard patterns to see that TGA output works

Drawing points and lines, working up to Bresenham's all-integer line-drawing algorithm

Loading and drawing a model by simply dropping the Z coordinates and drawing triangles

These are buggy! I had bugs in my Bresenham code

This is correct

You can do rotations in 3D with very little code

Filling in triangles

Lighting

You can do shader effects

Depth

Perspective

Normals for lighting

Mouselook

Visualizing the depth buffer for shadow mapping

More bugs

Trying to get a nice looking flashlight

What's the point of a renderer, show me a game already

Once I had a renderer I figured I might as well make a game with it.

About

Following Dmitry V. Sokolov's tinyrenderer course in Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published