Submitted by , posted on 26 September 2000



Image Description, by


Here's a screenshot from my contest entry for the Lights & Shadows contest here on Flipcode. I'm uploading it later tonight, so hopefully you can download it from www.flipcode.com/contest soon. I still have work to do, but I wanted to get it out there and see what folks had to say about it.

The technique that I'm using is shadow-mapping and goes something like this.

--during load time (or whenever really)
for each spotlight
    attach shadow casters
    attach shadow receivers
next
 
for each frame 
    for each spotlight
        calc view matrix from light
        render shadow-casting meshes (white on black) 
        blit result into shadow-map texture
    next
    for each mesh-in-scene
        render as usual
    next
    enable alpha blending and setup blend modes
    for each spotlight
        for each shadow receiver
            render using shadow-map texture for this spotlight
        next
    next
next
Shadow-mapping isn't perfect, but it is well-suited for demo work...

Pro's:
  • Very clean implementation
  • Will work on nearly all recent consumer hardware
  • Ideal application of multi-texturing
  • Con's:
  • Shadow-casting meshes cannot self-shadow, so you have to be careful when picking which objects to use as casters. However, Mark Kilgard has extended the technique to use depth-mapping to achieve self-shadowing using Nvidia register combiners with OpenGL. I'm not doing that...yet. 8)
  • Shadows are blocky unless you use insanely large shadow maps. -- I use 128x128
  • If the hardware doesn't support render-to-texture, then it's much SLOWER!
  • Eats fill rate like it's going out of style
  • "D3D" and "rendering to textures" aren't friendly with one another
  • The technique is covered in Game Programming Gems by Mark Deloura, ISBN: 1584500492 --- I highly recommended this book.

    Hope you like my demo.

    Alan Gordie
    alan.gordie@computer.org
    http://gordie.editthispage.com/



    [prev]
    Image of the Day Gallery
    www.flipcode.com

    [next]


     


    Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
    Please read our Terms, Conditions, and Privacy information.