Skip to content

About

A CPU triangle renderer in C++ using ray-plane intersections, barycentric area tests, supersampling, and PPM output.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Triangle Renderer — C++

A small CPU renderer that draws an antialiased triangle using ray-plane intersections and barycentric area tests.

White triangle rendered on a black background

Overview

A computer-graphics learning exercise implemented in C++. For each pixel, the program casts jittered orthographic rays at a triangle, checks whether the intersection is inside it, and averages the samples to soften its edges. The result is written as a binary PPM image.

Features

  • Three-dimensional vector operations and triangle-normal calculation.
  • Ray-plane intersection followed by an area-based inside-triangle test.
  • Forty jittered samples per pixel.
  • A 1024 × 1024 grayscale result stored as RGB pixels.
  • A minimal Makefile and no third-party runtime dependencies.

Tech stack

  • C++11
  • Standard C/C++ math and file I/O
  • Make

Getting started

Install a C++ compiler and Make, then run:

git clone https://github.com/ericksonnoah5/Triangle-Renderer-CPP.git
cd Triangle-Renderer-CPP
make render

This builds triangle and generates triangle.ppm in the current directory. Open it with a viewer that supports PPM. On macOS, open triangle.ppm opens it in the default viewer. The PNG above is a preview generated from the program's output.

Other commands:

make          # Build only
./triangle    # Render again
make clean    # Remove executable and generated PPM

Configuration

Edit WIDTH, HEIGHT, and SSLEVEL in src/triangle.cpp to change the image size or sample count. The triangle's three vertices are assigned in main(). Coordinates are in the same units as the image grid; adjust them if you change the dimensions.

Project structure

src/triangle.cpp   Vector math, intersection tests, sampling, and PPM output
docs/triangle.png  Preview generated by the renderer
Makefile           Build, render, and clean targets

Limitations

The scene contains one fixed white triangle on a black background with an orthographic camera. There is no lighting, texture mapping, scene loader, or interactive view. The random generator is not explicitly seeded. The intersection code assumes a nondegenerate triangle whose plane is not parallel to the rays.

Credits

Published by Noah Erickson as a computer-graphics learning exercise.

License

Available under the MIT License.

About

A CPU triangle renderer in C++ using ray-plane intersections, barycentric area tests, supersampling, and PPM output.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages