texture2D/texture2DProj

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.

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.

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 :wink:

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

komat is right, i forgot to switch to sampler2DShadow and shadow2DProj as it was working anyway. thank you guys.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.