Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Good afternoon,

I am looking 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.

share|improve this question
    
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? –  Nathan Reed Sep 18 '13 at 21:40
    
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. –  dpaz Sep 18 '13 at 21:58
    
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(). –  Nathan Reed Sep 18 '13 at 22:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.