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
- Pathtracer
- MeshEdit
- Animation
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.
Lines, Triangles Rasterization, and Triangles Interpolations
Implemented Line rasterization algorithm using diamond exit rules and Bresenham’s line algorithm.
Achieved Triangle rasterization algorithm(flat triangle) following first doing a bounding box test(to define the triangle area) then performing point-in-triangle tests and top-left rule to decide whether a fragment should be drawn or not.
Realized another 2 different Triangle rasterization algorithms with the interpolation in screen-space triangles and perspective-correct triangles with barycentric coordinates.
Depth Test and Color Blend
Implemented Depth test function Depth_Less() and Blending function Blend_Add() and Blend_Over()(alpha blending).
Mip-Mapping and Texture sampling
- Implemented mipmap generation, sampling, and lod determination from derivatives, according to section 3.8.11 of glspec33.core.pdf.
- Implemented nearest and bilinear for Magnification , trilinear sampling for minification.
- 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.
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
- Implemented Mirror and Glass BSDF materials, according to the reflection and refraction rule – Snell’s Law.
- To govern the glass’s reflected vs. transmitted, implemented the dielectric (non-conductive) Fresnel equations by using Schlick’s approximation.
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.
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.
Rig
Implemented Forward Kinematics & Inverse Kinematics, and Linear Blend Skinning
Used the simplest — forward Euler