GLART week 11: Shadows
April 4, 2007
Reading:
Red Book, Chapter 8, Images: pgs 294-300
Red Book, Chapter 9, Replacing all or Part of a texture Image: pgs 367-370
Examples:
GLART_11_Stencil.java -- Use the stencil buffer to make shadows.
GLART_11_Shadow.java -- Use the stencil buffer to make shadows.
glart_week11_examples.zip -- Full source code
NOTES:
=================================================================
Buffers
------------------------
Color buffer holds a color and alpha value for each pixel
Depth buffer holds a depth value for each pixel (how close is this point to the eye)
Stencil buffer holds a mask value for each pixel
turn testing on/off, glEnable/glDisable:
----------------------------------------
GL_ALPHA_TEST (by default it's "off". Color buffer is always "on", but alpha testing can be turned on/off)
GL_DEPTH_TEST (by default it's "off")
GL_STENCIL_TEST (by default it's "off")
specify how test will occur (what passes the test)
-----------------------------------------
glAlphaFunc
glDepthFunc
glStencilFunc
allow or don't allow writing to the buffer
------------------------------------------
glColorMask
glDepthMask
glStencilMask
specify what to do with stencil buffer value when test fails
-------------------------------------------------
glStencilOp
Summary
Buffer Enable/Disable How to test incoming Make buffer Additional
testing on this pixel value against read-only
buffer what's in the buffer
-------------- --------------------- ---------------------- --------------------- --------------
Color GL_ALPHA_TEST glAlphaFunc glColorMask
Depth GL_DEPTH_TEST glDepthFunc glDepthMask
Stencil GL_STENCIL_TEST glStencilFunc glStencilMask glStencilOp
How a pixel gets into a buffer
-----------------------------------
new pixel --> test pixel? compare new value to is buffer writable? write value to buffer.
if yes --> value in buffer. if yes --> StencilOp fine tunes
Does it pass test? what is written.
if no if yes -->
write pixel to
display without
any testing
Scissor Test
---------------------------
The "Scissor Test" clips all drawing to a specified rectangle. Like other tests it can
be enabled or disabled, and when enabled, it will restrict what pixels are rendered.
Unlike other tests, it is not related to a specific buffer. The Scissor test restricts
rendering to a given rectangular area of the display, but does not specifically alter
the behavior of the color, depth or stencil buffers.
glScissor(lowerX, lowerY, width, height) -- specify the rectangle where rendering can occur
glEnable(GL_SCISSOR_TEST) -- turn on scissor test (by default it's off)