Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Stencil shadow info

Hybrid View

  1. #1
    Member Regular Contributor
    Join Date
    Sep 2002
    Posts
    384

    Stencil shadow info

    From what I gather from the NeHe tutorial, to draw a stencil shadow, you basically just project every edge of the mesh in one direction. If you had a triangle between A, B, and C, you would create a quad out of A and B, and two other vertices offset by the vector of the shadow.

    I'm rather surprised that you actually have to adjust the vertex array in real time. Isn't there a way to do it so that this is automated somehow? Is that really how it is done in Doom 3?

  2. #2
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: Stencil shadow info

    Doom does this in software but it optimizes the resulting beam tree heavily. Also if the light and geometry don't move you don't have to recreate the silhouette.

    It can be done automatically by creating degenerate edges and extruding two of verts into a quad in a vertex program based on normal dot products with view vector from the contributing faces, but this imposes a huge geometric overhead drawing two triangles for every edge in your model, although most are rejected as degenerates there is a significant bandwidth and transformation overhead.

  3. #3
    Member Regular Contributor
    Join Date
    Sep 2002
    Posts
    384

    Re: Stencil shadow info

    but this imposes a huge geometric overhead drawing two triangles for every edge in your model
    Please explain how doing the same in software would not create the same overhead of drawing two triangles per edge.

  4. #4
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: Stencil shadow info

    In software only the silhouette triangles need be sent, but in hardware all degenerate edges must be sent through the vertex program.

  5. #5
    Member Regular Contributor
    Join Date
    Sep 2002
    Posts
    384

    Re: Stencil shadow info

    How do you tell which triangles are silhouette triangles? I suppose you could find the plane equation of each triangle, transform it to camera space, and look for edges that lie between a forward-facing triangle and a backwards-facing one...but I don't really see that operation happening in real-time.

  6. #6
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: Stencil shadow info

    You check adjacent face normals against the view vector.

    In the case of a fragment program you extrude an edge vertex pair or not on the basis of that dot product (there are two vertex pairs per edge with different normals, i.e. two identical edges running in opposite directions forming a degenerate quad with normals from different faces), in the case of software you can know the result for both faces and reject or extrude an edge based on both results.

  7. #7
    Member Regular Contributor
    Join Date
    Sep 2002
    Posts
    384

    Re: Stencil shadow info

    No wonder Doom 3 characters are so low-poly.

    In HL2, did they use stencils or a projected texture?

  8. #8
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: Stencil shadow info

    The issue isn't as straightforward as that. The lighting pass accumulation of Doom3 and the consistent shadow processing made stencils the right choice for that engine. Image based approaches would have had resolution, filtering and performance issues although that's now viable on newer hardware.

  9. #9
    Member Regular Contributor
    Join Date
    Sep 2002
    Posts
    384

    Re: Stencil shadow info

    You know, I could use a super low-poly stencil mesh to cast shadows with. It would cut the processing time down a lot, and would look about the same when projected as a shadow.

  10. #10
    Junior Member Regular Contributor
    Join Date
    May 2005
    Location
    boulder, co
    Posts
    228

    Re: Stencil shadow info

    Low poly shadow meshes have their own problems (bad self shadowing). Don't try to re-figure out everything. Shadow volume techniques are well researched, just read the papers:
    http://developer.nvidia.com/object/r...w_volumes.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •