Skip to main content
gamedev.net
🔒 Locked

Render depthvalues explicitly

Started by Icebraker 3 replies 500+ views
Original Post
Icebraker
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
ade-the-heat
ade-the-heat
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 viewRenderWorld();		// Now that the world is rendered, save the depth values to a textureglBindTexture(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 valuesglColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 



hope this helps
Icebraker
Icebraker
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..
Kalidor
Kalidor
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.
Icebraker
Icebraker
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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.