setting up samplers

Started by
5 comments, last by V-man 14 years ago
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?
Advertisement
Try this
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?
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.
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?
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.
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)
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement