GLSL sampler2DShadow deprecated past version 120? What to use?

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

I've been trying to implement percentage closer filtering for my shadow mapping as described here Nvidia GPU Gems

When I try to sample my shadow map using a uniform sampler2DShadow and shadow2D or shadow2DProj the GLSL compile fails and gives me the error

shadow2D deprecated after version 120 

How would I go about implementing an equivalent solution in GLSL 330+? I'm currently just using a binary texture sample along with Poisson Sampling but the staircase aliasing is pretty bad.

回答1:

Your title is way off base. sampler2DShadow is not deprecated. The only thing that changed in GLSL 1.30 was that the mess of functions like texture1D, texture2D, textureCube, shadow2D, etc. were all replaced with overloads of texture (...).


Note that this overload of texture (...) is equivalent to shadow2D (...):

float texture(sampler2DShadow sampler,               vec3 P,               [float bias]); 

The texture coordinates used for the lookup using this overload are: P.st and the reference value used for depth comparison is P.r. This overload only works properly when texture comparison is enabled (GL_TEXTURE_COMPARE_MODE == ) for the texture/sampler object bound to the shadow sampler's texture image unit; otherwise the results are undefined.


Beginning with GLSL 1.30, the only time you need to use a different texture lookup function is when you are doing something fundamentally different (e.g. texture projection => textureProj, requesting an exact LOD => textureLod, fetching a texel by its integer coordinates/sample index => texelFetch, etc.). Texture lookup with comparison (shadow sampler) is not considered fundamentally different enough to require its own specialized texture lookup function.

This is all described quite thoroughly on OpenGL's wiki site.



回答2:

You need to use textureProj, which returns a float rather than a vec4. There's a overview of shadow artifacts and solutions (including Poisson sampling) here.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!