Anyone have success with arrays of samplerCube's in GLSL?

Started by
1 comment, last by L. Spiro 9 years, 2 months ago

Previously, I had an issue with trying to get point light shadow maps to work inside of a shader. Me and L. Spiro were going around in circles over this, in this topic I wrote: http://www.gamedev.net/topic/665281-very-strange-glsl-problem-objects-not-rendering-when-accessing-shadowmaps/

I was just trying to send an array of shadowMaps to and array of samplerCubes like so:


uniform samplerCube shadowCubeMaps[8];

But apparently, this resulted in glitches. I changed it to a non-array for only one shadow map, and it worked. But the question is, is it possible to get samplerCube arrays to work? It's probably not a bit deal, since I can just:


uniform samplerCube shadowCubeMap1;
uniform samplerCube shadowCubeMap2;
uniform samplerCube shadowCubeMap3;
...etc

but, that could become tedious the more lights you want to add.

I swear I was sending the cubemap to GLSL correctly:


location = glGetUniformLocation(currentShader, "shadowCubeMaps[0]");
	glUniform1i(location, 12);
glActiveTexture(GL_TEXTURE0 + 12);
        
glBindTexture(GL_TEXTURE_CUBE_MAP, lightComponents->at(0).lock()->GetShadowMap());

but apparently, glsl doesn't seem to like this.

View my game dev blog here!

Advertisement

I once did a first implementation with map1, map2, map3 and so on and changed it later to use an array texture. Is this an alternative for you? Once I got them wrapped, I liked array textures very much. Keep in mind that you can't place different sized textures in an array texture - they must all have the same dimensions, types etc. Right before this approach I was able to use a sampler array and it worked, too - but I had to use indices from a texture which aren't opaque.

So in your case, can you be sure that "glGetUniformLocation(currentShader, "shadowCubeMaps[0]")" returns a valid value? Can you be sure that your shadow map is valid, too? And when you change your shader code and set the first sampler array element to 12 hardcoded (with your shadowmap correctly bound), does this change anything? Can you make sure, that you don't have some other sampler object bound to your texture units?

If all of my hints were useless, could you explain what kind of "glitches" you get? Maybe you can give us a fullscreen output of the values of your shadow map with a hardcoded index value or something.

Section 4.1.9 of the GLSL specification states, “All types (basic types, structures, arrays) can be formed into an array.”

Now that you know that, forget about it. Since Khronos doesn’t force vendors to adhere to a strict set of guidelines and issue official certificates of quality, there are bugs upon bugs in every version of OpenGL by every vendor.

Adreno cards don’t return the “[0]” part when you enumerate the names of shader uniforms.

Some cards don’t accept “shadowCubeMaps[0]” but might accept “shadowCubeMaps” when you call ::glGetUniformLocation().

Some cards are pickier with sampler arrays than with other types of arrays—they will let you access them via constant integers but not via variables (you can’t dynamically loop over them).

You may as well get accustomed to pre-processing your GLSL files in order to be able to handle issues such as these, but also #include, permutations, etc.

With even a very primitive pre-processing step in place you can easily generate—at run-time—macros to help you get around these kinds of bugs.

With a variable inside your engine you can automatically generate a set of macros that, when used in your shaders, expands to the correct number of samplers, along with macros for using those samplers, etc.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement