Software Rasterizer & Pathtracer & MeshEdit & Animations

This project is finished when I am taking Computer Graphics (Spring2024) at Carnegie Mellon University as homework . The public repository for the basic framework is here: https://github.com/CMU-Graphics/Scotty3D

Scotty3D is a 3D modeling, rendering, and animation package like Blender, but we will need to complete the main algorithms and functions such as Rasterization and Path-tracing rendering, MeshEdit operation, and Animations including Skeleton Kinematics and Skinning and Particle Simulation.

Rasterizer

Final result: Girl with a Pearl Earring rendered with rasterizer.

For Assignment 1 – Rasterizer, we are supposed to implement what Modern GPUs do in a Rasterization Pipeline, which has several highly parallel stages to converting 3D triangles into 2D pixels. Instead of rendering with GPU, we implement this pipeline in software using CPU to render things.


obj file is from the model I made before. This is the stylized model from the painting Girl with a Pearl Earring by Johannes Vermeer.

Scene Functions

 

  • Implemented local_to_world() and world_to_local() functions to get the transformation(4×4 matrix) from object space all the way to / from world space with scaling, rotation, and translation.

 

1. Line rasterize 2.Flat triangle 3.Smooth triangle 4. Perspective-correct triangle

Lines, Triangles Rasterization, and Triangles Interpolations

 

 

before
After

Depth Test and Color Blend

  • Implemented Depth test function Depth_Less() and Blending function Blend_Add() and Blend_Over()(alpha blending).

 

Mip-Map
Mip-Mapping

Mip-Mapping and Texture sampling

  •  

before
after 8x8 SSAA

Supersampling

  • Implemented a framebuffer to store new index points within one pixel sample point(x,y) and to resolve the pixel color into a weighted average of these new points. and then generate new fragments for these new sample points.

 

Pathtracer

Camera Rays

 

  • Simulate “backwards” scene traversal, shoot rays from the camera out into the scene.

  • Generate rays from cameras measure the amount of scene radiance that reaches a point on the camera’s sensor plane, as the first step in the raytracing procedure.

 

PathTracer result on model colored based on surface normals

Intersecting Objects

  • Triangle intersection is using Möller-Trumbore algorithm and Cramer’s rule as the method discuss here.

  • Sphere intersection is using an algebraic approach
  • tracer return UV and normal value on intersection. 

BVH

  • Constructed BVH and related intersect algorithm to make ray scene intersection faster. First, calculate the Bounding Box and the intersection of boxes, details can be found here. Next construct a BVH using the Surface Area Heuristic, following the picture shown here:

Traversal

  • Also Implemented ray-BVH intersection to decide whether scene objects in this BVH branch should be draw or not.

Lighting

  • Implemented Lambertian BSDF and sample_indirect_lighting and sample_direct_lighting related functions.
  • Implemented the next event estimation lighting procedure by splitting samples between BSDF scatters, and the area lights. more details

  • Implemented the Mixture Sampling and multiple-importance sampling

     

albedo gives the ratio of incoming light to reflected light, and then according to the ratio of incoming to outgoing radiance given a pair of directions, we can compute the PDF for sampling some incoming direction given some outgoing direction.

 

Then we sample indirect/direct lighting and Compute a Monte Carlo estimate of these two terms.it is only importance to sample the BSDF term of the rendering equation, so it exhibits far lower variance.

Materials

Environment Lighting

  • Realized a new type of light source: an infinite environment light. Importance sampling an HDR environment map, and then calculating for the Jacobian for transforming the PDF from the HDR map sampling distribution to the unit sphere.

MeshEdit

MeshEdit operations use a pointer-based structure, Halfedge_Mesh operations will often require the allocation and deallocation of new elements. more details can be seen here.

To be short, we use Halfedge, a Linked-list-like structure to move around the mesh and grab the element we want.
 

Local operations

Flip Edge

Split Edge

Collapse Edge

Extrude Face

Global operations

Triangulate

Linear Subdivision

Catmull-Clark Subdivision

Loop Subdivision

Animation

Catmull-Rom spline

  • Object movements are implemented using the Catmull-Rom spline. Details can be found here.

Particle Simulation