This is a collection of my computer graphics related implementations. Including physics simulation (PhySim), software renderer (Renderer) and some math (Math).
This project is built with MinGW under window. All the dependencies have been contained as submodule in the external
folder, so add the --recursive
flag when cloning the repository.
The dependencies are listed as follows:
- raylib: simple visualization
- eigen3: vector math
- raygui: gui components
- rlimgui(imgui): same as raygui
It is recommended to download MinGW from w64devkit. To compile the project, cmake is also required.
git clone --recursive https://github.com/lovoski/CG.git
cd CG
mkdir build
cd build
cmake ..
make
The learning resources includes Fluid Simulation for Computer Graphics by Robert Bridson.
Position-Based Simulation Methods in Computer Graphics by Jan Bender.
All the simulators are present as simple 2d form, so that i can understand the concepts of these methods and then implement a 3d version with unity.
There are some simulators I think worth mentioning.
The first one is a damping spring simulator based on PBD method.
In the demo, the red point is the start point of the system, the green points are the expected rest positions of correponding blue points, if the blue point has a different position with the green point, a damped spring force will be applied to the very blue point. One simulation during one frame consists of multiple substeps. To help accelerate the animation, a constant speed
is multiplied to dt
in each frame.
PBD is an intuitive method to simulate simple phenomenon. During the simulation, the object is considered as a set of particles each with its own position and velocity. Our job is to update the velocity with some specific velocity-updating rule. Then integrate the velocity with time to get the delta amount of position. The pipeline of PBD can be represented as follows.
The learning resource includes FABRIK by Andreas Aristidou.
FABRIK is an exemplary heuristic iterative inverse kinematics solver, surpassing other existing solvers in terms of its remarkable simplicity and unparalleled flexibility.
In this repository, a simple multi-target solver is implemented in 2d.
The learning resource is Spring It On by Holden which gave a detailed explaination to the equations used to construct a simple damper, an exact damper, and some spring dampers.
It is noteworthy that solving an exact spring damper involves solving an ordinary differential equation (ODE) with the following structure:
Holden gave an analytic solution for this ODE under three conditions named cirtical damped, under damped and over damped.
To make a controller based on the damper, we would put the user input as 2d vector indicating the desired velocity for the player in current frame, and use a spring damper to approximate the desired speed. The positions is itegrate direction from the analytic solution of velocity.
I wrote a simple demo of it :
The learning resource includes tinyrenderer by ssloy, games101 by Lingqi Yan.
The learning resource includes RayTracingInOneWeekend by Shirley et al.
A simple halfedge mesh data structure from scratch is included in DS/Halfedge.h
:
CG::HalfedgeMesh mesh(RESOURCE_DIR "/cloth.off");
int vn = mesh.GetNumVertices();
int vf = mesh.GetNumFaces();
int ve = mesh.GetNumHalfedges();
PrintEdgeInfo(mesh, mesh.Next(e1));
PrintEdgeInfo(mesh, mesh.Next(mesh.Next(e1)));
auto neigh = mesh.NeighborsOfVertex(0);
The following image shows the query of the halfedge data structure: