Stencil Buffer Algorithms CS418 Computer Graphics John C. Hart - - PowerPoint PPT Presentation

stencil buffer algorithms
SMART_READER_LITE
LIVE PREVIEW

Stencil Buffer Algorithms CS418 Computer Graphics John C. Hart - - PowerPoint PPT Presentation

Stencil Buffer Algorithms CS418 Computer Graphics John C. Hart Stencil Buffer glStencilOp(sfail,dfail,dpass) sfail: stencil test fails dfail: stencil test passes, depth test fails glEnable(GL_STENCIL_TEST) dpass: both stencil


slide-1
SLIDE 1

Stencil Buffer Algorithms

CS418 Computer Graphics John C. Hart

slide-2
SLIDE 2

Stencil Buffer

glEnable(GL_STENCIL_TEST) glDisable(GL_STENCIL_TEST) glStencilFunc(function,value,mask)

  • test function: GL_NEVER, ALWAYS,

LESS, LEQUAL, GREATER, GEQUAL, EQUAL, NOTEQUAL

  • integer value for comparison: [0,2n-1]
  • mask controls which bits used/affected

glStencilMask(mask)

  • Changes which stencil bits affected

glStencilOp(sfail,dfail,dpass)

  • sfail: stencil test fails
  • dfail: stencil test passes,

depth test fails

  • dpass: both stencil and

depth tests pass Operations:

  • GL_KEEP: Keep current value
  • ZERO: Stencil = 0
  • REPLACE: Stencil = value
  • INCR: Stencil++
  • INCR_WRAP: incr mod 2n-1
  • DECR: Stencil--
  • DECR_WRAP: decr mod 2n-1
  • INVERT: Xor w/ 2n-1 -1
slide-3
SLIDE 3

Shadows enhance realism

and

give important positional cues

slide-4
SLIDE 4

Shadow Buffer Problems

  • Shadow maps

– resolution issues

  • Dynamic

– lights – occluders – receivers

slide-5
SLIDE 5

Stenciled Shadow Volumes

  • 1. Render scene geom. into

frame and z-buffer

  • 2. Render front faces of SV,

incrementing stencil when they pass the z-test

  • 3. Render back faces of SV,

decrementing stencil when they pass the z-test

  • 4. Pixels with stencil = 0 are

lit, rest shadowed

Z-pass [Heidmann '91]