21
Computer Graphics Visible Surface Determination

Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Embed Size (px)

Citation preview

Page 1: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Computer Graphics

Visible Surface Determination

Page 2: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Goal of Visible Surface Determination

To draw only the surfaces (triangles) that are visible, given a view point and a view direction

Page 3: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Three reasons to not draw something

• 1. It isn’t in the view frustum

• 2. It is “back facing”

• 3. Something is in front of it (occlusion)

• We need to do this computation quickly. How quickly?

Page 4: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Surface Normal

• Surface Normal - vector perpendicular to the surface

• Three non-collinear points (that make up a triangle), also describes a plane. The normal is the vector perpendicular to this plane.

Page 5: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

What do the normals tell us?

Q: How can we use normals to tell us which “face” of a triangle we see?

Page 6: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Examine the angle between the normal and the view direction

V

N

Front if V . N <0

Page 7: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Backface Culling

•Before scan converting a triangle, determine if it is facing you

•Compute the dot product between the view vector (V) and triangle normal (N)

•Simplify this to examining only the z component of the normal

•If Nz<0 then it is a front facing triangle, and you should scan convert it

•What surface visibility problems does this solve? Not solve?

•Review OpenGL code

Page 8: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Multiple Objects

• If we want to draw: We can sort in z. What are the advantages? Disadvantages?

Called Painter’s Algorithm or splatting.

Page 9: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Painter’s Algorithm Subtleties

• What do we mean sort in z? That is for a triangle, what is its representative z value?– Minimum z– Maximum z– Polygon’s centroid

• Work cost = sort + draw• We still use Painter’s Algorithms for blended objects

(discussed in the Blending Lesson)• An object space visibility algorithm

Page 10: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Side View

Page 11: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Even Worse… Why?

Page 12: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Depth Buffers

Goal: We want to only draw something if it appears in front of what is already drawn.

What does this require? Can we do this on a per object basis?

Page 13: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Depth Buffers

We can’t do it object based, it must be image based.

What do we know about the x,y,z points where the objects overlap?

Remember our “eye” or “camera” is at the origin of our view coordinates.

What does that mean need to store?

Page 14: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Side View

Page 15: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Algorithm

• We need to have an additional value for each pixel that stores the depth value.

• What is the data type for the depth value?

• How much memory does this require?

• Playstation 1 had 2 MB.

• The first commercial 512 x 512 framebuffer cost $15,000

• Called Depth Buffering or Z buffering

Page 16: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Depth Buffer Algorithm

• Begin frame– Clear color

– Clear depth to z = zmax

• Draw Triangles– When scan converting znew pixel < zvalue at the pixel, set color and

zvalue at the pixel = znew pixel

– What does it mean if znew pixel > zvalue at the pixel?

– Why do we clear the depth buffer?– Now we see why it is sometimes called the z buffer

Page 17: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Computing the znew pixel

• Q: We can compute the znsc at the vertices, but what is the znsc as we scan convert?

• A: We interpolate znsc while we scan convert too!

Page 18: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Z Buffer Precision

• What does the # of bits for a depth buffer element mean?

• The z from eye space to normalized screen space is not linear. That is we do not have the same precision across z. (we divided by z).

• In fact, half of our precision is in z=0 and z=0.5. What does this mean? What happens if we do NOT have enough precision?

Page 19: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Z Fighting

• If we do not have enough precision in the depth buffer, we can not determine which fragment should be “in front”.

• What does this mean for the near and far plane?

We want them to as closely approximate our volume

Page 20: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Z Fighting Zoomed In

Run Demo

Page 21: Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a

Depth Buffer Algorithm

• Pros:– Easy to understand and

implement

– per pixel “correct” answer

– no preprocess

– draw objects in any order

– no need to redivide objects

• Cons:– Z precision

– additional memory

– Z fighting