Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 551 / 645: Introductory Computer Graphics Visible Surface Determination.

Similar presentations


Presentation on theme: "CS 551 / 645: Introductory Computer Graphics Visible Surface Determination."— Presentation transcript:

1 CS 551 / 645: Introductory Computer Graphics Visible Surface Determination

2 Administrivia l Midterm – Points returned for Orthonormal question –Sums to 1 is incorrect, but in my class notes l Assignment 2 returned l Describe assignment 3

3 Assignment 3 – Part 2 l Add textures to your OBJ –Put your OBJ (or another one you like) inside a cube (with six texture mapped sides) –Compute texture coordinates for the vertices in your OBJ model –Polygons will appear to reflect sides of cube l Add vertex normals l Add three lights (phong lighting model) l Add quaternion rotation for mouse

4 Assignment 3 - Part 2 l Beware of polygons that are projected onto two or three sides of cube l Extra credit for additional effects l Groundrules for collaboration –No written record after collaboration. Your recollection of the concepts should be the product of the collaboration. –No side-by-side coding/collaboration l Use of Web materials is accepted, but you must reference their use in README

5 Recap: Rendering Pipeline l Almost finished with the rendering pipeline: –Modeling transformations –Viewing transformations –Projection transformations –Clipping –Scan conversion l We now know everything about how to draw a polygon on the screen, except visible surface determination

6 Invisible Primitives l Why might a polygon be invisible? –Polygon outside the field of view –Polygon is backfacing –Polygon is occluded by object(s) nearer the viewpoint l For efficiency reasons, we want to avoid spending work on polygons outside field of view or backfacing l For efficiency and correctness reasons, we need to know when polygons are occluded

7 View Frustum Clipping l Remove polygons entirely outside frustum –Note that this includes polygons “behind” eye (actually behind near plane) l Pass through polygons entirely inside frustum l Modify remaining polygons to pass through portions intersecting view frustum

8 Back-Face Culling l Most objects in scene are typically “solid” l More rigorously: closed, orientable manifolds –Local neighborhood of all points isomorphic to disc –Boundary partitions space into interior & exterior

9 Manifold l Examples of manifold objects: –Sphere –Torus –Well-formed CAD part

10 Back-Face Culling l Examples of non-manifold objects: –A single polygon –A terrain or height field –polyhedron w/ missing face –Anything with cracks or holes in boundary –one-polygon thick lampshade:

11 Back-Face Culling l On the surface of a closed manifold, polygons whose normals point away from the camera are always occluded: Note: backface culling alone doesn’t solve the hidden-surface problem!

12 Back-Face Culling l Not rendering backfacing polygons improves performance –By how much? –When in the pipeline should we perform backface culling?

13 Occlusion l For most interesting scenes, some polygons will overlap: l To render the correct image, we need to determine which polygons occlude which

14 Painter’s Algorithm l Simple approach: render the polygons from back to front, “painting over” previous polygons: –Draw blue, then green, then orange l Will this work in the general case?

15 Painter’s Algorithm: Problems l Intersecting polygons present a problem l Even non-intersecting polygons can form a cycle with no valid visibility order:

16 Analytic Visibility Algorithms l Early visibility algorithms computed the set of visible polygon fragments directly, then rendered the fragments to a display: –Now known as analytic visibility algorithms

17 Analytic Visibility Algorithms l What is the minimum worst-case cost of computing the fragments for a scene composed of n polygons? l Answer: O(n 2 )

18 Analytic Visibility Algorithms l So, for about a decade (late 60s to late 70s) there was intense interest in finding efficient algorithms for hidden surface removal l We’ll talk about two: –Binary Space-Partition (BSP) Trees –Warnock’s Algorithm

19 Binary Space Partition Trees (1979) l BSP tree: organize all of space (hence partition) into a binary tree –Preprocess: overlay a binary tree on objects in the scene –Runtime: correctly traversing this tree enumerates objects from back to front –Idea: divide space recursively into half-spaces by choosing splitting planes n Splitting planes can be arbitrarily oriented n Notice: nodes are always convex

20 BSP Trees: Objects

21

22

23

24

25 Rendering BSP Trees renderBSP(BSPtree *T) BSPtree *near, far; if (eye on left side of T->plane) near = T->left; far = T->right; else near = T->right; far = T->left; renderBSP(far); if (T is a leaf node) renderObject(T) renderBSP(near);

26 Rendering BSP Trees

27

28 Polygons: BSP Tree Construction l Split along the plane containing any polygon l Classify all polygons into positive or negative half-space of the plane –If a polygon intersects plane, split it into two l Recurse down the negative half-space l Recurse down the positive half-space

29 Polygons: BSP Tree Traversal l Query: given a viewpoint, produce an ordered list of (possibly split) polygons from back to front: BSPnode::Draw(Vec3 viewpt) Classify viewpt: in + or - half-space of node->plane? /* Call that the “near” half-space */ farchild->draw(viewpt); render node->polygon; /* always on node->plane */ nearchild->draw(viewpt); l Intuitively: at each partition, draw the stuff on the farther side, then the polygon on the partition, then the stuff on the nearer side

30 l No bunnies were harmed in my example l But what if a splitting plane passes through an object? –Split the object; give half to each node: –Worst case: can create up to O(n 3 ) objects! Discussion: BSP Tree Cons Ouch

31 BSP Demo l Nice demo: http://symbolcraft.com/pjl/graphics/bsp

32 Summary: BSP Trees l Pros: –Simple, elegant scheme –Only writes to framebuffer (i.e., painters algorithm) n Thus very popular for video games (but getting less so) l Cons: –Computationally intense preprocess stage restricts algorithm to static scenes –Worst-case time to construct tree: O(n 3 ) –Splitting increases polygon count n Again, O(n 3 ) worst case

33 Warnock’s Algorithm (1969) l Elegant scheme based on a powerful general approach common in graphics: if the situation is too complex, subdivide –Start with a root viewport and a list of all primitives –Then recursively: n Clip objects to viewport n If number of objects incident to viewport is zero or one, visibility is trivial n Otherwise, subdivide into smaller viewports, distribute primitives among them, and recurse

34 Warnock’s Algorithm l What is the terminating condition? l How to determine the correct visible surface in this case?

35 Warnock’s Algorithm l Pros: –Very elegant scheme –Extends to any primitive type l Cons: –Hard to embed hierarchical schemes in hardware –Complex scenes usually have small polygons and high depth complexity n Thus most screen regions come down to the single-pixel case

36 The Z-Buffer Algorithm l Both BSP trees and Warnock’s algorithm were proposed when memory was expensive –Example: first 512x512 framebuffer > $50,000! l Ed Catmull (mid-70s) proposed a radical new approach called z-buffering. l The big idea: resolve visibility independently at each pixel

37 The Z-Buffer Algorithm l We know how to rasterize polygons into an image discretized into pixels:

38 The Z-Buffer Algorithm l What happens if multiple primitives occupy the same pixel on the screen? Which is allowed to paint the pixel?

39 The Z-Buffer Algorithm l Idea: retain depth (Z in eye coordinates) through projection transform –Recall canonical viewing volumes –Can transform canonical perspective volume into canonical parallel volume with:

40 The Z-Buffer Algorithm l Augment framebuffer with Z-buffer or depth buffer which stores Z value at each pixel –At frame beginning initialize all pixel depths to  –When rasterizing, interpolate depth (Z) across polygon and store in pixel of Z-buffer –Suppress writing to a pixel if its Z value is more distant than the Z value already stored there n “More distant”: greater than or less than, depending

41 Interpolating Z l Edge equations: Z is just another planar parameter: z = (-D - Ax – By) / C \z new = z – (A/C)(  x) –Look familiar? –Total cost: n 1 more parameter to increment in inner loop n 3x3 matrix multiply for setup l Edge walking: just interpolate Z along edges and across spans

42 The Z-Buffer Algorithm l How much memory does the Z-buffer use? l Does the image rendered depend on the drawing order? l Does the time to render the image depend on the drawing order? l How does Z-buffer load scale with visible polygons? With framebuffer resolution?

43 Z-Buffer Pros l Simple!!! l Easy to implement in hardware l Polygons can be processed in arbitrary order l Easily handles polygon interpenetration l Enables deferred shading –Rasterize shading parameters (e.g., surface normal) and only shade final visible fragments

44 Z-Buffer Cons l Lots of memory (e.g. 1280x1024x32 bits) l Read-Modify-Write in inner loop requires fast memory l Hard to do analytic antialiasing l Hard to simulate translucent polygons l Precision issues (scintillating, worse with perspective projection)


Download ppt "CS 551 / 645: Introductory Computer Graphics Visible Surface Determination."

Similar presentations


Ads by Google