Stenciling Effects Glenn G. Chappell

Slides:



Advertisements
Similar presentations
Lecture 8 Transparency, Mirroring
Advertisements

Technische Universität München Computer Graphics SS 2014 Graphics Effects Rüdiger Westermann Lehrstuhl für Computer Graphik und Visualisierung.
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.
More HSR, OpenGL Buffers & Tests Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, February 2, 2004.
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.
University of Sulaimani - School of Science - Computer Dept.
CSL 859: Advanced Computer Graphics Dept of Computer Sc. & Engg. IIT Delhi.
Week 10 - Monday.  What did we talk about last time?  Global illumination  Shadows  Projection shadows  Soft shadows.
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.
1 Dr. Scott Schaefer Shadows. 2/40 Shadows Shadows provide clues about depth Make scenes appear more realistic.
Real-Time Rendering SPEACIAL EFFECTS Lecture 03 Marina Gavrilova.
黃聰賢. Light Position Mesh Polygon Shadow Polygon  Clear color buffer and stencil buffer  Render the scene with ambient only.
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.
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.
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.
Erdem Alpay Ala Nawaiseh. Why Shadows? Real world has shadows More control of the game’s feel  dramatic effects  spooky effects Without shadows the.
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.
Representing Transformations, The TRANSF Package Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday,
Data Structures for Scenes, The Basics of Scene Graphs Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday,
CHAPTER 11 Shadows © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Shadow rendering algorithms – –Blinn’s shadow.
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.
1 10/24/ :01 UML Graphics II Shadows Session 4.
Shadows. Shadows is important in scenes, consolidating spatial relationships “Geometric shadows”: the shape of an area in shadow Early days, just pasted.
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.
Computer graphics & visualization Shadows / Transparency.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
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.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Accumulation-Based Effects Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, February 4, 2004.
Real-Time Dynamic Shadow Algorithms Evan Closson CSE 528.
Shadows David Luebke University of Virginia. Shadows An important visual cue, traditionally hard to do in real-time rendering Outline: –Notation –Planar.
Stencil Shadows Garrett Weng. What are stencil shadows? Also known as shadow volumes Relies on use of the stencil buffer Create volumes of the shadows.
09/23/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Reflections Shadows Part 1 Stage 1 is in.
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.
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
Lecture 9 From Vertices to Fragments. Objectives Introduce basic implementation strategies Clipping Rasterization hidden-surface removal.
CENG 477 Introduction to Computer Graphics
Week 7 - Monday CS361.
Hidden Surface Removal
Real-Time Rendering Shadow Volumes
Multiple-pass Reflection Depth of Field
3D Graphics Rendering PPT By Ricardo Veguilla.
Jim X. Chen George Mason University
OpenGL Buffers and Tests
CSCE 441: Computer Graphics Hidden Surface Removal
Advanced Menuing, Introduction to Picking
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
WINDOWING AND CLIPPING
Projection in 3-D Glenn G. Chappell
Display Lists & Text Glenn G. Chappell
WINDOWING AND CLIPPING
Visibility (hidden surface removal)
Texture and Shadow Mapping
Last Time Presentation of your game and idea Environment mapping
Ref: OpenGL Programming Guide (The Red Book)
Stencil Buffer & Decals
Preview of 3-D Graphics Glenn G. Chappell
Presentation transcript:

Stenciling Effects Glenn G. Chappell CHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, February 9, 2004

Review: Details of Jittering [1/2] Some of the more interesting accumulation-based effects can be accomplished via “jittering”. Jittering = making small, random-ish movements in a scene, rendering for each movement, and blending the results. Jittering is useful for making things that look “fuzzy”. We generally jitter in two dimensions. Using a table of x & y values is convenient. The file jitter.h contains a number of such tables. See simplejitter.cpp for an example program that uses them. For each jitter, we use x and y to generate a transformation. What sort of transformation? Where in the pipeline does it go? Answering these can be the trickiest part of jittering. 9 Feb 2004 CS 481/681

Review: Details of Jittering [2/2] We looked at three effects that can be created using jittering: Anti-Aliasing Jitter the entire rendered image. Transformations are simple translations. They go after the usual projection (before it, in the code). Depth-of-Field Effect Jitter the 3-D scene, leaving a plane fixed. Transformations are shears, and thus cannot be created using only glTranslate*, glRotate*, glScale*. They go before the usual projection (after it, in the code). Soft Shadows Use some shadowing method. Jitter the light source. Transformations are translations, perpendicular to the predominant light direction. They go before (after, in the code) the rest of the model/view transformation(s), for the light-source only. 9 Feb 2004 CS 481/681

Review: Introduction to Stenciling [1/3] Stenciling involves the stencil buffer and the stencil test. Remember: allocate the buffer, enable the test. Clear the buffer the same way you clear any buffer. The two major functions used in stenciling are glStencilFunc and glStencilOp. glStencilFunc determines what the stencil test does. glStencilOp determines what happens to the stencil buffer if the stencil test passes or fails. If the stencil test passes, then you can also have different outcomes based on the depth test. 9 Feb 2004 CS 481/681

Review: Introduction to Stenciling [2/3] glStencilFunc takes three parameters: A GLenum: what comparison the stencil test will do. A GLint used as a “reference value” in the stencil test. It is also used by the GL_REPLACE option of glStencilOp. A GLuint used as a mask (an “and” mask). Think: REF COMPARE (buffer pixel & mask) Examples Stencil test passes if bit in SB is on: glStencilFunc(GL_EQUAL, 1, 1); Stencil test passes if bit in SB is off: glStencilFunc(GL_NOTEQUAL, 1, 1); Test passes if 20 < low 8 bits in SB: glStencilFunc(GL_LESS, 20, 0xff); 9 Feb 2004 CS 481/681

Review: Introduction to Stenciling [3/3] glStencilOp takes three parameters, all GLenum’s: Operation to perform if stencil test fails. Op. to perform if stencil test passes and depth test fails. Op. to perform if stencil test passes and depth test passes. Examples Replace the SB value with the reference value (from glStencilFunc): glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); Do not modify the SB: glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); Replace SB value with zero, the reference value, or the bitwise inversion of the current SB value, respectively: glStencilFunc(GL_ZERO, GL_REPLACE, GL_INVERT); Increment or decrement the SB value, as appropriate: glStencilFunc(GL_DECR, GL_INCR, GL_INCR); 9 Feb 2004 CS 481/681

Stenciling Effects: “Ordinary” Stenciling First we draw a shape in the stencil buffer. If the shape is fixed, then we only need to redraw it when the viewport changes size. So this code can go in the reshape function. glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT); glStencilFunc(GL_NEVER, 1, 1); // No "real" drawing. glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); Draw a shape here. glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); Then we use the above shape, in the display function. glStencilFunc(GL_EQUAL, 1, 1); Draw something; it will appear only inside the above shape. glStencilFunc(GL_NOTEQUAL, 1, 1); Draw something; it will appear only outside the above shape. 9 Feb 2004 CS 481/681

Stenciling Effects: Reverse Painter’s Algorithm Recall that the R.P.A. can be used, with a method to order polygons front-to-back, to do HSR. To order polygons, you might use a BSP tree. To use the R.P.A., we draw front-to-back, and we make sure that no pixel color is set more than once. We can do the latter using stenciling. glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // No depth buffer! glStencilFunc(GL_NOTEQUAL, 1, 1); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); Draw scene front-to-back. 9 Feb 2004 CS 481/681

Stenciling Effects: Capping Here is an implementation of “capping” (see Red p. 446). Say we are drawing a number of closed objects. We wish to make sure that the inside of these is never visible, even if the near clipping plane slices one of them. glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glStencilFunc(GL_ALWAYS, 1, 1); glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT); Draw scene. glStencilFunc(GL_EQUAL, 1, 1); Draw rectangle covering entire viewport, in “capping” color. 9 Feb 2004 CS 481/681

Stenciling Effects: Odd Things to Do Draw each pixel at most 5 times: glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT); glStencilFunc(GL_GREATER, 5, 0xff); glStencilOp(GL_KEEP, GL_INCR, GL_INCR); Draw each pixel successfully only on every other attempt: glStencilFunc(GL_EQUAL, 0, 1); glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT); 9 Feb 2004 CS 481/681

Shadow Volumes: Introduction In CS 381 we covered two shadowing techniques: Shadowing via Projection The shadow is the shadow-caster drawn using the proper projection in the model/view matrix (and probably in a different color, too). Shadowing via Textures Draw the shadow-caster from the point of view of the light source. Grab the resulting image for use as a texture. Using the texture transformation, draw the shadow on the shadow-receiver. Now we look at a third technique: shadow volumes. This technique uses stenciling. 9 Feb 2004 CS 481/681

Shadow Volumes: The Idea [1/2] Consider a number of polygons that cast non-overlapping shadows. The “non-overlapping” part is important, unfortunately. These polygons may be part of a single surface. For each polygon, the region in its shadow is called its shadow volume. If we can draw the portions of polygons that lie inside shadow volumes into the stencil buffer, then we can use stenciling to draw the shadowed scene. Right? So, how do we do this? 9 Feb 2004 CS 481/681

Shadow Volumes: The Idea [2/2] Think about the boundaries of shadow volumes. A point is in shadow precisely when we must look through an odd number of these boundaries to see it. Assuming the viewer is not in shadow. If the viewer is in shadow, change “odd” to “even”. Zero is even (and not odd)! Do you see why it is important that shadow volumes do not overlap? 9 Feb 2004 CS 481/681

Shadow Volumes: The Technique First, draw the scene in the depth buffer: Clear the depth buffer. Set up the stencil test so that it always passes. Draw the scene in the depth buffer, with the usual depth test. Next the magic. Draw shadow-volume boundaries, inverting the SB value if the depth test passes. Clear the SB. Set up stenciling: The depth buffer is never changed. The depth test is as usual. The stencil test always passes (this is already set). If the stencil and depth tests pass, then invert the SB value. Otherwise, leave it alone. Draw the shadow-volume boundaries. Now the non-zero portions of the SB are those in which we see something in shadow, and we can draw the final scene: Fix the stencil buffer so it cannot be changed, and the depth buffer so it can. Clear the color and depth buffers. Draw scene with only ambient lighting, restricted to non-zero in SB. Draw scene with full lighting, restricted to zero in SB. 9 Feb 2004 CS 481/681

Note Due to the Discovery Lab becoming available, we will stop the buffers/tests/blending unit here. Next we will look at dealing with transformations in ways that are helpful in VR. 9 Feb 2004 CS 481/681