# Thread: Sampling imageCube using direction vector

1. ## Sampling imageCube using direction vector

Hello,

I'm currently working on a compute shader to render a large number of point lights. Additionally, I want as much point lights as possible to cast shadows. For this purpose, I decided to use an array of bindless images (more specifically, an array of imageCube's, each containing the 6-faces-depth-map of a point light). To read depth values from those images, I need to use the imageLoad(gimageCube, ivec3) function. However, this function requires an ivec3 consisting of two texel coordinates and an index determining the face of the cube. Previously, when I was using samplerCube, I could easily use the direction vector from the point light to the fragment to get the corresponding depth value of the depth cube map. Now I need a way to convert this direction vec3 into the ivec3 described above. Can you give me some hints how to approach this? I'm looking for an efficient way as complex plane-line intersections tests are probably redundant.

Thanks for your help!

2. The way to approach this is to... not use image load/store. If you want to read from a cubemap like a cubemap, you use a sampler, not an image.

Compute shaders can use samplers, just like any other shader stage. Bindless texture works with samplers just as well as image load/store. So just use the tool that does the thing you want.

3. Originally Posted by It'sMika
Previously, when I was using samplerCube, I could easily use the direction vector from the point light to the fragment to get the corresponding depth value of the depth cube map. Now I need a way to convert this direction vec3 into the ivec3 described above. Can you give me some hints how to approach this?
The face is determined by which of the three components have the largest magnitude, and its sign. Dividing the other two components by the largest gives values in the range [-1,1], so add 1 and divide by 2 to get s,t in the range [0,1]. Which spatial coordinate maps to which texture coordinate and the directions depend upon the face. The details are all in §8.13 of the specification.

In terms of efficiency, it might be faster to just have a usamplerCube containing the mapping. Or possibly a 1x1x1 usamplerCube containing the face index, with the rest performed in code.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•