Accumulation-Based Effects Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, February 4, 2004.

Slides:



Advertisements
Similar presentations
Compositing and Blending Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics.
Advertisements

Technische Universität München Computer Graphics SS 2014 Graphics Effects Rüdiger Westermann Lehrstuhl für Computer Graphik und Visualisierung.
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.
Framebuffer in OpenGL MAE152 Computer Graphics for Scientists and Engineers Fall 03.
OpenGL Fragment Operations
More HSR, OpenGL Buffers & Tests Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, February 2, 2004.
Graphics Pipeline.
1 Buffers and Processing Fragments 2011 Autumn Animação e Visualização Tridimensional 2011/2012.
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.
University of Sulaimani - School of Science - Computer Dept.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Compositing and Blending Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
Compositing and Blending - Chapter 8 modified by Ray Wisman Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Image Compositing Angel 8.11 Angel: Interactive Computer Graphics5E © Addison-Wesley
黃聰賢. Light Position Mesh Polygon Shadow Polygon  Clear color buffer and stencil buffer  Render the scene with ambient only.
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
CS 4731: Computer Graphics Lecture 18: Hidden Surface Removal Emmanuel Agu.
CS 4731: Computer Graphics Lecture 22: Raster Graphics Part 3 Emmanuel Agu.
Computer Graphics Shadows
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
Jittering, Introduction to Stenciling Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday, February 6, 2004.
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.
CS 638, Fall 2001 Today Light Mapping (Continued) Bump Mapping with Multi-Texturing Multi-Pass Rendering.
CS 450: COMPUTER GRAPHICS VISIBLE SURFACE DETECTION SPRING 2015 DR. MICHAEL J. REALE.
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
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.
Advanced Computer Graphics Depth & Stencil Buffers / Rendering to Textures CO2409 Computer Graphics Week 19.
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.
More on Drawable Objects, Hierarchical Objects Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, January.
Advanced HSR Methods Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday, January 30, 2004.
More on Environment Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, December 10, 2003.
Review of OpenGL Basics
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Compositing and Blending
More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
OpenGL Special Effects Jian-Liang Lin 2002 Blending: Alpha Channel Alpha value can be specify by glColor* When blending is enabled, the alpha value is.
11/24/ :45 Graphics II Shadow Maps Reflections Session 5.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
CS559: Computer Graphics Lecture 12: Antialiasing & Visibility Li Zhang Spring 2008.
Shadows David Luebke University of Virginia. Shadows An important visual cue, traditionally hard to do in real-time rendering Outline: –Notation –Planar.
More on Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, April 14, 2004.
Some Notes on 3-D Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 24, 2003.
The Framebuffer Hyun-Chul Cho. HyunChul Cho - KUCG -2 Buffer Goal of a graphics program Draw pictures on the screen Screen Rectangular array.
Tan-Chi Ho, CGGM Lab., CSIE of NCTU Pixel Operations and Buffers.
Computer Graphics I, Fall 2008 Compositing and Blending.
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
Stenciling Effects Glenn G. Chappell
Discrete Techniques.
Draw a Simple Object.
OpenGL Buffers and Tests
CSCE 441: Computer Graphics Hidden Surface Removal
Advanced Menuing, Introduction to Picking
Display Lists & Text Glenn G. Chappell
Ref: OpenGL Programming Guide (The Red Book)
Frame Buffers Fall 2018 CS480/680.
Preview of 3-D Graphics Glenn G. Chappell
Presentation transcript:

Accumulation-Based Effects Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, February 4, 2004

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.

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 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.

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--

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.

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

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.

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.

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.

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 );

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.

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?)

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.

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.

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.

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.

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 …