<p>In GLSL, cubemaps within a shader can be read with</p>
<pre><code>gvec4 texture(gsamplerCube sampler,
    vec3 P,
    [float bias]);
</code></pre>
<p>so a direction is used. How can the direction vector <code>P</code> be converted to layer number and uv coordinates of the cubemap and vice versa?</p>

CC BY-SA 4.0
2024-10-16T15:25:14.333Z
https://www.khronos.org/opengl/wiki/Cubemap_Texture#Upload_and_orientation
Kevin Reid
CC BY-SA 4.0
2024-10-16T19:35:13.850Z
Thank you first, I assume that the absolute highest of the 3 values of the direction vector represents the layer number as follows: 
PositiveX -> layer 0,
NegativeX -> layer 1,
PositiveY -> layer 2,
NegativeY -> layer 3,
PositiveZ -> layer 4,
NegativeZ -> layer 5
Thomas
CC BY-SA 4.0
2024-10-16T19:37:40.547Z
But how does the UV mapping work?
Thomas
<opengl><glsl><vulkan>
Conversion of the Cubemap direction access vector to UV coordinates
Thomas
# Conversion of the Cubemap direction access vector to UV coordinates

(Asked by: username_0 on 2024-10-16)

In GLSL, cubemaps within a shader can be read with

```
gvec4 texture(gsamplerCube sampler,
    vec3 P,
    [float bias]);

```

so a direction is used. How can the direction vector `P` be converted to layer number and uv coordinates of the cubemap and vice versa?

**Tags:** opengl, glsl, vulkan

> **Comments:**
> **username_1**: https://www.khronos.org/opengl/wiki/Cubemap_Texture#Upload_and_orientation  
> **username_0**: Thank you first, I assume that the absolute highest of the 3 values of the direction vector represents the layer number as follows:  PositiveX -> layer 0, NegativeX -> layer 1, PositiveY -> layer 2, NegativeY -> layer 3, PositiveZ -> layer 4, NegativeZ -> layer 5  
> **username_0**: But how does the UV mapping work?  

---

## 0 answers

