Jump to content
  • Advertisement
Sign in to follow this  
myers

Depth reads and comparisons in the same shader

This topic is 3799 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

Is there a neat way to read depth from a depth texture while also, in the same shader, performing a depth comparison? As I understand it, HLSL has separate functions to do these things (Sample and SampleCmp respectively), but in GLSL we only have shadow2D and texture2D. We can, of course, access the depth texture as a sampler2D and then do the comparison manually:
float depth = texture2D(depthtex, texcoord).r;
float comparison = float(depth>texcoord.z);


But then we lose the hardware PCF that we get on Nvidia with shadow2D. So is there a way to retain this if we need both the depth value and a depth comparison?

Share this post


Link to post
Share on other sites
Advertisement
You can bind the sample texture to another sampler


uniform sampler2D depthtex;
uniform shadow2D depthtex2;

float depth = texture2D(depthtex, texcoord).r;

float depth2 = shadow2D(depthtex2, texcoord).r;

Share this post


Link to post
Share on other sites
I considered doing that, but wasn't sure about what value to use for the texture's GL_TEXTURE_COMPARE_MODE: I recalled reading somewhere that using texture2D to sample a texture with comparison mode GL_COMPARE_R_TO_TEXTURE is undefined. And sure enough, the second-last post on this thread says just that.

Having said that, it does seem to work for me. But if that thread is to be believed, this is not legal OpenGL. Do you know if what the poster on that thread says is correct? Is this something that may not work on other GL implementations?

Share this post


Link to post
Share on other sites
Uh, scratch that. It doesn't actually work after all. It seems sampling from a texture with texture2D and comparison mode set to GL_COMPARE_R_TO_TEXTURE always just returns 1. :(

Share this post


Link to post
Share on other sites
I'm trying to implement a PCSS variant, and I suspect copying every shadow map every frame would negate any performance benefit I'd get, to say nothing of the memory cost. Bah.

Perhaps anyone who's implemented PCSS could tell me: is it possible to use hardware PCF with it? If so, how do you perform the blocker search on a texture that only allows comparisons, not sampling?

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!