Accumulation-Based Effects - PowerPoint PPT Presentation

About This Presentation
Title:

Accumulation-Based Effects

Description:

One of the options for assignment #3 (due Tues 2/10) is doing HSR ... Backface Culling. Works in the pipeline. Not complete; helps out some other HSR method. ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 19
Provided by: glenngc
Learn more at: https://www.cs.uaf.edu
Category:

less

Transcript and Presenter's Notes

Title: Accumulation-Based Effects


1
Accumulation-Based Effects
  • Glenn G. ChappellCHAPPELLG_at_member.ams.org
  • U. of Alaska Fairbanks
  • CS 481/681 Lecture Notes
  • Wednesday, February 4, 2004

2
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 viewers position
    in the coordinate system of the BSP Tree.
  • See whereami.cpp, from last semesters CS 381 web
    page, for an example of how to determine the
    viewers position.
  • If this method is used, then OpenGL
    transformation commands can be used to handle all
    transformations.

3
ReviewAdvanced 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
ReviewMore 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
ReviewOpenGL 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!

Buffer Corresponding Test
-- Scissor Test
Color Buffers Alpha Test
Depth Buffer Depth Test
Stencil Buffer Stencil Test
Accumulation Buffer --
6
ReviewOpenGL 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 buffers 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
ReviewOpenGL Buffers Tests 3/3
  • The simplest test is the scissor test.
  • It allows you to restrict drawing to
    arectangular portion of the viewport.
  • To enableglEnable(GL_SCISSOR_TEST)
  • To configureglScissor(x, y, width, height)
  • Parameters are as in glViewport.

ScissoringRegion
Viewport
Drawing Commands
Resulting Image
8
Accumulation-Based EffectsIntroduction
  • 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
OpenGLs Accumulation BufferBasics
  • 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
OpenGLs Accumulation BufferOperations
  • 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
    glClearglClearAccum(R, G, B, A) // like
    glClearColor //
    (and optional)glClear(GL_ACCUM_BUFFER_BIT) //
    Clear AB
  • The other four operations involve the glAccum
    command.

11
OpenGLs Accumulation BufferglAccum 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
OpenGLs Accumulation BufferglAccum 2/2
  • To multiply the contents of the AB by a
    valueglAccum(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 bufferglAccum(GL_RET
    URN, value)
  • This uses the color buffer selected for drawing.
  • Use glDrawBuffer to change this.
  • Generally, you do not need to worry about it.

13
OpenGLs Accumulation BufferTypical Code 1/2
  • void display() // The display function
  • glClear(GL_ACCUM_BUFFER_BIT)
  • for (int i 0 i lt numscenes i)
  • glClear(GL_COLOR_BUFFER_BIT
    GL_DEPTH_BUFFER_BIT)
  • Draw scene number i here
  • glAccum(GL_ACCUM, sceneweighti)
  • glAccum(GL_RETURN, 1.0)
  • glutSwapBuffers()
  • The values sceneweighti should be in 0,1 and
    should probably add up to 1.
  • Replacing sceneweighti 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
OpenGLs Accumulation BufferTypical Code 2/2
  • Here is more efficient code
  • void display() // The display function
  • for (int i 0 i lt numscenes i)
  • glClear(GL_COLOR_BUFFER_BIT
    GL_DEPTH_BUFFER_BIT)
  • Draw scene number i here
  • glAccum(((i gt 0) ? GL_ACCUM GL_LOAD),
    sceneweighti)
  • glAccum(GL_RETURN, 1.0)
  • glutSwapBuffers()
  • The AB does not need to be cleared if the first
    operation is GL_LOAD.

15
OpenGLs Accumulation BufferExample
  • See fade.cpp (on the web page) for an example of
    a program that uses the AB to do scene-to-scene
    fade.

16
OpenGLs Accumulation BufferThe Reality
  • As you have probably noticed, using OpenGLs AB
    can result in very slow programs.
  • Because pipeline-based-rendering is used mostly
    for real-time applications today, tools like
    OpenGLs 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
Accumulation JitteringIntroduction
  • 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
Accumulation JitteringApplications
  • 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
Write a Comment
User Comments (0)
About PowerShow.com