1 of 30

���Chapter V�Vertex Processing

All class materials including this PowerPoint file are available at

https://github.com/medialab-ku/openGLESbook

Introduction to Computer Graphics with OpenGL ES (J. Han)

2 of 30

GPU Rendering Pipeline

5-2

  • In GPU, rendering is done in a pipeline architecture.

  • It is composed of programmable stages and hard-wired stages.
    • A shader is a synonym of a program. We have to provide the pipeline with two programs, i.e., vertex shader and fragment shader.
    • In contrast, the rasterizer and output merger are hard-wired stages that perform fixed functions.

Introduction to Computer Graphics with OpenGL ES (J. Han)

3 of 30

GPU Rendering Pipeline

5-3

  • When rendered, each triangle of a polygon mesh occupies a set of pixels in the screen. Before determining the pixels’ colors, a fragment is defined for each pixel location. It refers to a set of data used to determine the pixel’s color.
  • Rendering pipeline

    • The vertex shader performs various operations, such as world transform, on every input vertex stored in the vertex array.
    • The rasterizer assembles triangles from the vertices and converts each triangle into fragments.
    • The fragment shader computes the fragment color.
    • The output merger uses the fragment color to determine the pixel color.

Introduction to Computer Graphics with OpenGL ES (J. Han)

4 of 30

GPU Rendering Pipeline (cont’d)

5-4

  • Among the operations performed by the vertex shader, the most essential is applying a series of transforms to the vertex.

  • We’ve learned the world transform in Chapter 4.

Introduction to Computer Graphics with OpenGL ES (J. Han)

5 of 30

World Transform for Normals

5-5

  • Previously, the world transform was applied to vertex positions in the vertex array. How about vertex normals?
  • For now, consider triangle normals.
  • If the world transform is in [L|t], the normals are affected only by L, not by t.
  • Suppose that L includes a non-uniform scaling. In the example shown below, where the red line segment represents the cross-section of a triangle, the normal scaled by L is not any longer orthogonal to the triangle scaled by L.

Introduction to Computer Graphics with OpenGL ES (J. Han)

6 of 30

World Transform for Normals (cont’d)

5-6

  • In order to make the normal always orthogonal to the triangle, we use the inverse transpose of L, i.e., (L-1)T, which is simply denoted by L-T.

  • If L does not contain any non-uniform scaling, n can be transformed by L. Then, Ln has the same direction as L-Tn even though their magnitudes may be different. For the sake of algorithmic simplicity, we transform n consistently by L-T regardless of whether L contains a non-uniform scaling or not.
  • The vertex normals stored in the vertex array are transformed by L-T.
  • The normals transformed by L-T will be finally normalized.

Introduction to Computer Graphics with OpenGL ES (J. Han)

7 of 30

Camera Pose and Camera Space

5-7

  • A virtual camera is used to capture the world space. Depending on its poses, different images are captured.
  • OpenGL convention for specifying the camera pose (position + orientation)
    • EYE: camera position
    • AT: a reference point toward which the camera is aimed
    • UP: view up vector that describes where the top of the camera is pointing. (In most cases, UP is set to the vertical axis, y-axis, of the world space.)

Introduction to Computer Graphics with OpenGL ES (J. Han)

8 of 30

Camera Pose and Camera Space (cont’d)

5-8

 

Introduction to Computer Graphics with OpenGL ES (J. Han)

9 of 30

Camera Pose and Camera Space (cont’d)

5-9

  • In Unity, the camera pose is specified using the so-called gizmo.
    • The circular gizmo is for object-space Euler transform.
    • It is converted into the world-space Euler transform and the Euler angles are shown in the Inspector’s Rotation.

camera pose

Introduction to Computer Graphics with OpenGL ES (J. Han)

10 of 30

Camera Space and View Transform

5-10

  • Note that a point is given different coordinates in distinct spaces.

  • If all WS objects can be newly defined with respect to CS in the manner of the teapot’s mouth end, it becomes much easier to develop the rendering algorithms.
  • The space change from the WS, {O, e1, e2, e3}, to the CS, {EYE, u, v, n}, is handled by the view transform, also called camera transform.

Introduction to Computer Graphics with OpenGL ES (J. Han)

11 of 30

Camera Space and View Transform (cont’d)

5-11

 

 

 

 

 

 

 

view transform

Introduction to Computer Graphics with OpenGL ES (J. Han)

12 of 30

Camera Pose Specification in Unity

5-12

  • In the previous example, we translate the camera first, and then rotate it. However, the rotation is an object-space Euler transform.

  • It implies that the rotation can be thought as if it’s made before translation, i.e., rotation first and then translation. Then, we (1) convert it into the world-space Euler transform (Rotation in the Inspector), (2) compute its 3×3 matrix, and (3) take it as R for the view matrix, [R|t].
  • In Unity, the world-space Euler angles are taken in the order of θz, θx and θy. Take a closer look at the Inspection window to find that Rotation’s X remains fixed while Rotation’s Z is changing.
  • Taking the camera’s position (Position in the Inspector) as EYE and using R, compute t for [R|t], as given in the definition of Mview.

Introduction to Computer Graphics with OpenGL ES (J. Han)

13 of 30

Right-hand System vs. Left-hand System

5-13

  • Right-hand system vs. left-hand system

Introduction to Computer Graphics with OpenGL ES (J. Han)

14 of 30

Right-hand System vs. Left-hand System (cont’d)

5-14

  • In LHS as well as in RHS, the rotation angle is positive if the rotation is made along the curling direction of the four fingers. Otherwise, negative.

Introduction to Computer Graphics with OpenGL ES (J. Han)

15 of 30

Right-hand System vs. Left-hand System (cont’d)

5-15

  • An inconsistency is observed if an object defined in the RHS is ported to the LHS as is together with the same camera parameters.

Introduction to Computer Graphics with OpenGL ES (J. Han)

16 of 30

Right-hand System vs. Left-hand System (cont’d)

5-16

  • In order to avoid the reflected image shown in the previous page, the z-coordinates of both the objects and view parameters should be negated.

  • Note that z-negation is conceptually equivalent to the z-axis inversion.

Introduction to Computer Graphics with OpenGL ES (J. Han)

17 of 30

View Frustum

5-17

  • Let us denote the camera-space axes by {x, y, z} instead of using {u, v, n}.

  • The camera pose,{EYE, u, v, n}, defined the external parameters of the camera. Now let’s define its internals. It is analogous to choosing a lens and controlling zoom-in and -out.
  • An infinite pyramid is defined by fovy and aspect. Its apex is at the origin and axis is the –z axis.

Introduction to Computer Graphics with OpenGL ES (J. Han)

18 of 30

View Frustum (cont’d)

5-18

  • Then, n and f, which stand for the distances to the near and far planes respectively, define a truncated pyramid. It’s called view frustum.

  • The near and far planes run counter to the real-world camera or human vision system but have been introduced for the sake of computational efficiency.

Introduction to Computer Graphics with OpenGL ES (J. Han)

19 of 30

View Frustum (cont’d)

5-19

  • In our example, the cylinder and sphere would be discarded by the so-called view-frustum culling whereas the teapot would survive. View-frustum culling that is implemented on CPU has been studied for a long time, and there exist good algorithms.
  • Only the teapot will proceed to the GPU rendering pipeline.
  • If a polygon intersects the boundary of the view frustum, it is clipped with respect to the boundary, and only the portion inside the view frustum is processed for display.

Introduction to Computer Graphics with OpenGL ES (J. Han)

20 of 30

View Frustum in Unity

5-20

Introduction to Computer Graphics with OpenGL ES (J. Han)

21 of 30

View Frustum in Unity (cont’d)�

5-21

  • Unity Esset “Gurbu”

Introduction to Computer Graphics with OpenGL ES (J. Han)

22 of 30

Projection Transform

5-22

  • The pyramidal view frustum is not used for clipping. Instead, a transform is developed to deform the view frustum into the axis-aligned 2×2×2-sized cube centered at the origin. It is called projection transform. The camera-space objects are projection-transformed and then clipped against the cube.

  • The projection-transformed objects are said to be in the clip space.

Introduction to Computer Graphics with OpenGL ES (J. Han)

23 of 30

Projection Transform (cont’d)

5-23

  • In the pin-hole camera model, the 3D object in the world space is projected to the 2D projection plane or image plane. Specifically, the world-space point q is projected to p in the image plane.
  • In computer graphics, reducing the camera to a point at the center of projection (COP), we can think of the virtual image plane using the same focal length.

q

p

p

(COP)

Introduction to Computer Graphics with OpenGL ES (J. Han)

24 of 30

Projection Transform (cont’d)

5-24

  • The view frustum is taken as a convergent pencil of projection lines. The lines converge on the origin, COP, where the virtual camera (EYE) is located.
  • All 3D points on a projection line are mapped onto a single 2D point in the projected image. It brings the effect of perspective projection, where objects farther away look smaller.

  • The projection transform ensures that the projection lines become parallel to the z-axis. Now viewing is done along the universal projection line with the camera located infinitely far away. The projection transform brings the effect of perspective projection “within a 3D space.”

image

plane

or

COP

Introduction to Computer Graphics with OpenGL ES (J. Han)

25 of 30

Projection Transform (cont’d)

5-25

  • Projection transform matrix (Its derivation is presented in the textbook).

Introduction to Computer Graphics with OpenGL ES (J. Han)

26 of 30

Projection Transform (cont’d)

5-26

  • Projection transform matrix

  • The projection-transformed objects will enter the rasterizer.
  • Unlike the vertex shader, the rasterizer is implemented in hardware, and it assumes that the clip space is left-handed. In order for the vertex shader to be compatible with the hard-wired rasterizer, the objects should be z-negated.

Introduction to Computer Graphics with OpenGL ES (J. Han)

27 of 30

Projection Transform (cont’d)

5-27

  • Projection transform from the camera space (RHS) to the clip space (LHS)

  • Note that the cube (equivalently, the corner points, (1,1,-1) and (-1,-1,1)) is not obtained by the projection transform only, which produces 4D homogeneous coordinates. Only after they are converted into Cartesian coordinates (via division by w), the cube is obtained. This will be clarified in Chapter 7.

Introduction to Computer Graphics with OpenGL ES (J. Han)

28 of 30

Saved

5-28

Introduction to Computer Graphics with OpenGL ES (J. Han)

29 of 30

Camera Pose and View Transform (cont’d)

29

 

 

 

 

 

 

Introduction to Computer Graphics with OpenGL ES (J. Han)

30 of 30

Camera Pose and View Transform (cont’d)

30

 

Introduction to Computer Graphics with OpenGL ES (J. Han)