More HSR, OpenGL Buffers & Tests Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, February 2, 2004.

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

Visibilidade MO603/MC930. Visibilidade Algoritmos básicos de visibilidade Algoritmo pintor Z-buffer Estilos de Shading Ray-casting.
15.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 15 – Visible Surfaces and Shadows.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
The Buffers and Operations
OpenGL Buffers and Tests Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday, February 8, 2002.
Graphics Pipeline.
OPENGL Return of the Survival Guide. Buffers (0,0) OpenGL holds the buffers in a coordinate system such that the origin is the lower left corner.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
03/12/02 (c) 2002 University of Wisconsin, CS559 Last Time Some Visibility (Hidden Surface Removal) algorithms –Painter’s Draw in some order Things drawn.
David Luebke5/11/2015 CS 551 / 645: Introductory Computer Graphics David Luebke
Hidden Surface Removal CSE 581. Visibility Assumption: All polygons are opaque What polygons are visible with respect to your view frustum?  Outside:
CAP4730: Computational Structures in Computer Graphics Visible Surface Determination.
Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a.
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
1 CSCE 441: Computer Graphics Hidden Surface Removal (Cont.) Jinxiang Chai.
Vertices and Fragments III Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
Ch 1 Intro to Graphics page 1CS 367 First Day Agenda Best course you have ever had (survey) Info Cards Name, , Nickname C / C++ experience, EOS experience.
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
09/18/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms.
9/20/2001CS 638, Fall 2001 Today Finishing Up Reflections More Multi-Pass Algorithms Shadows.
Hidden Surface Removal
Shadows Computer Graphics. Shadows Shadows Extended light sources produce penumbras In real-time, we only use point light sources –Extended light sources.
Computer Graphics Mirror and Shadows
Course Overview, Introduction to CG Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 5, 2003.
10/29/02 (c) 2002 University of Wisconsin, CS559 Today Hidden Surface Removal Exact Visibility.
CS 638, Fall 2001 Today Light Mapping (Continued) Bump Mapping with Multi-Texturing Multi-Pass Rendering.
Polygon Lists & 3-D File Formats Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, February 18, 2002.
Linear Interpolation, Brief Introduction to OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September.
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
The Visibility Problem In many environments, most of the primitives (triangles) are not visible most of the time –Architectural walkthroughs, Urban environments.
CSC418 Computer Graphics n BSP tree n Z-Buffer n A-buffer n Scanline.
Advanced Computer Graphics Depth & Stencil Buffers / Rendering to Textures CO2409 Computer Graphics Week 19.
Visible-Surface Detection Jehee Lee Seoul National University.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Shadows via Projection Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 5, 2003.
CS 638, Fall 2001 Multi-Pass Rendering The pipeline takes one triangle at a time, so only local information, and pre-computed maps, are available Multi-Pass.
Hidden Surface Removal 1.  Suppose that we have the polyhedron which has 3 totally visible surfaces, 4 totally invisible/hidden surfaces, and 1 partially.
More on Advanced Interfaces, Image Basics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, November 21, 2003.
Advanced HSR Methods Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday, January 30, 2004.
Intro. to Advanced Lighting, Basic Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, April.
3/23/04© University of Wisconsin, CS559 Spring 2004 Last Time Antialiasing –Area-weighted sampling Visibility –Painters algorithm –Depth buffer (Z-buffer)
1Computer Graphics Implementation II Lecture 16 John Shearer Culture Lab – space 2
Implementation II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.
Binary Space Partitioning Trees Ray Casting Depth Buffering
Implementation II.
David Luebke11/26/2015 CS 551 / 645: Introductory Computer Graphics David Luebke
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.
Where We Stand At this point we know how to: –Convert points from local to window coordinates –Clip polygons and lines to the view volume –Determine which.
Computer Graphics I, Fall 2010 Implementation II.
Accumulation-Based Effects Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, February 4, 2004.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
01/28/09Dinesh Manocha, COMP770 Visibility Computations Visible Surface Determination Visibility Culling.
Visible surface determination. Problem outline Given a set of 3D objects and a viewing specification, we wish to determine which lines or surfaces are.
More on Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, April 14, 2004.
09/23/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Reflections Shadows Part 1 Stage 1 is in.
Computer Graphics Implementation II
Stenciling Effects Glenn G. Chappell
© University of Wisconsin, CS559 Fall 2004
OpenGL Buffers and Tests
Implementation II Ed Angel Professor Emeritus of Computer Science
Visibility (hidden surface removal)
CSCE 441: Computer Graphics Hidden Surface Removal (Cont.)
Introduction to Computer Graphics with WebGL
Ref: OpenGL Programming Guide (The Red Book)
Implementation II Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

More HSR, OpenGL Buffers & Tests Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, February 2, 2004

2 Feb 2004CS 481/6812 Review: Advanced HSR Methods [1/2] Most HSR methods fall into one of two categories: object-space methods and image-space methods. Object-Space Methods Here, we do HSR before rasterization. Often outside the pipeline entirely. We deal with scene descriptions (polygons?). Image-Space Methods Here, we deal with fragments or pixels. Thus, if part of a pipeline, image-space methods generally come during or after rasterization. General advantages of object-space methods: Not limited by frame-buffer resolution. Most can be used as a pre-processing step. General advantages of image-space methods: Fewer requirements; usable more often. Usually faster, for scenes with high polygon count.

2 Feb 2004CS 481/6813 Review: Advanced HSR Methods [2/2] Last time we looked at four image-space HSR methods: Z-buffering. A.K.A. “depth buffering”. Very general. A-buffering (not in text) Store list of fragments in each pixel of “A buffer”. Render final scene as post-processing step. Very general, but not used much. Ray Casting Send a ray through each pixel. See what it hits first. Requires a scene description. Ray tracing is a fancier version of this. Scan-Line Method Proceed across scan line, keeping list of relevant polygons. With each new pixel, adjust list & depths of polygons. Requires a scene description. An important method, back before rendering-pipeline hardware.

2 Feb 2004CS 481/6814 More HSR: Intro. to Object-Space Methods Now we look at five object-space HSR methods. Here, we deal with objects or polygons before rasterization. Object-space methods require a scene description, so: Their applicability is not as general as that of, say, z- buffering. They do not fit well within a rendering pipeline; however, they can often be done before the pipeline. Object-space methods generally require comparisons between polygons. Thus, high polygon count can slow them down. Many object-space methods do make good pre-processing steps, however. First, an exception.

2 Feb 2004CS 481/6815 More HSR: 5. Backface Culling If a polygon faces away from the viewer, cull it. In other words, toss it out; do not rasterize it. If all objects are closed surfaces bounding convex regions, and no object covers another, then backface culling does HSR for us. We do this after projection. Why? In OpenGL: glCullFace(GL_BACK); glEnable(GL_CULL_FACE); Properties Object space. Works just fine in a pipeline. Not general at all, of course. Rarely is backface culling, by itself, enough to accomplish HSR for a scene. But we can use it with some other method, to improve efficiency.

2 Feb 2004CS 481/6816 More HSR: 6. Generic Object-Space HSR For each polygon, clip it so that only its visible region remains. Tricky … No, I’m not going to tell you how.  Properties Object-space method. “Main loop” runs over polygons. Polygon-polygon comparisons required. Can be slow. Requires a scene description. So do it before the pipeline. Does not handle translucency.

2 Feb 2004CS 481/6817 More HSR: Note on Painter’s Algorithm A generally useful technique is the Painter’s Algorithm. Method Draw back-to-front. New fragment colors replace old pixel colors. This does HSR. But we need to figure out how to draw back-to-front. The P.A. also handles translucency nicely; we use blending. Closely related is the Reverse Painter’s Algorithm. Method Draw front-to-back. Only set a pixel’s color once. We cannot do translucency with the R.P.A. Now we look at ways to draw in back-to-front order. Front-to-back just reverses this, of course.

2 Feb 2004CS 481/6818 More HSR: 7. Depth Sort Sort polygons by their depth. How can this be a problem? Some collections of polygons cannot be sorted. In such cases we split a polygon. No details right now. Maybe implement this as part of a project? Properties Object-space method. “Main loop” runs over polygons. Polygon-polygon comparisons required. Can be slow. Requires a scene description. Works with P.A. & R.P.A

2 Feb 2004CS 481/6819 More HSR: 8. BSP Trees We know how to get a back-to-front order with a BSP tree. So we do it. This is really just a fancy (but relatively easy) way to accomplish a depth sort. However, we may split polygons more often than we need to. Properties Object-space method. “Main loop” runs over polygons. Polygon-polygon comparisons required. Construction is slow. BSP-tree construction works well as a preprocessing step, as long as the scene is mostly static. Requires a scene description. Works with P.A. & R.P.A.

2 Feb 2004CS 481/68110 More HSR: Tossing Out Polygons With a couple of small exceptions, all of the HSR methods we have discussed have a big problem: They require every polygon in the scene to be rendered. For large, complex scenes, there are often huge areas we cannot see. For example, wandering around in a building, you cannot see most of the rooms. We could greatly improve efficiency if we could throw out polygons in hidden regions. A recent method that addresses this problem is “portal rendering”.

2 Feb 2004CS 481/68111 More HSR: 9. Portal Rendering [1/3] A recently introduced method is portal rendering. Introduced in 1995 by David P. Luebke and Chris Georges. Now implemented in many game engines. This is not in the text. Method Divide the scene into cells (a.k.a. “sectors” or “rooms”). A cell is, roughly speaking, a room. Cells contain polygons. Some of these polygons are portals. A portal joins two cells. Portal polygons are often completely transparent (invisible). When rendering, adjoining cells are placed, using the proper transformations, behind the appropriate portals. Or do ray tracing: rays that hit a portal “go through” to another cell. Cell that do not (potentially) appear are not referenced at all. This is not a complete HSR method. Some other method must be used to do HSR within a cell. However, portal rendering can dramatically improve efficiency of HSR.

2 Feb 2004CS 481/68112 More HSR: 9. Portal Rendering [2/3] Consider the following cell-portal data structure. Portals are in red. This results in the following logical arrangement of cells. Cell 1 Cell 2 Cell 3 A B C D To C To A To D To B Cell 1 Cell 2 Cell 3 A B C D

2 Feb 2004CS 481/68113 More HSR: 9. Portal Rendering [3/3] Portal rendering can easily be extended in interesting ways. Suppose a portal leads from cell 1 into cell 1, at the same portal, with a transformation that reflects the cell about the plane of the portal. Result: Suppose a portal leads from cell 2 into the opposite end of cell 2. We look into cell 1 from cell 3. Result: Generally, portals need not join cells in a reasonable fashion. Also, unlike structures like BSP trees, the cell-portal data structure can easily be modified on the fly. Thus, portal rendering has no problem with: Elevators. Rooms that are bigger than the buildings they lie inside. “Rips in the fabric of space”, or whatever … Is there a project hidden in here somewhere?

2 Feb 2004CS 481/68114 OpenGL Buffers & Tests: Overview We next look at various tools provided by OpenGL: Buffers Tests Blending Part of the OpenGL philosophy is to provide tools without dictating their use. These tools can be used in many ways. Often the name (“depth buffer”) suggests the most common use, but there is nothing “wrong” with using a tool quite differently.

2 Feb 2004CS 481/68115 OpenGL Buffers & Tests: Buffers An OpenGL buffer is (essentially) an array that holds one piece of data for each pixel in the viewport. OpenGL has 4 types of buffers: Color buffers Depth buffer Stencil buffer Accumulation buffer Each buffer has an intended function; however, you may use the buffers in any way you wish. In order to be used, a buffer must be allocated. Do this in your glutInitDisplayMode call.

2 Feb 2004CS 481/68116 OpenGL Buffers & Tests: Tests Related to the buffers are the OpenGL tests: Scissor test Alpha test Depth test Stencil test A test is an expression with a boolean value that OpenGL evaluates for every fragment. If the result is true, then the test passes, and the fragment continues down the pipeline. Otherwise, the test fails, and fragment is discarded. All tests are done in the fragment-processing part of the pipeline. In order to have any effect, a test must be enabled. Do this with glEnable.

2 Feb 2004CS 481/68117 OpenGL Buffers & Tests: Buffers & Tests Together Buffers and tests are associated. We have already seen this with the depth buffer & test. Remember: Allocate buffers; enable tests! BufferCorresponding Test --Scissor Test Color BuffersAlpha Test Depth BufferDepth Test Stencil BufferStencil Test Accumulation Buffer--

2 Feb 2004CS 481/68118 OpenGL Buffers & Tests: Clearing Every OpenGL buffer can be cleared. In each case, the command to do this is the same: glClear. The buffers to clear are specified by bitwise-or’ing together the appropriate GL_ … _BUFFER_BIT constants. For example, glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_ACCUM_BUFFER_BIT); The value to store in each pixel of a buffer is set by a separate command for each buffer: glClearColor glClearDepth glClearStencil glClearAccum

2 Feb 2004CS 481/68119 OpenGL Buffers & Tests: Masking [1/2] Most buffers have masks associated with them. The mask determines whether a buffer (or part of a buffer) is ever written. For example, the color-buffer mask is controlled by the glColorMask command. This command takes 4 parameters, all GLboolean ’s, representing R, G, B, and A, respectively. For example, glColorMask(false, true, true, true); means that the R portion of the color buffer will not be changed. Note: The mask affects all commands that would change the buffer, even glClear.

2 Feb 2004CS 481/68120 OpenGL Buffers & Tests: Masking [2/2] In masking.cpp, I define five bool variables: redmask, greenmask, bluemask, depthmask, clearall. Each defaults to true and is toggled by pressing the first letter in its name. The interesting part of the code is at the start of function display : if (clearall) { glColorMask(true, true, true, true); glDepthMask(true); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } glColorMask(redmask, greenmask, bluemask, true); glDepthMask(depthmask); if (!clearall) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

2 Feb 2004CS 481/68121 OpenGL Buffers & Tests: The Scissor Test The scissor test is by far the simplest of the tests. It allows you to restrict drawing to a rectangular portion of the viewport. To enable: glEnable(GL_SCISSOR_TEST); Then: glScissor( x, y, width, height ); Parameters are as in the glViewport command. (x,y) is the lower-left corner of the rectangle. The scissor test passes if the pixel is within the rectangle; otherwise, it fails. The scissor test is really just a quick, simple version of stenciling. We discuss stenciling later this week.