Hi!
I’m trying to access an environment cubemap loaded into a 2d texture from cuda, but currently I’m entirely clueluess how i should start with that.
I appreciate any input and best regards,
Mike
Hi!
I’m trying to access an environment cubemap loaded into a 2d texture from cuda, but currently I’m entirely clueluess how i should start with that.
I appreciate any input and best regards,
Mike
You’re trying to access a cubemap texture? You’ll probably have to implement the texture fetch by hand - you’d have to map each face of the texture as a separate CUDA texture, and use something like the algorithm in the OpenGL specification (Rasterization / Texturing / Cube Map Texture Selection). An alternative would be to put the cubemap into a 3 layer tex3D, which would clean up the texture selection, I think.
Here’s some code I wrote a while ago to emulate cubemap textures in CUDA using a 2D texture with the faces packed vertically. Note that this code doesn’t handle filtering (you would need to add borders around each face).
If you would like real cubemap textures in CUDA please reply to this thread.
texture<float4, 2, cudaReadModeElementType> cubeTex;
// calculate face and coordinates for cubemap lookup
__device__
void indexCubeMap(float3 d, int *face, float *s, float *t)
{
float3 absd;
float sc, tc, ma;
absd.x = fabs(d.x);
absd.y = fabs(d.y);
absd.z = fabs(d.z);
*face = 0;
if ((absd.x >= absd.y) && (absd.x >= absd.z)) {
if (d.x > 0.0f) {
*face = 0;
sc = -d.z; tc = -d.y; ma = absd.x;
} else {
*face = 1;
sc = d.z; tc = -d.y; ma = absd.x;
}
}
if ((absd.y >= absd.x) && (absd.y >= absd.z)) {
if (d.y > 0.0f) {
*face = 2;
sc = d.x; tc = d.z; ma = absd.y;
} else {
*face = 3;
sc = d.x; tc = -d.z; ma = absd.y;
}
}
if ((absd.z >= absd.x) && (absd.z >= absd.y)) {
if (d.z > 0.0f) {
*face = 4;
sc = d.x; tc = -d.y; ma = absd.z;
} else {
*face = 5;
sc = -d.x; tc = -d.y; ma = absd.z;
}
}
if (ma == 0.0f) {
*s = 0.0f;
*t = 0.0f;
} else {
*s = ((sc / ma) + 1.0f) * 0.5f;
*t = ((tc / ma) + 1.0f) * 0.5f;
}
}
// lookup in cubemap stored in 2D texture
__device__
float4 texCUBE(float3 d, int size)
{
int face;
float s, t;
indexCubeMap(d, &face, &s, &t);
int x, y;
x = s * size;
y = (face * size) + (t * size);
return tex2D(cubeTex, x, y);
}
Thank you for your hints. And i thought about doing the very same. But …
real cubemap textures would be absolutely awesome.
Regards,
Mike