I’m trying to get free PCF working on my shadows, something that I have heard and read about, but I can’t find any solid info on the specifics.
It seems that most solid info on it is hidden behind broken links (or I REALLY suck at googling)
I’m writing the shaders in CG, not directly in HLSL
First what I’ve read so far:
Sampler/Texture settings:
Some forum(post)s state that simply changing filtering of the depth texture is enough, this doesn’t seem to be true
I have read that the texture format should be DEPTH_STENCIL, some others have stated that it should be DEPTH_COMPONENT or some Nvidia specific format
Combined with above, i could not get any results, and I couldn’t find any reference to a Nvidia specific format.
GLSL:
Some have said Texture2D should be used, some others have said Shadow2D should be used.
Some say a different kind of sampler-type should be used (can’t remember the name by heart atm)
I couldn’t get any code to compile by using above keywords in my shaders, I probably need their CG-coutnerparts, if they exist.
I’m also unclear of how the extra “compare value” should be passed to the sampling instruction (texture2D/shadow2D). Should it be the extra third component of the sampling coord?
I have almost nog OpenGL background, but I do have worked some years with DirectX. On some hardware, Using Tex2D() with a third component (and corret sampler settings) was enough to trigger PCF under DX.
I have tried to use the ARB_Shadow Texure comparison state, (COMPARE_TEXTURE_TO_R) but I couldn’t really get it to work correctly.
I couldn’t make heads or tails of the ARB_Shadow OpenGL Spec for explenation of how the comparison works
(it seems to be doing compare between the (2D?3D?) V coord and the scalar (?) depth value, but I don’t see how that would work)
see: http://www.opengl.org/registry/specs/ARB/shadow.txt
It seems that the COMPARE_TEXTURE_TO_R stuff seems to be ARB_shadow specific, while Shadow2D is part of a later OpenGL spec?
Are some extra extensions needed?
You can do “free” 4-tap PCF shadow mapping using gathered texture fetches (http://www.opengl.org/registry/specs/ARB/texture_gather.txt), however this is only available on DX10.1 class hardware (GeForce 200 series, Radeon HD3000 series).
Actually I know that there was earlier support for 4-tap hardware PCF on both NVIDIA and ATI cards, however I don’t know whether it is exposed in any fashion in OpenGL.
I know it should be possible, I can find some info on it, scattered around the internet, but nothing that I could actually put together to create a working shader.
Oh, and I completely forgot to mention that I use CG, not GLSL. I’ll put it in the OP, since it probably explains some of the issues.
In GLSL, you have to use a sampler2DShadow sampler and pre-GLSL 1.3 a shadow2D* texture access function. In 1.3+, they got rid of the latter and you just use texture*.
Hmm, haven’t done this with CG, but given that others correctly pointed out that with GLSL you need a sampler2DShadow (and possibly the correct texture access function), have you tried CG’s tex2Dcmpbias?
Can’t get it to work, It seems that the CG compiler isn’t outputting the correct GLSL to get the compare-feature activated properly.
I’ll take a closer look later on when I have the tools and the time to go through the GLSL output.