<p>You can use <a href="https://www.khronos.org/opengl/wiki/Texture_Storage#Texture_views" rel="nofollow noreferrer">view textures</a> to accomplish what you're talking about. You create a 2D array texture and give it the number of layers you want. This is the base texture.</p>
<p>You can then construct two restricted views of the base texture. The first is a cubemap array texture using layers 0 to <code>lightSourceCount * 6</code>. The second is a 2D array texture using layers <code>lightSourceCount * 6</code> to <code>lightSourceCount * 6 + 4</code>.</p>

CC BY-SA 4.0
2022-03-22T13:32:38.700Z
2022-03-22T13:32:38.700Z
Nicol Bolas
<p>I am using layered rendering for all my light sources to avoid rendering multiple times.
I have <code>lightSourceCount</code> many point lights and one sun, which is implemented as an orthographic light source (due to the large distance).
The sun light should be implemented as cascaded shadow mapping (4 cascades), because I would like to render landscapes.
The shadowmap resolution and format of the point lights and the cascaded shadow maps are equal.</p>
<p>Is it possible to define a GL_TEXTURE_2D_ARRAY with (<code>lightSourceCount</code> * 6 + 4) layers as shadow maps. Render the scenario using layered rendering to fill these shadow maps. And afterwards use the first <code>lightSourceCount</code> * 6 layeres as a GL_TEXTURE_CUBEMAP_ARRAY with <code>lightSourceCount</code> layers within GLSL to be able to use
<code>gvec4 texture(gsamplerCubeArray sampler, vec4 P, [float bias]);</code> while the last 4 layers are able to be used with <code>gvec4 texture(gsampler2DArray sampler, vec3 P, [float bias]);</code>?</p>
<p>If yes, how can I do that? Can I just bind the GL_TEXTURE_2D_ARRAY as a GL_TEXTURE_CUBEMAP_ARRAY?
And use the last 4 layers by binding the same Texture as GL_TEXTURE_2D_ARRAY and access the last 4 layers by using <code>texture(gsampler2DArray sampler, vec3(uvCoordinate, lightSourceCount * 6 + currentTexture))</code>?</p>

<opengl><texture><glsl>
using parts of GL_TEXTURE_2D_ARRAY as GL_TEXTURE_CUBEMAP_ARRAY
Thomas
# using parts of GL_TEXTURE_2D_ARRAY as GL_TEXTURE_CUBEMAP_ARRAY

(Asked by: username_0 on 2022-03-22)

I am using layered rendering for all my light sources to avoid rendering multiple times.
I have `lightSourceCount` many point lights and one sun, which is implemented as an orthographic light source (due to the large distance).
The sun light should be implemented as cascaded shadow mapping (4 cascades), because I would like to render landscapes.
The shadowmap resolution and format of the point lights and the cascaded shadow maps are equal.

Is it possible to define a GL\_TEXTURE\_2D\_ARRAY with (`lightSourceCount` \* 6 + 4) layers as shadow maps. Render the scenario using layered rendering to fill these shadow maps. And afterwards use the first `lightSourceCount` \* 6 layeres as a GL\_TEXTURE\_CUBEMAP\_ARRAY with `lightSourceCount` layers within GLSL to be able to use
`gvec4 texture(gsamplerCubeArray sampler, vec4 P, [float bias]);` while the last 4 layers are able to be used with `gvec4 texture(gsampler2DArray sampler, vec3 P, [float bias]);`?

If yes, how can I do that? Can I just bind the GL\_TEXTURE\_2D\_ARRAY as a GL\_TEXTURE\_CUBEMAP\_ARRAY?
And use the last 4 layers by binding the same Texture as GL\_TEXTURE\_2D\_ARRAY and access the last 4 layers by using `texture(gsampler2DArray sampler, vec3(uvCoordinate, lightSourceCount * 6 + currentTexture))`?

**Tags:** opengl, texture, glsl


---

## 1 answers

### Answer by username_1 on 2022-03-22. Score: 3 | Accepted answer

You can use [view textures](https://www.khronos.org/opengl/wiki/Texture_Storage#Texture_views) to accomplish what you're talking about. You create a 2D array texture and give it the number of layers you want. This is the base texture.

You can then construct two restricted views of the base texture. The first is a cubemap array texture using layers 0 to `lightSourceCount * 6`. The second is a 2D array texture using layers `lightSourceCount * 6` to `lightSourceCount * 6 + 4`.


---

