0

I am not able understand how to use sampler2DAprrayShadows and how it works. Got some part of it that we need to use depth texture values (GL_DEPTH_COMPONENT) to get the compare result with ref depth. But then how to use the return float value to get the texel.

Got reference from : http://www.khronos.org/opengles/sdk/docs/manglsl/xhtml/texture.xml

I have written a small code to test it as below: My fragment shader as:

in highp vec2 texcoord;
in highp vec4 basecolor;
out highp vec4 myFragColor;

uniform highp sampler2DArrayShadow basetexture;

void main(void)
{
    highp vec3 coords = (vec3(texcoord, 0.0) + vec3(1.0, 1.0, 1.0)) / 2.0;
    highp float depth = texture(basetexture, vec4(coords.x, coords.y, coords.z, -0.5));
    myFragColor = vec4(depth * basecolor);

}

Created 3D texture (texdata), and binding it as :

glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE,  GL_COMPARE_REF_TO_TEXTURE);
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT16, TEX_SIZE, TEX_SIZE, TEX_SIZE, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, texdata);
genpfault
  • 51,148
  • 11
  • 85
  • 139
user1896853
  • 107
  • 1
  • 9
  • 1
    You can't do this in OpenGL ES 2.0 – Kimi Jan 10 '13 at 14:44
  • Your question has been answered on the OpenGL forum http://www.opengl.org/discussion_boards/showthread.php/180780-How-does-sampler2DArrayShadow-in-glsl-works – wip Apr 02 '13 at 08:56

1 Answers1

1

maybe this could help you: depth cubemap make tutorial

And to be frank, you're supposed to make a frame buffer object which binds a 2D depth texture instead of a Cubemap one. If you want to use sampler: sampler2DArrayShadow, then you just need to overload the glsl function texture, which is texture( Sampler2DArrayShadow gSampler, Vec4 P, [float bias]) .P.z is the number of the 2D tex, and P.w is the reference depth value. The default bias is 0, you can ignore it if don't need one.

lushl9301
  • 27
  • 1
  • 7
  • Please write here the solution instead of including a link that could be broken in the future. Thanks! – Ignacio Ara Apr 26 '18 at 09:02
  • @IgnacioAra That's a SO link and the linked post is unlikely to get deleted (only moderators could do that, and they won't). – Filnor Apr 26 '18 at 09:17
  • This should be a comment, not an answer. If it is a duplicate question, [vote to close](http://stackoverflow.com/help/privileges/close-questions) as such and/or leave a comment once you [earn](http://meta.stackoverflow.com/q/146472) enough [reputation](http://stackoverflow.com/help/whats-reputation). If not, tailor the answer to this specific question. – Filnor Apr 26 '18 at 09:17