PDA

View Full Version : The point of shadow samplers vs regular samplers



mlfarrell
08-12-2014, 03:23 PM
Shadow mapping is the last fronteir for me for modern GL techniques that I'd like to master. Can someone please explain to me why so many of the tutorials I find DON'T use sampler2DShadow

Aren't the shadow samplers better? Can someone explain to me the difference between shadow samplers and regular texture samplers.

Dark Photon
08-12-2014, 05:31 PM
Shadow mapping is the last fronteir for me for modern GL techniques that I'd like to master. Can someone please explain to me why so many of the tutorials I find DON'T use sampler2DShadow

Aren't the shadow samplers better? Can someone explain to me the difference between shadow samplers and regular texture samplers.

The shadow samplers allow you to utilize hardware-accelerated depth comparisons and filtering (e.g. PCF, which is "free" on some GPUs). In other words, with the shadow samplers, the "in shadow" visibility tests and filtering are internalized in the texture lookup from the shadow map. These must be fed textures with a depth component (e.g. base type of GL_DEPTH_COMPONENT or GL_DEPTH_STENCIL), and hardware depth compare must be enabled for the texture.

With the non-shadow samplers, what you get back is the depth values, and you have to do your own filtering. They'll work with depth component textures, but you can feed anything else you want in here instead.

Ed Daenar
08-24-2014, 08:10 AM
On the topic of shadow samplers, what I can't seem to understand is the logic behind the limitation of making shadow samplers only work with depth surfaces. Is this a problem with the hardware implementation? It certainly cannot be that complicated, since it's doing little more than a filtering and compare operation. Yet, this operation still has uses on any other kind of surface; most obvious one is implementing shadow maps with linear values, but there's other more obscure uses one could apply this to.

On nVidia drivers it's possible to use a shadow sampler on a non depth texture and it works as expected (or, at least, as what I'd expect). However, you get the required warning that this is undefined behavior, which is correct based on the GL spec.

So just out of curiosity, is there any good reason for the spec to limit shadow samplers to depth textures?