Sign in to follow this  
MARS_999

Shadowmap comparison with GLSL vs FFP

Recommended Posts

Is it possible to get rid of these functions
 glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

and use GLSL to do the same thing instead of using the FFP to do the comparisons? I am guessing it is, but how would you do it? Thanks

Share this post


Link to post
Share on other sites
From the specs:

ARB_depth_texture :

Get Value Type Get Command Initial Value Description Sec. Attribute
-------------------------- ---- -------------------- ------------- -------------- ----- ---------
DEPTH_TEXTURE_MODE_ARB Z_3 GetTexParameter[if]v LUMINANCE depth texture mode 3.8.13 texture

This means that if you don't alter the depth texture mode (GL_DEPTH_TEXTURE_MODE) it will be LUMINANCE (Dt, Dt, Dt, 1).

ARB_shadow :
Quote:
ARB_shadow specs
3.8.13.1 Depth Texture Comparison Mode

If the currently bound texture's format is DEPTH_COMPONENT then
TEXTURE_COMPARE_MODE_ARB, TEXTURE_COMPARE_FUNC_ARB and
DEPTH_TEXTURE_MODE_ARB control the output of the texture unit
as described below. However, if the currently bound texture is
not DEPTH_COMPONENT then the texture unit operates in the normal
manner and texture comparison is bypassed.

Let Dt (D subscript t) be the depth texture value, in the range
[0, 1]. Let R be the interpolated texture coordinate clamped to
the range [0, 1]. Then the effective texture value Lt, It, or At
is computed by


if TEXTURE_COMPARE_MODE_ARB = NONE

r = Dt

else if TEXTURE_COMPARE_MODE_ARB = COMPARE_R_TO_TEXTURE_ARB

if TEXTURE_COMPARE_FUNC_ARB = LEQUAL

{ 1.0, if R <= Dt
r = {
{ 0.0, if R > Dt

else if TEXTURE_COMPARE_FUNC_ARB = GEQUAL

{ 1.0, if R >= Dt
r = {
{ 0.0, if R < Dt

endif

if DEPTH_TEXTURE_MODE_ARB = LUMINANCE

Lt = r

else if DEPTH_TEXTURE_MODE_ARB = INTENSITY

It = r

else if DEPTH_TEXTURE_MODE_ARB = ALPHA

At = r

endif

endif



And the initial values :

Get Value Type Get Command Initial Value Description Sec. Attribute
-------------------------- ---- -------------------- ------------- -------------- ----- ---------
TEXTURE_COMPARE_MODE_ARB Z_2 GetTexParameter[if]v NONE compare mode 3.8.13 texture


This means that if you don't set a texture compare mode, a depth texture read will return (Dt, Dt, Dt, 1) as color.

Of course there may be problems dependant on how the driver implements these things, but i'd expect it to work with GLSL too. I've checked it with ARBfp and it works correctly (i think so at least) (the returned color from a depth texture was actually (Dt, Dt, Dt, 1).

Then you can do whatever you want with this value. Compare it with the R coord maybe? :)

Hope that helps.

HellRaiZer

Share this post


Link to post
Share on other sites
If the depth comparison is turned on, just use the built-in shadow texture look-up functions. It will perform the comparison for you. If the depth comparison is turned off (what I think you're asking about), use the normal texture look-up functions and perform the comparison yourself. You can then use the result of the function however you want. HellRaiZer posted the part of the extension spec that says what R is and the functions used, but the GLSL spec also mentions how to calculate R in the description of the shadow texture functions.

Share this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
Ok, my next question is would the shadow quality be any better having the shader check it vs. the FFP compare mode? Thanks

I think that bilinear depth texture filtering (hardware PCF) works only when the comparison function is COMPARE_R_TO_TEXTURE. So, if you are going to perform only one depth texture fetch in your shaders (with compare mode set to NONE), and of course only one comparison, then i would expect the quality to be worse than FFP (with COMPARE_R_TO_TEXTURE and bilinear filtering).

I think that this works only on nVidia cards (is this true??), so on an ATI one i think the quality should be the same. I'm not really sure about that though.

HellRaiZer

Share this post


Link to post
Share on other sites
Quote:
Original post by HellRaiZerI think that this works only on nVidia cards (is this true??), so on an ATI one i think the quality should be the same. I'm not really sure about that though.
ATI made a big hype about this great new feature when the X1x00 series came out. However, they don't really do any PCF, so they invented a cool new name instead: Fetch4.
If you want PCF, you still have to do it in the shader.

nVidia cards support hardware PCF since...? GeForce3? It's been so long that I hardly remember. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this