Tải bản đầy đủ (.pdf) (40 trang)

Lecture computer graphics and virtual reality slides lesson 11 hidden surface removal

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.13 MB, 40 trang )

Lesson 11

Hidden surface
removal

Trinh Thanh Trung School of ICT, HUST

Content

1. Overview
2. Painter’s algorithm
3. Z-buffer
4. BSP tree
5. Portal culling
6. Additional techniques

1.
Overview

Why hidden surface removal

■ A correct rendering requires correct visibility
calculations
■ When multiple opaque polygons cover the same
screen space, only the closest one is visible (remove
the other hidden surfaces)

wrong visibility correct visibility

Why hidden surface removal


■ We don’t want to waste computational
resources rendering primitives which don’t
contribute to the final image
■ Drawing polygonal faces on screen consumes
CPU cycles

□ e.g. Illumination

Hidden surface removal

■ Painter’s algorithm
■ Z-buffer
■ BSP tree
■ Portal culling
■ Additional techniques

□ Back face culling

2.
Painter’s algorithm

Painter’s algorithm

■ Draw surfaces in back to front order – nearer
polygons “paint” over farther ones.
■ Need to decide the order to draw – far objects
first

Painter’s algorithm: Problem


■ Key issue is order
determination.
■ Doesn’t always work

□ see image at right

Painter’s algorithm: Problem

■ Another situation it
■ does not work
■ In both cases, we
need to segment the
triangles and make
them sortable

3.
Z Buffer

Z-Buffer

■ An image-based method applied during the
rasterization stage
■ A standard approach implemented in most
graphics libraries
■ Easy to be implemented on hardware
■ By Wolfgang Straßer in 1974

Z-Buffer

■ Basic Z-buffer idea:

■ For every input polygon

□ For every pixel in the polygon interior, calculate its
corresponding z value (by interpolation)

□ Compare the depth value with the closest value
from a different polygon (largest z) so far

□ Paint the pixel with the color of the polygon if it is
closer

Z-Buffer example

−1.0 −1.0 −1.0 −1.0
−1.0 −1.0 −1.0 −1.0
−1.0 −1.0 −1.0 −1.0
−1.0 −1.0 −1.0 −1.0

Step 1: Initialise the depth buffer

Step 2: Draw the blue polygon (order
does not affect the final result)

Step 2: Draw the yellow polygon

- If the depth value is greater than corresponding value in z-buffer,
that pixel is coloured and the value in z-buffer will be updated

Step 2: Draw the red polygon


- Similarly, if the depth value is greater than corresponding value
in z-buffer, that pixel is coloured and the value in z-buffer will be

Advantages

■ Simple to implement in hardware.

□ Memory for z-buffer is now not expensive

■ Diversity of primitives – not just polygons.
■ Unlimited scene complexity
■ No need to sort the objects
■ No need to calculate object-object intersections

Disadvantages

■ Waste time drawing hidden objects
■ Z-precision errors (aliasing problems)

■ See this example Too many polygons behind walls


×