computer graphics
play

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


  1. Computer Graphics Si Lu Fall 2017 http://web.cecs.pdx.edu/~lusi/CS447/CS447_547_Comp uter_Graphics.htm 10/30/2017

  2. Last time o Rasterization 2

  3. Today o Hidden Surface Removal 3

  4. Demo o 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

  5. Where We Stand o 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 o Next thing: n Determine which polygon is in front 5

  6. Visibility o Given a set of polygons, which is visible at each pixel? (in front, etc.). Also called hidden surface removal o Very large number of different algorithms known. Two main classes: n Object precision: computations that operate on primitives Image precision: computations at the pixel level n o All the spaces in the viewing pipeline maintain depth, so we can work in any space World, View and Canonical Screen spaces might be used n 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

  7. Painters Algorithm Algorithm: o Choose an order for the n polygons based on some Fails choice (e.g. depth of a point on the polygon) Render the polygons in that n order, deepest one first o This renders nearer polygons over further z s Which o Difficulty: point for n doesn’t work in this form for choosing most geometries - need at ordering? least better ways of determining ordering x s 7

  8. The Z-buffer (1) (Image Precision) o For each pixel on screen, have at least two buffers n Color buffer stores the current color of each pixel o The thing to ultimately display n Z-buffer stores at each pixel the depth of the nearest thing seen so far o Also called the depth buffer o Initialize this buffer to a value corresponding to the furthest point o As a polygon is filled in, compute the depth value of each pixel that is to be filled if depth < z-buffer depth, fill in pixel color and new depth n else disregard n 8

  9. The Z-buffer (2) o Advantages: Simple and now ubiquitous in hardware n o A z-buffer is part of what makes a graphics card “3D” n Computing the required depth values is simple o Disadvantages: Over-renders – rasterizes polygons even if they are not visible n Depth quantization errors can be annoying n n Can’t easily do transparency or filter-based anti-aliasing (Requires keeping information about partially covered polygons) 9

  10. OpenGL Depth Buffer o OpenGL defines a depth buffer as its visibility algorithm o The enable depth testing: glEnable(GL_DEPTH_TEST) o 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) o The number of bits used for the depth values can be specified (windowing system dependent, and hardware may impose limits based on available memory) o The comparison function can be specified: glDepthFunc(…) Sometimes want to draw furthest thing, or equal to depth in buffer o 10

  11. The A-buffer (Image Precision) o Handles transparent surfaces and filter anti-aliasing o 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 o 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

  12. The A-buffer (2) o Algorithm: Rendering pass n At each pixel, traverse buffer using polygon colors and coverage masks to composite: over o Advantage: Can do more than Z-buffer n Coverage mask idea can be used in other visibility algorithms n o Disadvantages: n Not in hardware, and slow in software n Still at heart a z-buffer: Over-rendering and depth quantization problems o But, used in high quality rendering tools 12

  13. BSP-Trees (Object Precision) o Construct a binary space partition tree Tree gives a rendering order n A list-priority algorithm n o Tree splits 3D world with planes n The world is broken into convex cells Each cell is the intersection of all the half-spaces of splitting n planes on tree path to the cell o Also used to model the shape of objects, and in other visibility algorithms 13

  14. BSP-Tree Example A A C - + 4 3 B C - B + - + 1 3 2 4 1 2 14

  15. Building BSP-Trees o Choose polygon (arbitrary) o Split its cell using plane on which polygon lies n May have to chop polygons in two (Clipping!) o Continue until each cell contains only one polygon fragment o Splitting planes could be chosen in other ways, but there is no efficient optimal algorithm for building BSP trees Optimal means minimum number of polygon fragments in a n balanced tree 15

  16. Building Example o We will build a BSP tree, in 5 2D, for a 3 room building n Ignoring doors o Splitting edge order is shown 2 n “Back” side of edge is side with the number 3 4 1 6 16

  17. Building Example (Done) 5b 5a 1 + - 2 3a - + + 3b 2 4b 4a 4b 3b + + + 6 5a 5b 1 4a 3a 6 17

  18. Using a BSP-Tree o Observation: Things on the opposite side of a splitting plane from the viewpoint cannot obscure things on the same side as the viewpoint Split plane o 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 o NOT a statement about distance – things on the far side of the plane can be closer than things on the near side Gives a relative ordering of the polygons, not absolute in terms of n depth or any other quantity 18

  19. BSP-Tree Rendering o Observation: Things on the opposite side of a splitting plane from the viewpoint cannot obscure things on the same side as the viewpoint o Rendering algorithm is recursive descent of the BSP Tree o At each node (for back to front rendering): Recurse down the side of the sub-tree that does not contain the n viewpoint o Test viewpoint against the split plane to decide which tree n Draw the polygon in the splitting plane o Paint over whatever has already been drawn Recurse down the side of the tree containing the viewpoint n 19

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

  21. BSP-Tree Rendering (2) o Advantages: n One tree works for any viewing point n Filter anti-aliasing and transparency work o Have back to front ordering for compositing o Disadvantages: Can be many small pieces of polygon n n Over-rendering 21

  22. Exact Visibility o An exact visibility algorithm tells you what is visible and only what is visible No over-rendering n o Difficult to achieve efficiently in practice Small detail objects in an environment make it particularly n difficult o But, in mazes and other simple environments, exact visibility is extremely efficient 22

  23. Cells and Portals o Assume the world can be broken into cells n Simple shapes n Rooms in a building, for instance o Define portals to be the transparent boundaries between cells n Doorways between rooms, windows, etc o In a world like this, can determine exactly which parts of which rooms are visible n Then render visible rooms plus contents 23

  24. Cell-Portal Example (1) View 24

  25. Cell and Portal Visibility o Start in the cell containing the viewer, with the full viewing frustum o Render the walls of that room and its contents o Recursively clip the viewing frustum to each portal out of the cell, and call the algorithm on the cell beyond the portal 25

  26. Cell-Portal Example (2) View 26

  27. Cell-Portal Example (3) View 27

  28. Cell-Portal Example (4) View 28

  29. Cell-Portal Example (5) View 29

  30. Cell-Portal Example (6) View 30

  31. Compiling project 2 o This is not a programming course, thus mostly you should be able to figure it out by yourself. o Details might be different depending on system, programming tool or even personal programming habits o Here is one option for compiling the code, it works on my own desktop (a normal one) o Start as early as possible 31

  32. Compiling project 2 o Step1: Finish all tutorials on our 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 o TargaImage.h; TargaImage.cpp; libtarga.c; libtarga.h. n Be careful to the image’s path o Absolute path recommended 32

  33. Compiling project 2 o 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 Add fltkdlld.lib, opengl32.lib, glu32.lib, fltkgld.lib, n wsock32.lib, comctl32.lib to Project -> Properties -> Configuration Properties -> Linker ->Input -> Additional Dependencies Delete “Fl::visual(FL_RGB);” in main function in World.cpp n n Build and run, it works for me 33

  34. Next Time o Mid-term o 34

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend