Table of Contents
1. Shader
- Shader is the code that runs on GPU.
- Use math instead of branching in production code, since the GPU is optimized for a single path.
1.1. OpenGL
- Standard for shader codes and its execution. GLSL(OpenGL Shader Language) is used.
- Looks much like C. Initialized and start the
void main()
function.
1.1.1. Vector
- Defined using
vec2
,vec3
,vec4
. - Vector components can be accessed in various ways.
- x, y, z, w / r, g, b, a / s, t, p, q
1.1.1.1. Swizzling
- Concatenate the lables of the components to access specific parts
of a vector.
- e.g.
pos.yx
is[pos.y pos.x]
.
- e.g.
1.1.2. Global Variables
1.1.2.1. Uniform Variable
- Permanantly set before the shader code.
- Accessed everywhere.
1.1.2.2. Attribute
- A const that is specific to a vertex.
- Only accessed by vertex shader.
1.1.2.3. Varying Variable
- A variable that is set by the vertex shader for each fragment so that it can be accessed in later stages.
1.1.3. Vertex Shader
1.1.3.1. Attributes
- Initialized with
attribute <type> <name>
.
1.1.3.1.1. p5.js
vec3 aPosition
vec2 aTexCoord
- Texture Coordinate
1.1.3.2. Outputs
vec4 gl_Position
1.1.4. Fragment Shader
1.1.4.1. Outputs
vec4 gl_FragColor
1.2. Vulkan
- New standard that is faster and more modern than OpenGL.
2. Graphics Pipeline
2.1. Vertex Shader
- Take Uniforms and Attributes and generate Varyings
2.2. Geometry Shader
2.3. Fragment Shader
2.3.1. Diffusion
2.3.1.1. Lambertian Diffusion
- A way of modeling diffusion. It utilizes Lambert's cosine law: \[ \vec{L}\cdot\vec{N}=\cos(\theta). \]
2.3.2. Specular Light
- It is light sources getting reflected: \[ \vec{N}\cdot(\vec{L}+\vec{V}). \]
2.3.3. Ambient Light
- A constant color that's added to all fragments.
2.3.4. Reflection
- Ray tracing
- Screen space reflection
- Image based reflection
2.3.4.1. Fresnel's law
3. Color Management
The working color space often has wide gamut and linear transformation function, while that of the displays and photos often has narrow gamut and non-linear transformation function in order to save disk space.
For example, Blender uses Lienar Rec.709 color space as a working color space. The displayed color and PNG files often uses sRGB with Gamma 2.2 as the transformation function.
The color space transformation happens whenever the software or hardware that processes the color changes.
In the case of printer, the color space has to be manually adjusted in order to compensate for the degradation of the machine.
4. Occlusion
- How Games Have Worked for 30 Years to Do Less Work - YouTube
- View Frustum
- Pre-Render Depth Map
5. Gaussian Splatting
- 3D Gaussian Splatting! - Computerphile - YouTube
- Create a scene of bunch of small specs of 3D Gaussians, by means of gradient descent over the entire original images, which then can be rendered by rasterizing it onto the screen.
- It is significantly faster than NERF.
6. Voxel Engine
6.1. Mesher
- Figure out what quads to draw, from the voxel data
- Blazingly Fast Greedy Mesher - Voxel Engine Optimizations - YouTube
- Greedy Mesher
- Culled Mesher