shadow maps- w/o pixel shaders?

Started by
7 comments, last by superpig 18 years, 8 months ago
WAIT! So can i use shadow map techniques without using a pixel shader? or should i stop being cheap and replace my.. well... geforce.. 2... :\ lol oh, and if i can, how? :)
--Amir
Advertisement

  1. Create a texture using a depth buffer format.
  2. Set level0 of the texture as the depth buffer.
  3. Disable colour writes (probably by setting SRCBLEND=0 DSTBLEND=1).
  4. Render the occluder geometry from the point of view of your light.
  5. Set the depth buffer back to normal and reenable colour writes.
  6. Set texture 0 to the depth buffer format texture.
  7. Set up the texcoord source for stage0 to be the camera-space position.
  8. Set up a texture matrix in stage 0 to transform from camera-space positions to projected light-space positions.
  9. Set up the remaining texture stages to apply your shadow with the appropriate blending.
  10. Sip a large drink with an umbrella in it.


The last step is optional but recommended.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Yeah, you can do shadow mapping without using pixel shaders but you still need (assuming you want proper shadow mapping) a graphics card capable of doing the depth comparison for you. That is still GeForce3 and above as far as I'm aware. Unfortunately, you'll probably find on ATi cards of that generation you can't create a depth texture in Direct3D, at least that was my experience, and I don't know much about OpenGL but your card needs to support the GL_ARB_depth_texture and GL_ARB_shadow (or equivelent) if you want the hardware comparison there.

-Mezz
There's a good demo and explanation here:
http://www.paulsprojects.net/tutorials/smt/smt.html

Its relatively old, so doesn't include use of the frame buffer object extension, which makes shadow mapping easier, i.e. you can drop pbuffers out of the equation, but is still a very good starting point. There is also a demo in the Nvidia SDK, think it also lives somewhere on the developer website as well.
One thing to keep in mind though, is that in a practical game, the cost of generating and rendering the shadow maps will be so great that you'll, more often than not, want to reset your min spec to shader 2.0 class hardware, and that's still while ignoring the low quality that a hardware SM will give most of the time. On that last point, there are exceptions to that rule, such as SimmerD's Ancident Galaxy, but his camera is also a fair distance away from most shadows, so the low quality is not very evident. If you're targeting GF2 hardware, go for shadow volumes, not shadow maps.
Another idea is to use alpha test to do your shadow map comparisons. This gives you 8-bit depth shadows, and can work on very old hw.

This is what I do in my engine, although other features make my engine require gf3+...
thanks for all the replies, i didn't even know there's an animal called texture matrix.

Quote:Original post by superpig

  1. Create a texture using a depth buffer format.
  2. Set level0 of the texture as the depth buffer.
  3. Disable colour writes (probably by setting SRCBLEND=0 DSTBLEND=1).
  4. Render the occluder geometry from the point of view of your light.
  5. Set the depth buffer back to normal and reenable colour writes.
  6. Set texture 0 to the depth buffer format texture.
  7. Set up the texcoord source for stage0 to be the camera-space position.
  8. Set up a texture matrix in stage 0 to transform from camera-space positions to projected light-space positions.
  9. Set up the remaining texture stages to apply your shadow with the appropriate blending.
  10. Sip a large drink with an umbrella in it.


The last step is optional but recommended.


meow, woof.
how does d3d know to take values from the default depth buffer AND the texture and compare them all nicely together?
it just.. knows that?
or am i missing something?
i guess i AM missing something.

--Amir
Lord Gzoo: I think
Quote:Set up the remaining texture stages to apply your shadow with the appropriate blending.
would be where the depth compare is applied, but I'm not sure (I've only done shader-based SMs).
No, this is the special hardware hack that NVidia did back with the GF2 (?). Basically, it detects when you're reading from a depth format texture using a projected 4D coord (x, y, z, w), calculates (x/w, y/w) to do the read, then compares it to (z/w). The final result of the sampling comes out as either 0 or 1 depending on which is higher.

The major downside is that it doesn't work on ATI cards, natch.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

This topic is closed to new replies.

Advertisement