3D Graphics Flashcards
Covers a wide range of topics regarding 3D graphics and rendering
List several differences between GPUs and CPUs.
CPU | GPU
————————————-|—————————–
Several cores | Many cores
Low latency | High throughput
Good at serial processing | Good for parallel processing
What components does a typical GPU consist of? How are they organised?
GPUs organise their cores into groups (called blocks or compute units). Each one has the following:
- A set of cores
- Scheduler
- Register file
- Instruction cache
- Texture and Texture mapping units
- L1 cache
Why is GPU and CPU memory incompatible?
GPU memory typically has a wide interface with more room for p2p connections. This means it runs at a higher clock speed than CPU memory. CPU memory tends to have lower latency, but lower bandwidth.
What bottlenecks can occur when transferring data between GPU and CPU?
Slow CPU, fast GPU - CPU cannot send enough data to GPU fast enough, underutilizing GPU.
Fast CPU, slow GPU - GPU cannot process and return sent data quickly enough.
List and briefly describe some modern graphics APIs.
OpenGL - An old graphics API developed by the Khronos group.
OpenGL ES - OpenGL for embedded systems (a subset of OpenGL). Stripped down - all ES apps will work on non-ES, but not vice-versa.
WebGL - A limited version of OpenGL ES - designed to run in a web browser.
Vulkan - Lower-level API by Khronos allowing more control and optimisations than OpenGL.
Metal - Graphics API designed specifically for Apple’s hardware.
DirectX - Lower-level API by Microsoft, has similar advantages over OpenGL, but Windows-only. Direct3D is the actual 3D graphics component, DirectX includes other parts such as text, audio, video, raytracing etc.
Explain how double-buffered rendering works, and why it is used?
This is a technique used by the GPU for avoiding stuttering, tearing and other artifacts. It accomplishes this by ensuring there is always a buffer to obtain graphics data from every frame.
The GPU sends data to one of two buffers. The data on this buffer is displayed on the screen as a frame. While being displayed, the GPU fills up the other buffer with new data. When displaying the next frame, it switches to the other buffer and the cycle repeats.
Describe the differences between vector and raster graphics.
Raster Graphics | Vector Graphics
———————————————————-|——————————————
Composed of pixel data. | Composed of paths
Refresh image regardless of complexity | Refresh tied to number of lines displayed
Scan conversion required | Scan conversion not necessary
Scaling shows deformities | Scaling does not show deformities
Space occupied dependent on quality | Not dependent on quality
Describe the steps of the rendering pipeline.
1) Vertex Specification - Prepares vertex data for processing.
2) Vertex Shader - Processes vertex data to produce output vertex data 1:1.
3) Tessellation - Splits up primitives, used to add higher LOD dynamically.
4) Geometry Shader - Processes primitives to modify them or output new ones.
5) Vertex Post-Process - Caches previous results, performs clipping of non-visible primitives.
6) Primitive Assembly - Converts vertices into primitives (vertex groups), does face-culling.
7) Rasterization - Scan-converts primitives to fragments.
8) Fragment Shader - Processes fragment data, outputs colour, depth and stencil values.
9) Sample Operations - Includes stencil and depth tests, blending and more.
Describe how transparency can be achieved in 3D rendering.
Transparency can be achieved by blending fragments that lie on semi-transparent textures. The distance order from the camera needs to be known to achieve this, so it can be achieved with the following steps:
1) Draw all opaque objects first.
2) Sort all transparent objects in distance order from the camera (nearest to furthest).
3) Draw all transparent objects in that order.
This may be difficult to achieve depending on how the scene is setup, and won’t work with deferred rendering. Order-independent transparency techniques do exist however.
What are the differences between forward and deferred rendering?
In forward rendering, geometry from many sources is passed throuh their respective pipelines through vertex and fragment shaders. The fragments are all passed to a final render target.
In deferred, the fragment shaders omit lighting calculation. The fragments are instead passed to an intermediate stage, in which all lighting calculations are done instead before passing to a final render target.
The main benefit is performance improvement. Instead of doing lighting calculations per fragment (many of which will be discarded), we are doing it per pixel. Given that there are often far more fragments than pixels, this reduces the number of calculations required.
There are several disadvantages however:
- Transparency isn’t possible (a workaround is to use forward with transparent objects).
- Use of the G-buffer to store intermediate data can eat a lot of memory.
- Anti-aliasing is difficult to achieve without workarounds.
- Can only use a single material type for each object.
What are the differences between rasterization and raytracing?
Rasterization works by iterating over object vertices, then projecting the calculated fragments onto the screen. While this approach is fast, it doesn’t describe how the object should appear and limits its ability to produce photorealistic images.
Raytracing works the opposite way - it fires rays through each screen pixel at objects in the scene. Rays bounces off objects are calculated until reaching a light source (though bounces are limited to keep calculations manageable). This allows raytracing to produce more photorealistic images. Pathtracing is a similar concept, but bounces are limited to 1.
How is shadow mapping accomplished?
Shadow mapping is accomplished in two passes. The first pass generates a depth map from the light source’s perspective. This requires a light space matrix (using light source view / projection matrices) and vertex positions. No fragment shader is required as depth values get calculated anyway per fragment. The result is rendered onto a texture of some given size.
The second pass then renders using the shadow map texture. The texture is passed into the fragment shader for a given object. We can then determine if a fragment lies within the shadow map, and adjust its brightness accordingly so.
What causes shadow map aliasing, and how can we combat it?
Shadow map aliasing are visual defects in shadows due to a mismatch in shadow map resolution and pixel distance from eye. Too high a pixel-texel ratio and shadows appear blocky, too low and artifacts start getting introduced.
Cascading shadow maps are a technique that can be used to fix this. It works by splitting the light projection frustum into several sub-frustums and calculating shadow maps for each one with lowering resolutions. The vertex shader calculates lighting with each map, then the fragment shader determines the appropriate shadow map to use for the distance and lights it accordingly.
List 3 culling techniques.
Frustum - Clips all objects not lying within the viewing frustum.
Depth - Used for hidden surface removal, gives z-values to each fragment to determine if one object lies in front of another (from the camera’s perspective).
Backface - Using depth values, culls back faces for each polygon.
What buffers are available for each pixel?
Color - Holds the pixel color data.
Depth - Holds the depth value for a given pixel (AKA Z-buffer).
Stencil - Extra per-pixel data mask to determine if pixel gets drawn.