12
1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection

1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection

Embed Size (px)

DESCRIPTION

3 Perspective Normalization Consider a perspective projection where the viewing angle is 90 deg and the focal distance is 1. x z x = z x = -z Clipping Volume enclosed by: x = +/- z, y = +/- z, z min < z < z max

Citation preview

Page 1: 1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection

1

Graphics

CSCI 343, Fall 2015Lecture 18

Viewing III--More Projection

Page 2: 1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection

2

Orthographic and Oblique projections

Orthographic Projection:1) Translate clipping volume to origin2) Scale sides of clipping volume to be 2x2x2

M = MORTHOST

Oblique Projection:1) Shear clipping volume to be rectangular box.2) Translate to origin3) Scale sides to 2x2x2

M = MORTHOSTH

Page 3: 1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection

3

Perspective NormalizationConsider a perspective projection where the viewing angle is 90 deg and the focal distance is 1.

-1

x

z

x = z

x = -z

Clipping Volume enclosed by:x = +/- z, y = +/- z, zmin < z < zmax

Page 4: 1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection

4

Splitting the projection matrixTo fit this in the canonical volume, we want to find a matrix, N, such that:

PPROJ = MORTHN

We know that we will have to translate along the Z axis and scale the Z components. Try the following:

Page 5: 1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection

5

Fitting the canonical volumeAt x = -z, x'' = (-(-z/z)) = 1At x = z, x'' = (-z/z) = -1

Sides of canonical volume

The same is true for y.

For zmax and zmin:zmin'' = -( + /zmin) = -1zmax'' = -( + /zmax) = +1

Solve for and :

Page 6: 1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection

6

Scaling the X and Y edgesIf the perspective projection does not have a 90 deg viewing angle: We must first scale x and y so the sides are at x = +/-z, y=+/-z

x

z(xmin, zmax)

(xmax, zmax)

PPROJ = MORTHNS

S = ?

Page 7: 1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection

7

Dealing with a non-centered clipping volume

If the frustum that defines the clipping volume is not a right frustum (i.e. the near and far planes are not centered on the Z axis), we must first Shear the clipping volume to center these.

z(xmin, zmax)

(xmax, zmax)

Shear along x:

Shear along y:

x

Page 8: 1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection

8

The Shear Matrix

Note that this matrix transforms the center point:

to

Full Perspective Projection:P = MORTHONSH

Page 9: 1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection

9

Projections and ShadowsIn simple situations we can generate shadows with a projection trick.

Suppose we have a light source at (xa, ya, za)The "shadow" of a polygon is its projection onto the x,z plane.

(xa, ya, za)

z

x

y

Page 10: 1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection

10

Projecting a shadow1. Translate the image so that the light source is at the origin.

T(-xa, -ya, -za)1. Compute the projection along the Y axis, with the focal

distance equal to -ya.2. Translate back to the original position: T(xa, ya, za)

Step 2: Projection Matrix:

z

x

y

-ya

Page 11: 1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection

Shadow projection in OpenGLSetting up the matrix, M: light = vec3(0.0, 2.0, 0.0); m = mat4(); m[3][3] = 0; m[3][1] = -1/light[1];

Rendering a square: // model-view matrix for square modelViewMatrix = mat4( );modelViewMatrix = mult(modelViewMatrix, rotate(30.0, 1.0, 0.0, 0.0)); // send color and matrix for square then render gl.uniformMatrix4fv( modelViewMatrixLoc, false,

flatten(modelViewMatrix) );gl.uniform4fv(fColor, flatten(red));gl.drawArrays(gl.TRIANGLE_FAN, 0, 4);

Page 12: 1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection

Drawing the shadow// rotate light source light[0] = Math.sin(theta);light[2] = Math.cos(theta); // model-view matrix for shadow then rendermodelViewMatrix = mult(modelViewMatrix,

translate(light[0], light[1], light[2]));modelViewMatrix = mult(modelViewMatrix, m);modelViewMatrix = mult(modelViewMatrix,

translate(-light[0], -light[1], -light[2]));// send color and matrix for shadow gl.uniformMatrix4fv( modelViewMatrixLoc, false,

flatten(modelViewMatrix) );gl.uniform4fv(fColor, flatten(black));gl.drawArrays(gl.TRIANGLE_FAN, 0, 4);