I want to offload some 3D calculations to the GPU without raising my requirements to DX10. Specifically, I am generating densities in 64x64x64 3D blocks, which fit nicely into 512x512 2D textures. I would like to be able to convert my float2 texture coordinates to float3 values, so I can offset them, convert back to float2, perform lookups against my randomness texture, and interpolate the results manually.

This has been easy to do with integer values on the CPU side, but the GPU's texture coordinates are all floating points. Is there an easy way to do this? Or is there a way to coax pixel shader 3.0 into using something similar to 3D textures, so I can take advantage of automatic interpolation?

Another caveat is that I am using the Vector4 image format for my render targets (need better resolution in each channel) in XNA, so I am restricted to Point sampling.

  • \$\begingroup\$ You can certainly use volume textures natively in pixel shader 3.0. See this related question. You can't render directly to a volume texture slice, though. (You can in D3D10/11.) At best you can render all the slices to a 2D texture, then lock it and copy the data into the volume texture. Perhaps that would work for your case, though? \$\endgroup\$ Sep 18, 2013 at 21:40
  • \$\begingroup\$ Thank you. I will definitely look into that as referencing a volume texture will cut down on conversion calculations (and hopefully interpolation), but unless I cannot find a way to do it, I still want to convert float2 texture coordinates to float3. I considered rendering to each slice, but I am worried because my engine is continuously pumping out hundreds of these blocks. At 64 slices each, I fear that would become quite a bottleneck and would leave very little room for actual rendering. I would rather let the CPU decode 2D to 3D than run a thousand draw calls per frame. \$\endgroup\$
    – dpaz
    Sep 18, 2013 at 21:58
  • \$\begingroup\$ Well if all you want is to find where you are in a 3D block, based on where you are in the flattened 2D texture, you just have to multiply the texture coordinate by 8 and use frac(). \$\endgroup\$ Sep 18, 2013 at 22:08


You must log in to answer this question.

Browse other questions tagged .