Computer Graphics Si Lu Fall 2017 - - PowerPoint PPT Presentation

computer graphics
SMART_READER_LITE
LIVE PREVIEW

Computer Graphics Si Lu Fall 2017 - - PowerPoint PPT Presentation

Computer Graphics Si Lu Fall 2017 http://web.cecs.pdx.edu/~lusi/CS447/CS447_547_Comp uter_Graphics.htm 10/30/2017 Last time o Rasterization 2 Today o Hidden Surface Removal 3 Demo o Lytro Volume Tracer n Light Field rendering solution for


slide-1
SLIDE 1

Computer Graphics

Si Lu

Fall 2017

http://web.cecs.pdx.edu/~lusi/CS447/CS447_547_Comp uter_Graphics.htm 10/30/2017

slide-2
SLIDE 2

Last time

  • Rasterization

2

slide-3
SLIDE 3

Today

  • Hidden Surface Removal

3

slide-4
SLIDE 4

Demo

  • Lytro Volume Tracer

n Light Field rendering solution for CG content n Delivering the highest fidelity, most immersive playback experience. n https://vimeo.com/236615698

4

slide-5
SLIDE 5

Where We Stand

  • At this point we know how to:

n Convert points from local to window coordinates n Clip polygons and lines to the view volume n Determine which pixels are covered by any given line or polygon n Anti-alias

  • Next thing:

n Determine which polygon is in front

5

slide-6
SLIDE 6

Visibility

  • Given a set of polygons, which is visible at each pixel?

(in front, etc.). Also called hidden surface removal

  • Very large number of different algorithms known. Two

main classes:

n Object precision: computations that operate on primitives n Image precision: computations at the pixel level

  • All the spaces in the viewing pipeline maintain depth,

so we can work in any space

n World, View and Canonical Screen spaces might be used n Depth can be updated on a per-pixel basis as we scan convert polygons or lines n Actually, run Bresenham-like algorithm on z and w before perspective divide

6

slide-7
SLIDE 7

Painters Algorithm

  • Algorithm:

n Choose an order for the polygons based on some choice (e.g. depth of a point

  • n the polygon)

n Render the polygons in that

  • rder, deepest one first
  • This renders nearer polygons
  • ver further
  • Difficulty:

n doesn’t work in this form for most geometries - need at least better ways of determining ordering zs xs

Fails

Which point for choosing

  • rdering?

7

slide-8
SLIDE 8

The Z-buffer (1) (Image Precision)

  • For each pixel on screen, have at least two buffers

n Color buffer stores the current color of each pixel

  • The thing to ultimately display

n Z-buffer stores at each pixel the depth of the nearest thing seen so far

  • Also called the depth buffer
  • Initialize this buffer to a value corresponding to the

furthest point

  • As a polygon is filled in, compute the depth value of

each pixel that is to be filled

n if depth < z-buffer depth, fill in pixel color and new depth n else disregard

8

slide-9
SLIDE 9

The Z-buffer (2)

  • Advantages:

n Simple and now ubiquitous in hardware

  • A z-buffer is part of what makes a graphics card “3D”

n Computing the required depth values is simple

  • Disadvantages:

n Over-renders – rasterizes polygons even if they are not visible n Depth quantization errors can be annoying n Can’t easily do transparency or filter-based anti-aliasing (Requires keeping information about partially covered polygons)

9

slide-10
SLIDE 10

OpenGL Depth Buffer

  • OpenGL defines a depth buffer as its visibility algorithm
  • The enable depth testing: glEnable(GL_DEPTH_TEST)
  • To clear the depth buffer: glClear(GL_DEPTH_BUFFER_BIT)

n To clear color and depth:

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)

  • The number of bits used for the depth values can be specified

(windowing system dependent, and hardware may impose limits based on available memory)

  • The comparison function can be specified: glDepthFunc(…)
  • Sometimes want to draw furthest thing, or equal to depth in buffer

10

slide-11
SLIDE 11

The A-buffer (Image Precision)

  • Handles transparent surfaces and filter anti-aliasing
  • At each pixel, maintain a pointer to a list of polygons

sorted by depth, and a sub-pixel coverage mask for each polygon

n Coverage mask: Matrix of bits saying which parts of the pixel are covered

  • Algorithm: Drawing pass (do not directly display the

result)

n if polygon is opaque and covers pixel, insert into list, removing all polygons farther away n if polygon is transparent or only partially covers pixel, insert into list, but don’t remove farther polygons

11

slide-12
SLIDE 12

The A-buffer (2)

  • Algorithm: Rendering pass

n At each pixel, traverse buffer using polygon colors and coverage masks to composite:

  • Advantage:

n Can do more than Z-buffer n Coverage mask idea can be used in other visibility algorithms

  • Disadvantages:

n Not in hardware, and slow in software n Still at heart a z-buffer: Over-rendering and depth quantization problems

  • But, used in high quality rendering tools
  • ver

12

slide-13
SLIDE 13

BSP-Trees (Object Precision)

  • Construct a binary space partition tree

n Tree gives a rendering order n A list-priority algorithm

  • Tree splits 3D world with planes

n The world is broken into convex cells n Each cell is the intersection of all the half-spaces of splitting planes on tree path to the cell

  • Also used to model the shape of objects, and in other

visibility algorithms

13

slide-14
SLIDE 14

BSP-Tree Example

A C B 2 4 1 3 A B C 3 2 4 1

  • +

+ +

14

slide-15
SLIDE 15

Building BSP-Trees

  • Choose polygon (arbitrary)
  • Split its cell using plane on which polygon lies

n May have to chop polygons in two (Clipping!)

  • Continue until each cell contains only one polygon

fragment

  • Splitting planes could be chosen in other ways, but there

is no efficient optimal algorithm for building BSP trees

n Optimal means minimum number of polygon fragments in a balanced tree

15

slide-16
SLIDE 16

Building Example

  • We will build a BSP tree, in

2D, for a 3 room building

n Ignoring doors

  • Splitting edge order is

shown

n “Back” side of edge is side with the number 1 2 3 4 5 6

16

slide-17
SLIDE 17

Building Example (Done)

1 2 3b 4b 5a

1

  • +

4a 3a

2

  • +

5b

3a + 4b + 4a 6 + 5a 3b 5b +

6

17

slide-18
SLIDE 18

Using a BSP-Tree

  • Observation: Things on the opposite side of a splitting plane from

the viewpoint cannot obscure things on the same side as the viewpoint

  • A statement about rays – a ray must hit something on this side of

the split plane before it hits the split plane and before it hits anything on the back side

  • NOT a statement about distance – things on the far side of the

plane can be closer than things on the near side

n Gives a relative ordering of the polygons, not absolute in terms of depth or any other quantity

Split plane

18

slide-19
SLIDE 19

BSP-Tree Rendering

  • Observation: Things on the opposite side of a splitting

plane from the viewpoint cannot obscure things on the same side as the viewpoint

  • Rendering algorithm is recursive descent of the BSP Tree
  • At each node (for back to front rendering):

n Recurse down the side of the sub-tree that does not contain the viewpoint

  • Test viewpoint against the split plane to decide which tree

n Draw the polygon in the splitting plane

  • Paint over whatever has already been drawn

n Recurse down the side of the tree containing the viewpoint

19

slide-20
SLIDE 20

Rendering Example

1

  • +

2

  • +

1 2 3b 4b 5a 6 4a 3a 5b 3a + 4b + 4a 6 + 5a 3b 5b + Back-to-front rendering order is 3a,4a,6,1,4b,5a,2,3b,5b 1 2 3 4 5 6 Eye 9 8 7

20

slide-21
SLIDE 21

BSP-Tree Rendering (2)

  • Advantages:

n One tree works for any viewing point n Filter anti-aliasing and transparency work

  • Have back to front ordering for compositing
  • Disadvantages:

n Can be many small pieces of polygon n Over-rendering

21

slide-22
SLIDE 22

Exact Visibility

  • An exact visibility algorithm tells you what is visible

and only what is visible

n No over-rendering

  • Difficult to achieve efficiently in practice

n Small detail objects in an environment make it particularly difficult

  • But, in mazes and other simple environments, exact

visibility is extremely efficient

22

slide-23
SLIDE 23

Cells and Portals

  • Assume the world can be broken into cells

n Simple shapes n Rooms in a building, for instance

  • Define portals to be the transparent boundaries

between cells

n Doorways between rooms, windows, etc

  • In a world like this, can determine exactly which parts
  • f which rooms are visible

n Then render visible rooms plus contents

23

slide-24
SLIDE 24

Cell-Portal Example (1)

View

24

slide-25
SLIDE 25

Cell and Portal Visibility

  • Start in the cell containing the viewer, with the full

viewing frustum

  • Render the walls of that room and its contents
  • Recursively clip the viewing frustum to each portal out
  • f the cell, and call the algorithm on the cell beyond

the portal

25

slide-26
SLIDE 26

Cell-Portal Example (2)

View

26

slide-27
SLIDE 27

Cell-Portal Example (3)

View

27

slide-28
SLIDE 28

Cell-Portal Example (4)

View

28

slide-29
SLIDE 29

Cell-Portal Example (5)

View

29

slide-30
SLIDE 30

Cell-Portal Example (6)

View

30

slide-31
SLIDE 31

Compiling project 2

31

  • This is not a programming course, thus mostly you

should be able to figure it out by yourself.

  • Details might be different depending on system,

programming tool or even personal programming habits

  • Here is one option for compiling the code, it works on my
  • wn desktop (a normal one)
  • Start as early as possible
slide-32
SLIDE 32

Compiling project 2

32

  • Step1: Finish all tutorials on
  • ur course website, you will

have a solution file/folder A.

n Do not forget to add all fltk\opengl libraries n Do not forget to add the four additional source files

  • TargaImage.h; TargaImage.cpp;

libtarga.c; libtarga.h.

n Be careful to the image’s path

  • Absolute path recommended
slide-33
SLIDE 33

Compiling project 2

33

  • Step2: Modify the solution A to project 2

n Remove main.cpp, myWindow.h, myWindow.cpp in A n Download source code of project 2 from our website n Add all cpp/c and h files in project 2 to A n Add fltkdlld.lib, opengl32.lib, glu32.lib, fltkgld.lib, wsock32.lib, comctl32.lib to Project -> Properties -> Configuration Properties -> Linker ->Input -> Additional Dependencies n Delete “Fl::visual(FL_RGB);” in main function in World.cpp n Build and run, it works for me

slide-34
SLIDE 34

Next Time

  • Mid-term
  • 34