Download presentation
Presentation is loading. Please wait.
Published byRudolf Morton Modified over 9 years ago
1
Accumulation-Based Effects Glenn G. Chappell CHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, February 4, 2004
2
4 Feb 2004CS 481/6812 Note on BSP Trees & Assn. #3 One of the options for assignment #3 (due Tues 2/10) is doing HSR with a BSP Tree. Once the tree is created, its structure is only used to get a back-to-front ordering of polygons. Or front-to-back. Therefore, you need to know the viewer’s position in the coordinate system of the BSP Tree. See whereami.cpp, from last semester’s CS 381 web page, for an example of how to determine the viewer’s position. If this method is used, then OpenGL transformation commands can be used to handle all transformations.
3
4 Feb 2004CS 481/6813 Review: Advanced HSR Methods 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.
4
4 Feb 2004CS 481/6814 Review: More HSR Last time we looked at five object-space HSR methods: Backface Culling Works in the pipeline. Not complete; helps out some other HSR method. “Generic” Object-Space HSR Clip polygons so that only the visible region remains. Depth Sort Sort polygons by depth. May need to split polygons. Works with P.A. & R.P.A. (What does this tell you?) BSP Trees Essentially a nice way to do depth sort. Works with P.A. & R.P.A. Portal Rendering (not in text) Relatively new (1995), but widely used. Divide scene into cells (or “sectors” or “rooms”) joined by portals. Determine which cells are potentially visible. Throw out (!) others. Not complete; helps out some other HSR method. Allows nifty effects like mirrors, infinite corridors, “contradictory” layouts.
5
4 Feb 2004CS 481/6815 Review: OpenGL Buffers & Tests [1/3] OpenGL has 4 kinds of buffers. Each buffer holds a piece of data about every pixel in the viewport. The kind of data depends on which buffer and how it is used. OpenGL has 4 tests. A test gives a Boolean result for each fragment. True → test passes → fragment continues through pipeline. False → test fails → fragment is discarded. Buffers and tests are associated: Remember: Allocate buffers; enable tests! BufferCorresponding Test --Scissor Test Color BuffersAlpha Test Depth BufferDepth Test Stencil BufferStencil Test Accumulation Buffer--
6
4 Feb 2004CS 481/6816 Review: OpenGL Buffers & Tests [2/3] All buffers can be cleared. For example, glClear(GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); Set the value to which a buffer’s pixels are cleared using one of glClearColor, glClearDepth, glClearStencil, glClearAccum. Most buffers can be masked. A mask is, essentially, a Boolean. True means the buffer can be written; false means it will not be. Set & clear masks using glColorMask, glDepthMask, glStencilMask.
7
4 Feb 2004CS 481/6817 Review: OpenGL Buffers & Tests [3/3] The simplest test is the scissor test. It allows you to restrict drawing to a rectangular portion of the viewport. To enable: glEnable(GL_SCISSOR_TEST); To configure: glScissor( x, y, width, height ); Parameters are as in glViewport. Scissoring Region Viewport Drawing CommandsResulting Image
8
4 Feb 2004CS 481/6818 Accumulation-Based Effects: Introduction A number of interesting CG effects can be done by blending several rendered images together. These techniques generally go under the heading of accumulation. Examples: Fade between scenes. See fade.cpp. Motion blur. In OpenGL, image blending is handled with the accumulation buffer.
9
4 Feb 2004CS 481/6819 OpenGL’s Accumulation Buffer: Basics The accumulation buffer allows you to blend together different 2-D images. These can be renderings of 3-D scenes. The accumulation buffer holds RGBA color data, just like the color buffers. Special commands allow you to blend a color buffer with the accumulation buffer (possibly several times) and then transfer the contents of the accumulation buffer to a color buffer. Allocate the accumulation buffer using GLUT_ACCUM in your glutInitDisplayMode call. There is nothing to enable.
10
4 Feb 2004CS 481/68110 OpenGL’s Accumulation Buffer: Operations Five operations can be performed on the accumulation buffer (AB). They are all performed on the entire buffer at once: AB can be cleared. Contents of a color buffer can be multiplied by a value and then copied to AB. Contents of a color buffer can be multiplied by a value and then added to AB. An arithmetic operation ( or +) can be performed on every pixel in AB. The contents of AB can be multiplied by a value and copied to a color buffer. The first operation above, clearing, is done with glClear : glClearAccum( R, G, B, A ); // like glClearColor // (and optional) glClear(GL_ACCUM_BUFFER_BIT); // Clear AB The other four operations involve the glAccum command.
11
4 Feb 2004CS 481/68111 OpenGL’s Accumulation Buffer: glAccum [1/2] glAccum takes two parameters: A GLenum telling which operation to perform. A GLfloat giving a relevant constant value. To multiply the contents of a color buffer by a value and copy the result to the AB: glAccum(GL_LOAD, value ); This uses the color buffer selected for reading. Use glReadBuffer to change this. Generally, you do not need to worry about it. To multiply the contents of a color buffer by a value and add the result to the AB: glAccum(GL_ACCUM, value );
12
4 Feb 2004CS 481/68112 OpenGL’s Accumulation Buffer: glAccum [2/2] To multiply the contents of the AB by a value: glAccum(GL_MULT, value ); There is also GL_ADD, to add instead of multiplying, but I have never seen a use for it. To multiply the contents of the AB by a value and copy the result to a color buffer: glAccum(GL_RETURN, value ); This uses the color buffer selected for drawing. Use glDrawBuffer to change this. Generally, you do not need to worry about it.
13
4 Feb 2004CS 481/68113 OpenGL’s Accumulation Buffer: Typical Code [1/2] void display() // The display function { glClear(GL_ACCUM_BUFFER_BIT); for (int i = 0; i < numscenes; ++i) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Draw scene number i here glAccum(GL_ACCUM, sceneweight[i]); } glAccum(GL_RETURN, 1.0); glutSwapBuffers(); } The values sceneweight[i] should be in [0,1] and should probably add up to 1. Replacing “ sceneweight[i] ” with “ 1.0/numscenes ” would give equal weight to all scenes being blended. Note how the clearing works: AB outside the loop, color & depth inside. Also note that the above code is not as efficient as it could be. (Why?)
14
4 Feb 2004CS 481/68114 OpenGL’s Accumulation Buffer: Typical Code [2/2] Here is more efficient code: void display() // The display function { for (int i = 0; i < numscenes; ++i) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Draw scene number i here glAccum(((i > 0) ? GL_ACCUM : GL_LOAD), sceneweight[i]); } glAccum(GL_RETURN, 1.0); glutSwapBuffers(); } The AB does not need to be cleared if the first operation is GL_LOAD.
15
4 Feb 2004CS 481/68115 OpenGL’s Accumulation Buffer: Example See fade.cpp (on the web page) for an example of a program that uses the AB to do scene-to-scene fade.
16
4 Feb 2004CS 481/68116 OpenGL’s Accumulation Buffer: The Reality As you have probably noticed, using OpenGL’s AB can result in very slow programs. Because pipeline-based-rendering is used mostly for real-time applications today, tools like OpenGL’s AB are probably not used much. However, accumulation-based effects are not specific to any rendering system. They merely require different renderings of a scene to be blended. Thus, similar ideas can be (and are) used in ray-tracing contexts, etc., and so I think they are still worth learning about.
17
4 Feb 2004CS 481/68117 Accumulation & Jittering: Introduction Fancier accumulation-based effects can be done using “jittering”. Jittering means making a number of small changes in the scene, rendering separately for each change, and blending the results. Usually we jitter so that the small changes will be distributed somewhat uniformly. Arrays of data appropriate for jittering can are in jitter.h, from the Red Book (and linked on the web page). You may use jitter.h on an assignment.
18
4 Feb 2004CS 481/68118 Accumulation & Jittering: Applications What can be done with jittering, and how? Anti-aliasing Jitter the scene so that all objects move identical sub- pixel distances. Depth of Field Effect Jitter the entire scene so that a certain plane stays fixed. Soft Shadows Using a shadowing technique. Jitter the light source. This works well with shadows via projection. Using this with the textured-shadows technique is a bit inefficient, since the texture must be generated anew each time the light source moves. However, the AB is already inefficient …
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.