# Why does texture-sampling only work at (0,0,0)?

I want to save the color of every point of one object in the RWTexture3D(UAV Resource) and transfer them to another object in its shader.

RWTexture3D<float4> gUAVColor;
gUAVColor[uint3(0,0,0)] = float4(1.0f,0.0f,0.0f,1.0f);


Texture3D<float4> gVoxelList;
float4 output = gVoxelList.SampleLevel(SVOFilter, uint3(0,0,0),0);


The result is correct, I got red as the result.

But when I change the code, the texture cant be sampled correctly.

RWTexture3D<float4> gUAVColor;
gUAVColor[uint3(1,0,0)] = float4(1.0f,0.0f,0.0f,1.0f);


Texture3D<float4> gVoxelList;
float4 output = gVoxelList.SampleLevel(SVOFilter, uint3(1,0,0),0);


I only changed the pos which save the red color from uint(0,0,0) to uint(1,0,0), but what I got changed to black, which means it's uncorrect.

If I use gVoxelList[uint(1,0,0)].xyz ,it works.

I have no idea where the mistake will be.

• I'm not familiar with HLSL, but if it's like GLSL, don't the sampling coordinates get multiplied by the texture size? Mar 25 '17 at 7:54
• yes, you are right, same to directx.
– HUAQ
Mar 25 '17 at 10:28

I have found the answer, gVoxelList[texcoord].xyz this texcoord is the same as the texture size. If we have 512x512x512 size 3Dtexture,then the texcoord should be in [0,512] of every axis. The same to function texture.Load(texcoord) .
However, gVoxelList.SampleLevel(Filter, sample_texcoord,0) in sample function, this sample_texcoord should be in [0,1] of every axis. If we have 512x512x512 size 3Dtexture, we should use gVoxelList.SampleLevel(Filter, texelpos/512.0f ,0), texelpos is where each texel is.