I am trying to use the layered textures. As mentioned in the documentation I used RT_BUFFER_LAYERED along with RT_BUFFER_INPUT flag while create the buffer (3D buffer, layers of 2D textures). When I am trying to access texture values in a program always a 0 is returned. Here is the code for creating the texture.
optix::Buffer specularTexBuffer = context->createBuffer(RT_BUFFER_INPUT | RT_BUFFER_LAYERED, RT_FORMAT_FLOAT, texture_dimensions.x, texture_dimensions.y, 14);
data = (float*)specularTexBuffer->map();
specularTextureFile.read((char*)data, sizeof(float)*texture_dimensions.x*texture_dimensions.y*14);
specularTexBuffer->unmap();
data = NULL;
specularTextureFile.close();
//setting specular texture sampler
optix::TextureSampler specularTex = context->createTextureSampler();
specularTex->setWrapMode(0,RT_WRAP_CLAMP_TO_EDGE);
specularTex->setWrapMode(1,RT_WRAP_CLAMP_TO_EDGE);
specularTex->setWrapMode(2,RT_WRAP_CLAMP_TO_EDGE);
specularTex->setFilteringModes(RT_FILTER_LINEAR, RT_FILTER_LINEAR, RT_FILTER_NONE);
specularTex->setIndexingMode(RT_TEXTURE_INDEX_ARRAY_INDEX);
specularTex->setReadMode(RT_TEXTURE_READ_ELEMENT_TYPE);
specularTex->setMaxAnisotropy(1.f);
specularTex->setMipLevelCount(1u);
specularTex->setArraySize(1u);
specularTex->setBuffer(specularTexBuffer);
Here’s how I declare the texture in the program and how I access it
rtTextureSampler<float, 3, cudaReadModeElementType> specular_texture;
......
.....
//Code for fetching
tex3D(specular_texture, 0,0,0); //Always returns 0 for all coordinates
I have another doubt regarding rtTexD class of functions, how are they different from texD functions and when is it appropriate to use them?