0
\$\begingroup\$

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.

I made a test in the two shaders. Both in the fragment shader.

In first shader, I gave

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

In second shader:

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.

In first shader, I gave

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

In second shader:

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.

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

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.

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.