Está en la página 1de 8

Computer Graphics Hidden Lines

So far our treatment has concerned only points and


Lecture 5: lines.

Towards Solid objects: This has utility in some applications, but for anything
Hidden Surfaces and Texture mapping of complexity wire frame representations become
confusing.

We need to eliminate the hidden parts of the picture

Graphics Lecture 5: Slide 1 Graphics Lecture 5: Slide 2

Types of Visibility Methods Back Face Culling

Polygons should be ordered in a consistent manner


• Back-face culling (clockwise or counter clockwise)
• Ordering in object space Polygons whose normal does not face the viewpoint,
• Depth sort are not rendered
• Painter’s algorithm
• Ordering in projection space
Pi+2
• Ordering in image space Pi
• Z-buffer
• Ray casting

Pi+1
Graphics Lecture 5: Slide 3 Graphics Lecture 5: Slide 4

Back Face Culling Back Face Culling

Polygons should be ordered in a consistent manner Polygons whose normal is pointing away from the
(clockwise or counter clockwise) viewer can be culled. If α is the angle between the
Polygons whose normal does not face the viewpoint, normal and the viewer the polygon is front facing if
are not rendered
-90 < α < 90 or cos α > 90

Pi Alternatively we can test for

n·v>0
Pi+1
Graphics Lecture 5: Slide 5 Graphics Lecture 5: Slide 6

1
Back Face Culling Types of Visibility Methods

Alternatively, think about back projection space


The transformed polygon must have a normal with a • Back-face culling
negative z component to be visible • Ordering in object space
• Depth sort
V • Painter’s algorithm
+1 • Ordering in projection space
DOP
• Ordering in image space
O
N
• Z-buffer
• Ray casting
-1

Graphics Lecture 5: Slide 7 Graphics Lecture 5: Slide 8

The Painter’s Algorithm The Painter’s Algorithm

Suppose we take each face of our wire frame and Polygons are rendered in depth order
draw it in two dimensions as a filled polygon.
5th
By filling it we hide anything behind it.
4th 1st 3rd
So, if we draw the furthest parts first then the hidden
parts of the scene are automatically eliminated
2nd

Graphics Lecture 5: Slide 9 Graphics Lecture 5: Slide 10

The Painter’s Algorithm Depth-sort

Changing the order changes the result

1st

3rd 2nd
5th

4th
Note that two polygons P and Q can be rendered in
any order, if they do not overlap in X-Y
P can be rendered before Q if its P’s z range is
completely behind Q’s
Graphics Lecture 5: Slide 11 Graphics Lecture 5: Slide 12

2
Depth-sort Types of Visibility Methods

P can be rendered before Q if


• Z-extent of Q is wholly in front of P or • Back-face culling
• Y-extent of Q does not overlap P or • Ordering in object space
• X-extent of Q does not overlap P or • Depth sort
• All points on P lie on the opposite side of Q than the centre • Painter’s algorithm
of projection (COP) or
• Ordering in projection space
• All points on Q lie on the same side of P as the COP or
• Ordering in image space
• The projections of P and Q on the XY plane do not overlap
• Z-buffer
• Ray casting

Graphics Lecture 5: Slide 13 Graphics Lecture 5: Slide 14

The Z-Buffer The Z-Buffer again

The painter’s algorithm requires the objects to be When we render a new polygon we check at each
sorted into depth order. pixel to see whether it is nearer or further than the
object currently drawn at that pixel.
A Z-Buffer algorithm is similar, but avoids sorting.
We only set the pixel if the polygon is closer.
Every time we set a pixel in our image we record in a
separate array (the z-buffer) the 3D z co-ordinate at A further advantage of the z-buffer is that it can be
that pixel. simply implemented in hardware

Graphics Lecture 5: Slide 15 Graphics Lecture 5: Slide 16

The Z-Buffer Interpolating Depth

• Most common usage is a a full window sized array of Interpolate z along edges AND interpolate between
size m x n of 16, 24 or 32 bit “depth” values. edges on each scan-line (bi-linear interpolation)
• Basic idea:
• Initialise buffer to Z_MAX
• For each pixel in each polygon
• If z < ZBUF[x,y] set CBUF[x,y] = col (X2,Y2,Z2)

• Now we have to write a z-value for each point


• directly from plane equation (re-calculate for each point) (XL,YL,ZL) (XR,YR,ZR)

• incremental across the scan-line (store z_start and dz)


z r − zl
• interpolate … (X1,Y1,Z1) dz =
xr − xl
Graphics Lecture 5: Slide 17 Graphics Lecture 5: Slide 18

3
Texture

The visual appearance of a graphics scene can be


greatly enhanced by the use of texture.

Consider a brick building, using a polygon for every


brick require a huge effort in scene design.

So why not use one polygon and draw a repeating


brick pattern onto it?

Graphics Lecture 5: Slide 19 Graphics Lecture 5: Slide 20

Texture Mapping Texture Mapping

Graphics Lecture 5: Slide 21 Graphics Lecture 5: Slide 22

Texture Mapping Texture Definition

Textures may be defined as:

Bitmaps - Arrays containing the actual pixel values to be


mapped to the polygon. The data can be derived from
photographs for example.

Procedures - Suitable for repeating patterns.

Graphics Lecture 5: Slide 23 Graphics Lecture 5: Slide 24

4
Textures need not map exactly to polygons. They Mapping texture to individual pixels
can be smaller or larger than the polygon
P3

P2 Diagram 7.2
Texture Definition Space Texture applied to a polygon Bi-linear texture
β e
map
c
b
p
1.5β
Polygon being
β
textured
a
α 2α P4
P1 α

Graphics Lecture 5: Slide 25 Graphics Lecture 5: Slide 26

Bi-linear Map - Solving for α and β Non Linearities in texture mapping

The second order term means that straight lines in the


P3
texture may become curved when the texture is
p = αa + βe mapped.
P2
e = b + α(c - b) e
c
so b However, if the mapping is to a parallelogram:
p
p = αa + βb + αβ(c-b) β p = αa + βb + αβ(c-b)
a
P4 and
Its Quadratic ! P1 α
b=c
so p = αa + βb

Graphics Lecture 5: Slide 27 Graphics Lecture 5: Slide 28

Photographs as Textures Alias Effects

Photographs can be used to enhance reality with One major problem with texture mapping is called
virtually no design effort. alias effects.

For a flight simulator landing at an airport the distant These are caused by undersampling, and can cause
landscape can be presented as a photograph which unreal visual artefacts.
forms the back clipping plane

Graphics Lecture 5: Slide 29 Graphics Lecture 5: Slide 30

5
Appearance of the textured
polygon in the image
Texture Alias effects in static images

Aliases appear in untextured static images as well.

Polygon width
They have the characteristic of making straight line
12 Pixels boundaries look jagged.
6 Pixels
4 Pixels
3 Pixels
This is also due to undersampling.
Samples

Diagram 7.3
Alias Effects in Texture Mapping
Graphics Lecture 5: Slide 31 Graphics Lecture 5: Slide 32

Alias Effects at straight boundaries in raster Anti-Aliasing


images.
The solution to aliasing problems is to apply a degree
of blurring to the boundary such that the effect is
reduced.

The most successful technique is called


Supersampling
Desired Boundaries Pixels Set

Graphics Lecture 5: Slide 33 Graphics Lecture 5: Slide 34

Supersampling

The basic idea is to compute the picture at a higher (13/16)I2 + (3/16)I1


resolution to that of the display area. I2 Polygon Boundary (3/16)I2 + (13/16)I1

I1 Solid lines are


Then the supersamples are averaged to find the pixel pixel boundaries

value. Dashed lines are Actual Pixel


supersamples I1 I1 Intensities

This has the effect of blurring boundaries, but leaving


coherent areas of colour unchanged

Graphics Lecture 5: Slide 35 Graphics Lecture 5: Slide 36

6
Limitations of Supersampling

Supersampling works well for scenes made up of


filled polygons. I/4 I/4

I/4 I/4
However, it does require a lot of extra computation.
Actual Pixel
I/4 I/4 0 0 intensities
It does not work for line drawings.

Graphics Lecture 5: Slide 37 Graphics Lecture 5: Slide 38

Convolution filtering For example consider the image of a line

The more common (and much faster) way of dealing


with alias effects is to use a ‘filter’ to blur the image.

This essentially takes an average over a small region Theoretical Line


around each pixel
Pixels set to
intensity I
(others set to 0)

Graphics Lecture 5: Slide 39 Graphics Lecture 5: Slide 40

Treat each pixel of the image Weighted averages

Taking a straight local average has undesirable


Consider one
pixel. effects.

Thus we normally use a weighted average.

We replace the pixel by a local average, 1/36 * 1 4 1


one possibility would be 3*I/9 4 16 4
1 4 1

Graphics Lecture 5: Slide 41 Graphics Lecture 5: Slide 42

7
Convolution
Theoretical Line 1/36 1/9 1/36 mask located
at one pixel
1/9 4/9 1/9
Convolution Pixels set to
Theoretical Line 1/36 1/9 1/36 mask located intensity I
1/36 1/9 1/36
at one pixel (others set to 0)
1/9 4/9 1/9
Pixels set to
intensity I
1/36 1/9 1/36 Final Pixel Intensities
(others set to 0)
(9/36)I (21/36)I
Diagram 7.7:
(21/36)I (9/36)I Anti-aliasing by convolution filtering

Graphics Lecture 5: Slide 43 Graphics Lecture 5: Slide 44

Advantages of Convolution filtering Anti-Aliasing textures

It is very fast and can be done in hardware, This is essentially the same technique.

It is of general application When we identify a point in the texture map we return


an average of texture map around the point.
however
Scaling needs to be applied so that the less the
It does degrade the image while enhancing its visual samples taken the bigger the local area where
appearance. averaging is done.

Graphics Lecture 5: Slide 45 Graphics Lecture 5: Slide 46

También podría gustarte