Does anyone have or know of a generic shadowmapping shader? I'm looking at providing an alternative to stencil shadows, and I think shadowmapping is probably the way to go. Preferably it should be something simple and fast. No penumbral wedges and all that, that's overkill. I don't even need any gaussian blurring. I just want something which is as fast as possible as a fallback for cards which are slow with stencil volumes.
Generic Shadowmapping Shader?
Miscellaneous Forums/General Discussion/Generic Shadowmapping Shader? in the tutorials section of the ogre wiki theres an article about doing your own shader based shadow mapping with source. Might be a usefull place to check out.
The monster shader is cool too and has flags for toggling many different features.
http://www.ogre3d.org/wiki/index.php/Custom_Shadow_Mapping
The monster shader is cool too and has flags for toggling many different features.
http://www.ogre3d.org/wiki/index.php/Custom_Shadow_Mapping
Yeah, I have a good book on HLSL shader programming and it has a chapter on shadowmapping. At this point though, I'm looking for something which is complete and ready to use. I need to focus my efforts on things I can't get elsewhere, so I'll only be writing shaders I can't get elsewhere. I think ( though I could be wrong ) that a shadowmapping shader which works with pretty much any engine ought to be pretty possible.
There are several things to consider:
- Which shader language
- Which format should the rendertarget be in
- Which light types should it support
- How are light positions and matrices (projection etc) supplied
- How should it be integrated with the remainder of the shaders?
It is unlikely you can find a shader that plugs in to which ever engine you are using without modifying it slightly. The biggest issue is how it's integrated with the rest of the shaders, the other stuff is more or less generic.
And in general stencil shadows are more widely supported, and do not rely on shaders. Neither does shadow mapping, really, but it requires a more recent graphics card.
- Which shader language
- Which format should the rendertarget be in
- Which light types should it support
- How are light positions and matrices (projection etc) supplied
- How should it be integrated with the remainder of the shaders?
It is unlikely you can find a shader that plugs in to which ever engine you are using without modifying it slightly. The biggest issue is how it's integrated with the rest of the shaders, the other stuff is more or less generic.
And in general stencil shadows are more widely supported, and do not rely on shaders. Neither does shadow mapping, really, but it requires a more recent graphics card.
There are several things to consider:
Yes, I realise that. I'm not ( at this point ) asking anyone to go off and write it, so I would have a bash at using anything, then if I can't find anything, I will either write one myself or find someone who would be prepared to write one cheaply. At that point, I would obviously be precise about exactly what I want, because I'd be paying for it. At this point, I didn't want to be too specific and avoid people posting something I might be able to adapt easily.
However, since you asked..
- Which shader language
HLSL or ASM is fine. IE: .FX files.
Which format should the rendertarget be in
I generally use rendertargets in A8R8G8B8 format, but I expect I could convert if necessary.
- Which light types should it support
Well again, I can't afford to be fussy at this point. Point, Directional, even spot would probably be fine. Ideally, I suppose a point light makes most sense.
How are light positions and matrices (projection etc) supplied
That really doesn't matter. As long as there's an explanation of what info needs to be supplied, I'm certain I could supply it as vectors, matrices or whatever.
- How should it be integrated with the remainder of the shaders?
I'm not entirely sure what you mean. I can't think of any way it would affect other shaders. Obviously a shader applied to a mesh has to include whatever lighting, etc you're using on similar meshes which don't have this shader or it won't be lit, etc. But I'm not sure what considerations there would be with a shadowmapping shader.
And in general stencil shadows are more widely supported, and do not rely on shaders.
Yes, I know. They're real slow on animated meshes even in hardware though, and in software they're really, really slow. I'm under the impression that shadowmapping is often faster on animated meshes, though I could be wrong.
The issue with shader integration is that it, in order to be generic, needs to be merged with the other shaders. Otherwise you would get, either completely black shadows, or shadows with the wrong materials (shaders/textures) in the shadowed areas.
You can find examples on nVidia's developer website, which should be straightforward to integrate.
You should note that unless you do some filtering shadow maps generate pixelated shadows, which depending on rendertarget resolution can be severe. In addition point lights require either a very big rendertarget or six seperate rendertargets to produce good results. If you wish to use an A8R8G8B8, you need to pack and unpack the depth in the pixel shader (which isn't a biggy).
Yes, shadow mapping is mostly a better and faster choice, but it does have drawbacks.
You can find examples on nVidia's developer website, which should be straightforward to integrate.
You should note that unless you do some filtering shadow maps generate pixelated shadows, which depending on rendertarget resolution can be severe. In addition point lights require either a very big rendertarget or six seperate rendertargets to produce good results. If you wish to use an A8R8G8B8, you need to pack and unpack the depth in the pixel shader (which isn't a biggy).
Yes, shadow mapping is mostly a better and faster choice, but it does have drawbacks.
I was actually thinking of just pure black shadows actually, though I suppose that would be a bit ugly, so I'll give that some consideration, thanks for the tip.
I was concerned about the Nvidia shaders, as I've read that they're not too good on ATI cards, but I'll take another look.
I can probably afford to use a lot of texture memory for these actually. I'm currently planning to use vertex colors instead of lightmaps for everything, although I've not decided if this will be a static or dynamic lighting solution. Either way, since I'm not using lightmaps, I should be able to use high res rendertargets without worrying too much about VRam.
Thanks also for the info about packing and unpacking the depth in the PS. I'll see what other rendertarget formats I can use as well.
I was concerned about the Nvidia shaders, as I've read that they're not too good on ATI cards, but I'll take another look.
I can probably afford to use a lot of texture memory for these actually. I'm currently planning to use vertex colors instead of lightmaps for everything, although I've not decided if this will be a static or dynamic lighting solution. Either way, since I'm not using lightmaps, I should be able to use high res rendertargets without worrying too much about VRam.
Thanks also for the info about packing and unpacking the depth in the PS. I'll see what other rendertarget formats I can use as well.