• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/81

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

81 Cards in this Set

  • Front
  • Back
  • 3rd side (hint)

gluLookAt params

X,y,z of eye, X,y,z of reference, X,y,z of up vector

Basic OpenGL2 Pipeline

Primitives (quads and triangles) -> Modelling (built in models, procedurally generated, user generated etc) -> Rendering (textures / illumination models) -> Animation (physics animation, procedurally generated animation)

OpenGL Coordinate Frame

RH Rule



Y index, thumb X, middle z.

Homogeneous coordinates

(X,y,z,h) - a point, (X/h,y/h,z/h) in Cartesian coordinates.



(X,y,z,0) - a vector

Construct a model from triangle mesh:

glBegin(GL_TRIANGLES):


glVertex3f(X1,y1,Z1);


.


.


.


glVertex3f(xn,yn,zn);


glEnd();

Direction of vertices in a primitive triangle or quad

Anti clockwise wrt to outward normal.

Colour Combinations

Red+Green = yellow


Green+Blue= cyan


Red+blue=magenta

Specify colour values openGL

glColor3f(0,1,1) or


glColor4f(0,1,1,1) with optional transparency value

Frustrum Camera Model, glFrustrum parameters

Perspective Camera Model

Camera View

gluLookAt() positions the camera in the world coordinate space, defining a transformation into the eye coordinate frame. The camera is at the origin of this frame, with y_e up, x_e pointing right and -z_e the view axis.

Model-View Transformation

Objects created in own local coordinate space then transformed into world coordinate space (then transformed again into coordinate space of camera to generate the view).

Translation

glTranslatef(a,b,c) - move a units in X direction, b units in y direction and c units in z direction.

Rotation

glRotatef(angle, l, m, n) - rotate angle degrees around axis of rotation l,m,n (right hand rotation rule).

Scale

glScalef(ax,sy,sz)



Self explanatory

Independent transformation of only one object. - make a cube then translate it then scale it.

glPushMatrix();


glScalef(1,4,4);


glTranslatef (3,0,2);


glutSolidCube(3);


glPopMatrix();

Rotate about a pivot point (px,py,pz)

All openGL rotations are done with origin as pivot point. Translate pivot point to origin, perform rotation, translate back.



glTranslatef (px,py,pz);


glRotatef (90,0,1,0);


glTranslatef(-px,-py,-pz);


glutSolidCube (1);

Local Illumination Model

Colour at each vertex is computed using position of light and vertex, surface normal orientation at vertex, position of viewer.



Does not take into account other info, eg light reflected from other objects.

Ambient Reflection

Constant background light, does not depend on light/viewer positions or surface orientation. Typically defined as a low intensity gray, L_a = (0.2,0.2,0.2).



If material colour is M_a:



Ambient Reflection I_a = L_a M_a

Diffuse Reflection

Intensity depends on orientation of surface relative to light direction. Max at angle 0, min at angle >= 90. Light diffuse colour L_d usually (1,1,1).



Light source vector l, normal vector n both normalised then cos(theta) = l•n.



The diffuse Reflection



I_d = L_d M_d * max(l•n, 0)

Specular Reflection + shininess

Bright reflections from mirror or polished surfaces. Specular reflection maximised when view vector (v, unit) is equal to direction of reflection (r, unit) from the light source.




M_s material specular colour usually set to white to provide bright highlight.



L_s = light's specular colour.



"Shininess" refers to the width of the specular highlight. Higher shininess = less spread and more concentrated highlight. Phong's constant/shininess term f controls diameter of highlight. High values give more concentrated highlights.



Specular reflection:



I_s = L_s M_s * (max(r • v, 0))^f

Vertex lighting

OpenGL calculates lighting at each vertex, polygon interiors are filled with interpolation. Face normal vectors assign the same normal to all 3/4 face vertices, so shape looks blocky. Vertex normals give a smooth variation of shades on surface.

OpenGL2 Spotlights

Lights are omnidirectional by default. Make spotlight by specifying



- spot cutoff angle (half cone angle of spotlight)


- spot direction (vector specifying cone axis)


- spot exponent (higher means faster drop off in intensity away from center of spotlight)

Types of Shadow

Backface Shadows - Shadow on the surface of the object when it is oriented away from light, generated by illumination model.



Projected shadows - shadows cast on other surfaces, not generated in openGL 2 lighting model.

Rendering polygons

Vertices just be specified anticlockwise. Polygon must be convex. Specify using GL_POLYGON or triangle/quad to be more specific.

GL_TRIANGLE_FAN

GL_TRIANGLE_STRIP or GL_QUAD_STRIP

Sweep Surface

Surface done by transforming a polygonal element, eg volume of revolution and connecting points between transformative by triangle or quad strips.

Texture Environment

GL_REPLACE - primitive colour completely replaced with texture.



GL_MODULATE - primitive colour multiplied by fragment colour.

Texture coordinates

(s,t) with s and t between 0 and 1. Corresponding to the coordinates of the image ( (0,0) in bottom left)

Texture Tiling

When setting wrap parameters for s or t:



If GL_CLAMP set, texture coordinate values over 1 are treated as 1 (so you get a stretchy look after the initial image).



If GL_REPEAT set values over 1 are taken mod 1 so the image repeats like a tile.

Texel

The pixel value of a texture.

Texture Magnification/Minification

When mapping a small texture to a larger polygon (magnification) or a large texture to a smaller polygon (minification):



GL_NEAREST sets each pixel to get the colour of the texel value closest to the centre of the pixel (more blocky).



GL_LINEAR sets the pixel value to be the weighted average of the 4 texel values closest to the centre of the pixel (more blurry).

Mipmaps

Thin lines often disappear during minification.



Mipmap = a set of prefiltered versions of the same image at different scales (resolutions).



Requires extra processing and texture storage space but reduces aliasing effects as different images can be used in different scenarios.

Angle between vectors (and obtuse Vs acute(

cos(theta) = v1•v2 / ||v1||•||v2||



If cos(theta) > 0, acute


If cos(theta) < 0, obtuse

Surface normal at vertex

Take cross product of 2 vectors going to adjacent vertices.

Translation matrix

Scale Matrix

Affine Transformation

A general linear transformation followed by a translation. Examples: translation, rotation, scaling, shear transformations.



Under affine transformations, line segments transform into line segments and parallel lines transform into parallel lines.



Linear Interpolation

Interpolate some value v between end points v1 and V2:



V = (1-t)v1 + tv2

Bilinear Interpolation

Given values of an attribute at vertices of a triangle, we want to obtain values at interior points. For triangle vertices A,B,C:



Compute:



D = (1-t)A + tB


E = (1-t)A + tC



Then bilinearly interpolated value is:



F = (1-s)D + sE



Phong Blinn Illumination Model

Halfway vector and it's advantages

h = (l + v) normalised.



If theta is angle between r and v and beta is angle between h and n they are correlated and 0 at the same time. So OpenGL uses h•n to approximate r•v in specular lighting calculations.



Advantages:



Easier to compute h than r



If l is directional source and view direction is constant, h only needs to be computed once for the whole scene.

Local / Global Illumination

Local Illumination: considers only light traveling from a light source to a surface, reflected to the eye. Does not consider occlusions and transmittance of light.



Global illumination: illumination at a given point is a combination of the light received from a source and the light reflected from other surfaces in the scene.

Ray Tracing

Generate a 2D image pixel by pixel by computing the colour cake of each pixel via rays generated from the eye position through the degree of the pixel.



Along each primary ray calculate the closest point of intersection (if none assign background colour), then use secondary rats to model shadows, reflections, refractions to return overall colour.

Ray

Specified by a point p (source of ray) and a unit vector d (direction of ray) with ray parameter t.




Ray's equation: p = p0 + td

Ray Casting

Use only primary rays, and material colour at point of intersection.



With no lighting, looks 2D.



With Phong illumination, gain specular highlights, diffuse lighting, but no reflections, refraction etc.

OpenGL 4 Motivation

The ability to program graphics hardware allows a wider range of rendering effects that give optional performance.



Developers have more freedom to define actions to be taken at each stage of processing.

OpenGL 4 Programmable Pipeline overview

Program and memory (eg vertex data) does in CPU. Shaders in GPU.



Application sends vertex data, transformation matrices to vertex shader which does transformation and lighting calcs. It outputs vertices in clip coordinates to fragment shader, application sends image/texture pixel values to fragment shader. Fragment shader outputs colour after texturing, interpolation etc.

OpenGL4 Shader Stages

Vertex shader -> tessellation control shader -> primitive generator -> tessellation evaluation shader -> geometry shader -> primitive assembly, clipping, viewport transformation -> rasterization -> fragment shader -> fragment tests -> frame buffer

Vertex Buffer Objects

Represents the data (coords, colour, normal) for a particular vertex attribute in video memory. Stored in a vertex array object which encapsulates all vertex data.



To create a vbo, generate a new buffer object, bind buffer object to target, copy vertex data to buffer.



To create a vao, generate new vertex array object, bind it (initially empty), create constituent vbo's and transfer data.

Vertex Shader

Executed once per vertex (multiple in parallel).



Position, normal, colour, texture coordinates etc of current vertex available in shader. Positions and attributes of other vertices not available.



Vertex shader outputs the clip coordinates of the current vertex, performs lighting calculations.



gl_Position is built in out variable for vertex shader, must be defined. Per vertex colour outputs are optional.

Rasterization

Process of scan converting a primitive into a set of fragments.



A fragment is a pixel sized element that belongs to a primitive and could potentially be displayed as a pixel. Num of generated fragments depends on projected area of the primitive in the screen coordinate space.

Fragment Shader

Gets values from previous stage, not VBO.



Executed once per fragment generated by the rasterizer. Outputs colour of fragment and optionally the depth value. Colour computations such as texture mapping, depth offsets etc can be performed. Can also discard a fragment.



Built in variables gl_FragCoord, gl_FragColor, gl_FragDepth

Uniform Variables

Mechanism for transferring matrices and other values from application to shader.

Important Matrices

Model View Matrix (VM) - product of view matrix and transformation matrices, converts view coordinates into eye coordinates to do lighting calculations (easier in this coordinate system since camera is at the origin).



Model View Projection Matrix (PVM) - product of Model View Matrix and projection matrix, converts view coordinates to clip coordinates.



Both sent to shaders.




Clip coordinate = projection matrix * view matrix * transformation matrix * world coordinate

Transformation of a Normal Vector

If points are transformed by a matrix A, the normal vectors must be transformed by



(A^T)^-1



To remain normal to the transposed surface.

Parametric Domain Definition and 2D Types

A space defined by a regular shape, within which points are specified using parametric values between 0 and 1.



Types:



Quad domain - a unit square.



Triangle domain - given in barycentric coordinates, (u,v,w).

Mapping Parametric Domain to a General shape in 3D space (both quad and triangle)

Quad: Use bilinear Interpolation formula:



Q = (1-v)((1-u)P0 + uP1) + v((1-u)P3 + uP4)



Triangle: use barycentric mapping:



Q = uP0 + vP1 + wP2

Tessellating Parametric Domains - why and details

Tesselating arbitrary shapes hard, easier to tessellate eg a square and map it into a general quad. (u,v) or (u,v,w) called tessellation coordinates.

Tesselation Levels

Outer tesselating levels specify the number of subdivisions on the edges of the domain.



Inner tesselation levels specify the minimum number of subdivisions from one side to the other.



For a quad : two inner levels, horizontal and vertical.


For a triangle : one inner level for all 3 directions.



Quad specified by ooooii


Triangle specified by ooo0i0 (extra gap filled with 0 for both outer and inner).

Tesselation Control Shader


Tesselation control shader receives patch vertices (gl_in), specifies outer and inner tesselation levels and can modify patch vertices if needed. Generally we use this to add higher levels of detail to objects closer to the camera (higher tesselation levels). We theoretically could just leave it as a pass through shader to have everything in the same detail.


GL_PATCHES

A patch is an ordered list of vertices. It is not a renderable primitive so the vertex shader doesn't convert patch vertices to clip coordinates. GL_PATCHES must be passed to the vertex shader if the tesselation stage is active.

gl_in

The built in array variable through which the shader accesses the patch vertices.

Primitive Generator

Primitive generator outputs triangles of the tessellated mesh with vertices in tesselation coordinates. These triangles form tessellations of square or triangle domains. Vertices of each triangle will have normalised coordinates.



These are sent to the evaluation shader.

Tesselation Evaluation Shader

Tesselation evaluator specifies blending functions and combines patch vertices with tesselation coordinates to position vertices of the generated mesh on the patch. It converts 2D primitive vertices (u,v) to 3D points in clip coordinates.

Vertex shader if tesselation or geometry stages on

Just a pass through shader

Geometry shader overall ideas

Receives input from TES or vertex shader if tesselation not active. Input is primitives with vertices stored in an array, geometry shader runs once per entire primitive (has much more information than eg a vertex shader).



The shader can change the type of input primitive and the number of vertices or discard primitives. It can output values into multiple streams.



It outputs each vertex in clip coordinates using the built in gl_position variable.

Geometry shader input and output types, built in output functions

INPUT: Any primitives: points, lines, line strip, triangles, quads etc. Also GL_TRIANGLES_ADJACENCY.



OUTPUT: points, line strip or triangle strip (triangles and quads are special cases of triangle strips).



Outputs vertices using built in function EmitVertex(). End whole primitive with EndPrimitive(). If shader exits without emitting a vertex then it does not produce any output primitive.

Adjacency Primitives

GL_LINES_ADJACENCY: 4 vertices per primitive, 2nd and 3rd form current line, other two are just tested as adjacent.



GL_TRIANGLES_ADJACENCY: 6 vertices per primitive. 1st, 3rd and 5th form current triangle.



When adjacency primitive is drawn without geometry shader only current primitive vertices are drawn and the others discarded.



If geometry shader is active it gets all vertices of adjacency primitive in gl_in[].gl_position array. It can modify attributes of the current triangle or generate additional primitives using information about adjacent triangles.

Geometry culling

Shader can discard a primitive as a whole.

Geometry amplification

Example:



The application generates a 2D strip line, geometry shader receives individual lines of the strip (X1,y1), (X2,y2) and outputs Triangles strip for each line received.



When done on repeat could create eg a volume of revolution.

Uses of geometry shader

More complex lighting/texture calculations than previously possible due to being able to work with whole primitive at once and having neighbouring vertex info.



Eg can be used for lighting and height based texture mapping in terrain construction.

Terrain Construction Stages

Construct terrain base (application).


Tesselate the base to the required level (control shader).


Reposition (u,v) using patch coordinates (evaluation shader).


Use height map to modify vertices of the tessellated mesh (evaluation shader).


Perform lighting computation and height based texture mapping (geometry shader).

List 2 Uses of Vertex Shader

Transformation - position vectors from world to clip coordinates via MVP matrix.



Lighting - position and normal vectors from world to eye coordinates via MV and normal matrices.

List 2 Uses of Tesselation Control Shader

Specify Inner and Outer Tessellation levels.



Modify patch vertices if necessary.

Specify purpose of primitive generator

Output mesh of triangle primitives in tessellation coordinates determined by the specified tessellation levels.

List 2 Uses of Tesselation evaluation shader

Reposition each mesh vertex in (u,v) tessellation coordinates using patch vertices.



Output vertex positions in clip coordinates. (Or world sometimes).

List uses of geometry shader

Geometry culling - discard primitives, eg if not in view.


Perform lighting/texture calculations.


Output multiple primitives in different streams if needed (eg for geometry amplification).

List 3 uses of fragment shader

Perform lighting and texturing calculations for each fragment by interpolating vertex values.


Perform optional depth calculations.


Optionally discard fragments if needed.

Conditions for being in shadow

Distance to object is less than distance to light on secondary ray. t value is positive.