View Full Version : texture2D/texture2DProj

08-26-2007, 02:21 PM
shouldn't this:

float GetShadow( sampler2D shadowmap, vec4 projection )
return texture2DProj( shadowmap, projection ).r;
}give the same result as this?

float GetShadow( sampler2D shadowmap, vec4 projection )
return texture2D( shadowmap, projection.xy /projection.w ).r;
}first one works fine for my shadow mapping shader, second one does not.

08-26-2007, 03:09 PM
If you are trying to use builtin shadowmap comparisons (TEXTURE_COMPARE_MODE) then both functions are wrong because they are using incorrect sampler type and sampling instruction (the correct are sampler2DShadow and shadow2D(Proj)) so theirs results are undefined. This is likely what you are seeing. In the first case the hw will by accident get correct data (the depth coordinate from projection.z) to perform the comparison. (I assume that you have Nvidia cards which supports that comparison in hw).

If you really use ordinary textures, both functions should give the same result.

08-26-2007, 04:33 PM
My guess is that he's using VSMs and just looking for a sample from a depthmap for debugging purposes; or perhaps he's trying to perform his own PCF. Heck, maybe he's just rendering a spotlight and has a strange function naming convention, or he's cleverly generalized his shadow and projective texture functionality.

Perhaps it's something far more vexing ;-)

I guess we'll never really know for sure until he's good enough to volunteer with some more information.

08-27-2007, 01:15 AM
komat is right, i forgot to switch to sampler2DShadow and shadow2DProj as it was working anyway. thank you guys.