Sign in to follow this  
famous

setting up samplers

Recommended Posts

hi, I'm just wondering about how to setup those samplers. Nearly any GLSL tutorial has tons of code examples about the fancy stuff you can do with those but none of them shows how to setup your sampler and pass it to the shader. I wanna use Parallax Occlusion Mapping with Shadow Maps so in my Fragment Shader I use the function vCurrSample = shadow2DGradARB(ShadowSampler, vec2(gl_TexCoord[0]) + vCurrOffset, dx, dy); Can anyone explain me what I have to do to setup and pass my sampler from the GL app?

Share this post


Link to post
Share on other sites
Thanks, this really helped a lot. There are still some things I don't get, though.

What I wanna do is calculate new views from existing parallel projected shadow maps. To do so I have to sample a depth map and do some shader calculations on it.

Now lets say I have a depth texture that was created by someone else so I have no idea which format it has. How can I find this out so that I know which texture format to use (GL_DEPTH_COMPONENT16 or GL_DEPTH_COMPONENT24 or ...)

The next thing is that I don't understand what the depth comparison during texture access is used for. The orange book says:

"Use texture coordinate coord to do a
depth comparison lookup on the
depth texture specified by sampler.
The third component of coord (coord.p)
is compared to the value read from
the depth texture."

So it compares the value and what is the result then? Why would you ever wanna compare depth values during texture lookups? I'm pretty sure I don't need this for my problem so do I have to always input a coord.p that is always lower than the depth value in the shadow map so that it will always return the depth value of the shadow map?

And what about the proj versions of texture lookups? Again the orange book says they project a texture onto an object (useful for computing shadow maps) but why would I ever wanna project an existing texture during a lookup?

Share this post


Link to post
Share on other sites
Depth texture comparisons are for shadow maps. You don't need a comparison, so you can disable it (Using a normal sampler2D instead of a sample2DShadow).

Projections for projective textures, and again, if you don't need them, just don't bother with it.

Share this post


Link to post
Share on other sites
Quote:
Original post by HuntsMan
Depth texture comparisons are for shadow maps.


I'm using shadow maps, though, or do you mean for shadow map creation only?

Quote:
Original post by HuntsMan
Projections for projective textures, and again, if you don't need them, just don't bother with it.


Yeah, the thing is that as long as I don't understand what it's for I can't be sure whether or not I need it and right now I can't imagine an application of textures with depth comparison or projective textures.

I mean, this is a texture lookup so why would you ever wanna get non deterministic results which is what happens if you use depth comparison?

Share this post


Link to post
Share on other sites
No, shadow mapping does a depth comparison between the sample from the depth texture, and the depth of the fragment, so you know if you are in shadow or not.

So, the texture comparison you see in the texture sample functions are exactly to do that.

Share this post


Link to post
Share on other sites
Quote:
Original post by famous
Now lets say I have a depth texture that was created by someone else so I have no idea which format it has. How can I find this out so that I know which texture format to use (GL_DEPTH_COMPONENT16 or GL_DEPTH_COMPONENT24 or ...)

Where is the depth texture located? On the hard disk? In RAM?
If it is in a file, then the file should contain the format information.
If it is in RAM, you need a variable, something like
int myformatIs=GL_DEPTH_COMPONENT16;
unsigned short *depthBuffer=xxxxx;

Quote:
Original post by famous
So it compares the value and what is the result then? Why would you ever wanna compare depth values during texture lookups? I'm pretty sure I don't need this for my problem so do I have to always input a coord.p that is always lower than the depth value in the shadow map so that it will always return the depth value of the shadow map?

I believe you need to setup your texture with
glTexParameteri(GLTextureType, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
glTexParameteri(GLTextureType, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri(GLTextureType, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

and when you declare your sampler as sampler2DShadow, it compares the r component of your str with the texel in your shadow map and if it is LEQUAL, then the result is 1.0 (meaning not in shadow).
If it is greater, then that pixel is in shadow, in other words, result is 0.0.
You always get 0.0 or 1.0.

If you make the texture with
glTexParameteri(GLTextureType, GL_TEXTURE_COMPARE_MODE, GL_NONE);
and you also use sampler2D, then no comparing takes place. The GPU erads the texel, normalizes it, and gives it to you. In other words, texture2D(mytexture, mycoord) gives a value from 0.0 to 1.0 for all 4 components.

Quote:
Original post by famous
And what about the proj versions of texture lookups? Again the orange book says they project a texture onto an object (useful for computing shadow maps) but why would I ever wanna project an existing texture during a lookup?


That's what I would use if I had a spot light. Explaining it would be too long but it is related to the need for a perspective divide (divide by q)

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