OpenGL Stencil Buffer Effect

twitterlinkedin

Purpose of the Sample:

Demonstrates how to use the stencil buffer to mask draw calls.  Over time, a portion of the man’s body will be rendered in wireframe.  The effect is achieved like so.

  1. Draw Filled Man
    1. Write 0 to the stencil buffer for each fragment rendered to by the filled man.
  2. Render an invisible quad in front of the man.
    1. Write 1 to the stencil buffer for each fragment rendered to by the quad.
  3. Render the Wireframe Man
    1. Only display the wireframe man where the stencil buffer value is 1 which is wherever the quad was rendered.

Download RenderDoc Frame Capture

Captured with RenderDoc Version 1.2 (x86) (x64)

CGame.h

CGame.cpp

vertexPass0.glsl – Draw the Filled Man

fragmentPass0.glsl – Shade the Filled Man with his Normals

vertexStencil.glsl – Render the Quad Mask

fragmentStencil.glsl – Render the Quad Mask

vertexPass1.glsl – Render the Wireframe Man

fragmentPass1.glsl – Render the Wireframe Man

Download Sample App

twitterlinkedin
Share It!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.