Graphics Flashcards
What is a frame buffer?
A memory space that stores a grid
What is double buffering?
Where the front buffer’s image is being displayed on screen, and the back buffer contains the image that is currently being rendered. Then you swap the two buffers so the image that was being rendered earlier is now being displayed. WebGL does this for you automatically.
Vertex shader vs fragment shader
Vertex shader: The programmable shader that handles the processing of individual vertices
Fragment shader = pixel shader: takes care of how the pixels between the vertices look
Vertex Buffer Objects
Contain the data WebGL needs to describe the geometry that will be rendered
Index Buffer Objects
Contain integers that are used as references pointing to data in VBOs, in order to enable the reuse of the same vertex
Local coordinates and world coordinates
Each object in a 3D space is constructed on a dedicated coordinate system, and the purpose of this is to reduce complication for 3D scene construction. Then we apply the model transform which gives us the world coordinates (the single coordinate system for all objects in the scene). The view transform gives us the inverse, turning the world coordinates into view coordinates.
Perspective projection vs orthographic projection
Perspective: near and far planes of frustum are different
Orthographic: near and far planes are the same
View frustum
Name of the visible region, defined by six planes: near/far, top/bottom, right/left.
Viewport transform
The viewpoint transform maps the projected view to the available space in the computer screen (canvas).
Scaling operation
(a, 0 | 0, b)
Anticlockwise rotation
(cos, -sin | sin, cos)
Shear along x
(1, k | 0, 1)
Reflect in x-axis
(1, 0 | 0, -1)
Homogeneous coordinates
Coordinates in “projective space”. The W component scales all the others. If we have the homogeneous 2D coordinate (x, y, w), the Cartesian form is (x/w, y/w). Under homogeneous coordinates, 2D transformation matrices become 3D. Multiplying homogeneous coordinates by a scalar represents the same point as before.
Perspective transformation
Transforms each object so that the distant object appears smaller. The view volume in the shape of a frustum will become a regular parallelepiped.
Perspective transformation equations
x’ = dx/z
y’ = dy/z
z’ = z
d is the distance of the image plane from the centre of projection
Shading
The process of altering the colour of an object/surface/polygon, based on the type of light source emitting light.
Flat shading
Assign a single colour to each face of an object
Smooth shading
Apply lighting against the normal vector at each vertex, to calculate vertex colours (vertex shader). The colours across a face are generated by interpolating the colours obtained at the corner vertices of the face (rasterisation).
Phong shading
Normal vector at each point over an object surface is obtained by interpolating normal vectors of the corner vertices of the surface (rasterisation). The colour of each surface point is then calculated by applying lighting against the interpolated normal vector at the point (fragment shader)
Types of light source
Directional light: like the sun, generates light from very far away, parallel rays
Point light: like a light bulb that emits light artificially in all directions from a point
Ambient light: represents indirect light, light emitted from all light sources and reflected by walls
Calculating overall surface colour
surface colour by diffuse reflection + surface colour by ambient reflection
Ambient reflection
Reflection of light from indirect light sources, illuminates an object equally from all directions with the same intensity, its brightness is the same at any position
Diffuse reflection
Reflection of light from a directional or point light. Light is reflected equally in all directions from where it hits (due to rough surface). “t” is the angle between light direction and surface orientation (direction perpendicular to surface).
surface colour by diffuse = light colour * base colour of surface * cos(angle between light and normal)