top of page
Writer's picturefeng jessica

Software Rasterizer & Pathtracer & MeshEdit & Animations

Updated: Jan 2, 2023

involved technology: C++,CG algroithm

This project is finished when I am taking 15-462/662 Computer Graphics (Fall2022)at Carnegie Mellon University as a homework in this class. The public repository for the basic framework is here: https://github.com/CMU-Graphics/Scotty3D

(my personal solution not included because we are not allowed to upload our own repository).

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 :duck renderd with rasterizer. obj and texture are from:https://www.cs.cmu.edu/~kmcrane/Projects/ModelRepository/

For the Assignment 1 - Rasterizer, we are supposed to implement what Modern GPUs does 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.


Main feature:



Scene Functions

before and after
  • Implemented local_to_world() and world_to_local() functions to get the transformation(4x4 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 diamonds exit rules and Bresenham's line algorithm.

  • Achieved Triangle rasterization algorithm(flat triangle) following first do a bounding box test(to define the triangle area) then perform point-in-triangle tests and top-left rule to decide whether a fragment should be draw or not.

  • Realized another 2 different Triangle rasterization algorithm with the interpolation in screen-space triangles and perspective-correct triangles.


As the picture below, considering how to project the triangle correctly from 3D space to 2D image. calculate partial derivatives with respect to screen locations using vertex position andattributes ,and then after we interpolate the vertex attribute using Barycentric coordinates for each fragment, we will get the screen-space interpolation(affine).

Here is the alogrithm how we achieve perspective-correct interpolation. In short, we will do first multiply 1/Z value in each vertex attibutes ,do a Barycentric coordinates interpolations with the result and then divide the result with interpolated Z.


final result:

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

  • Implemented clip_triangle(), clip triangle to portion with -w <= x,y,z <= w.Using Sutherland-Hodgeman clipping algorithm. Discard the triangles that lie outside of the normalized coordinate cube. and generate new triangles if parts of is inside of the cube.

Given 6 half plane(near,far,,left,right,top,buttom), Iterate over each triangle edge in the 2D plane, generating new vertices and using them as input for the next edge. After a new iteration through all 6 plane, we will get the new vertex and triangles.



clipping result

clipping result


Depth Test and Blending

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

before

after

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, bilinear, trilinear sampling strategy.


1.line 2.nearest sampling 3.bilinear sampling 4.trilinear sampling

Bilinear sampling process:

Trilinear sampling process:

But also make use of the mip-map levels to perform trilinear,




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


Final render result in Soctty3D using pathtracer as picture below.

Models and textures Credits to my teammembers Xintong Liu,Xiaoying Meng,Yongzi Ye and Yukti Gupte from the class ADVANCED PIPELINE TOPICS FOR FILM AND GAME ART - 53884 - Spring 2021. https://www.artstation.com/artwork/wJ29QY

Also Check out more detail about it in this page.!


Main feature:

  • Implemented Camera rays and Intersection test for triangles and sphere(sphere intersection also is used in the particle detection parts). 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.

Camera rays

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

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

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

BVH result:

with BVH:

without BVH:


  • Implmented Lambertian BSDF and sample_indirect_lighting and sample_direct_lighting related functions.

First Lambertian:::albedo give 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 computes 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 only importance sampling the BSDF term of the rendering equation, so it exhibit far lower variance.


  • Implemented next event estimation lighting procedure by splitting samples between BSDF scatters ,the area lights and doing a mixture sampling. more details

not sampling lights with single PDF and sampling lights with mixture PDF :


final result together so far:




Result together so far:



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

result:



MeshEdit


MeshEdit operations are using a pointer-based structure, Halfedge_Mesh operations(picture 1) will often require the allocation and deallocation of new elements. more detail can be seen here.

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


1

2
  • Implemented 11 local Mesh Operations,such as flip edge, split edge,collapse edge. Also implemented 4 global mesh operations, such as Triangulation, Linear Subdivision, Catmull-Clark Subdivision Positions and Loop Subdivision.



Local operations:

Flip edge, split edge, collapse edge and weld edge:

Inset vertex, dissolve vertex and bevel vertex:

bevel edge and dissolve edge:

extrude face and collapse face:

for the extrude face,I use vertical movement of mouse to control shrink or Enlarge of the face and use horizontal movement of mouse to control move up or down.

Global operations:

triangulation, linear subdivision positions , Catmull-Clark subdivision positions and Loop subdivision:



Animations


Final render out animation made within Scotty3D. rendered with pathtracer. fps 24. 640 * 360.

models and textures are Credits to my teammembers Xintong Liu,Xiaoying Meng,Yongzi Ye and Yukti Gupte from the class ADVANCED PIPELINE TOPICS FOR FILM AND GAME ART - 53884 - Spring 2021. https://www.artstation.com/artwork/wJ29QY

Also Check out more detail about in this page.!



  • Particle simulations












156 views0 comments

Comments


bottom of page