• Advertisement
Sign in to follow this  

Render depthvalues explicitly

This topic is 4173 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have a shader and a shadowMap as a sampler2Dshadow - input. Now I want to render the depthvalues explicitly, that is I want to get a grey-image which represents the depth-values of my depthtexture, seen from the lightsource. How can I accomplish this? I guess I need to use texture2D as access-function, but how do I get the corresponding coordinates in my fragment-shader? Has anybody done something like this already? any shader-code would be a great help! thanks, Icebraker

Share this post


Link to post
Share on other sites
Advertisement
I had the following bits of a tutorial lying around:


glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

// Render the world according to the light's view
RenderWorld();

// Now that the world is rendered, save the depth values to a texture
glBindTexture(GL_TEXTURE_2D, g_Texture[SHADOW_ID]);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, (int)SHADOW_WIDTH, (int)SHADOW_HEIGHT);

// We can turn color writing back on since we already stored the depth values
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);




hope this helps

Share this post


Link to post
Share on other sites
Well, the problem is that I want to display the depthvalues as greyscale-image on the screen. I already have a depthtexture which is working, But I need direct access to the depthvalues in my shader..

Share this post


Link to post
Share on other sites
Quote:
Original post by Icebraker
Hi,

I have a shader and a shadowMap as a sampler2Dshadow - input. Now I want to render the depthvalues explicitly, that is I want to get a grey-image which represents the depth-values of my depthtexture, seen from the lightsource.

How can I accomplish this? I guess I need to use texture2D as access-function, but how do I get the corresponding coordinates in my fragment-shader? Has anybody done something like this already? any shader-code would be a great help!

thanks,

Icebraker
Yes, you just use the non-shadow texture lookup functions (the depth comparison has to be disabled on the depth texture, otherwise the results of the lookup are undefined, read the GLSL spec). What do you mean by corresponding coordinates? You just use the same coordinates that you would use in a shadow texture lookup function. It is most likely being projected, so you will probably be using texture2DProj.

Share this post


Link to post
Share on other sites
OK, I'm no longer sure that my shader-setup is correct... I am doing the following steps to hand over the shadow-texture:

glActiveTextureARB(GL_TEXTURE0_ARB);

glGenTextures(1, &shadowDepthMap);
glBindTexture(GL_TEXTURE_2D, shadowDepthMap);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_NONE);

// Draw Scene from lightsource

glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, mapSizeX, mapSizeY, 0);

// And in the shader-class
glUniform1iARB(glGetUniformLocationARB(progID, "shadowMap"),0);

I am not sure that the shadowTexture is correctly haded over because I can't read the depthvalues explcitly. Has anybody a texture - and shader-setup code which shaows how shadowmaps are correctly passed to shaders?

Thanks a lot,

Icebraker

[Edited by - Icebraker on September 20, 2006 11:20:06 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement