Jon
18-05-2007 23:01:04
While I'm not quite to the point of admitting defeat when it comes to variable sized textures and indexed splatting, I am taking some time to implement the volume texture approach.
256x256x256 RGBA should take about 64M of texture memory. And while this number of textures is excessive, it does seem quite doable on a variety of cards.
Somewhere along the line I decided I probably could do quite well with 256x256 textures, and the time to think about that restriction is after this splatting mode is working.
Now that the explanation of what and why is out of the way, I am running into problems with the volume textures. Given that I have no experience with them, this is expected, but I am hoping that someone will see the error of my ways.
The texture file is made from 16 png images, 256x256. I am using nvdxt to create a DDS file which looks fine when examined with the DirectX Texture Tool (from the SDK). Fine meaning there are 16 slices, and DXT5 compression is being used. I can move from slice to slice, and the textures are correct. (Note: for simplicity, the textures are uniform colors so I can tell what slice is being sampled).
Even better news is that when I use PIX to capture a frame, I can see the texture unit being loaded, and the texture attributes are correct. (Note: getting everyone to stop making mipmaps was a gotcha). Here is a screenshot from PIX so we can see what DirectX has loaded:
![](http://home.comcast.net/~jondoran/pix_screen.png)
Note also: PIX has some nice features. Being able to browse the textures, and showing the floating point coordinates in the toolbar is an unexpected bonus.
So what happens? The wrong color is being returned by the fragment program, which in turn means the wrong color is being returned from the tex3D lookup. Now I cheated a little, and forced (0,0,0) as the volume coordinate to sample. That should be guaranteed to be a valid point, and a corner of the volume. Given uniform colors for the slices, there are only two colors which can be returned no matter how the volume is rotated.
The problem is: I get some oddball gray which is not in any of the slices, and certainly not the blue or yellow which are the first and last slices.
Ogre is loading the volume correctly, it is assigned to the correct sampler. The (0,0,0) coords are in fact being used for the lookup.
So I conclude that my understanding of what tex3D wants to see in a volume texture is wrong. Any suggestions?
Edit: of course the minute I post this I have a brainstorm and may have fixed things. Two problems:
1) I was missing the "tex_address_mode clamp" in the material for the volume
2) There appears to be an interpolation between slices, so an offset needs to be added to Z so that the height is midway between slice boundaries. For 16 slices, to get to slice 2 Z will be 1/16+1/32. The floating point color values are a little off, but the integer values look fine.
Time to investigate more complex textures to see if this interpolation is going to continue to be a problem.
256x256x256 RGBA should take about 64M of texture memory. And while this number of textures is excessive, it does seem quite doable on a variety of cards.
Somewhere along the line I decided I probably could do quite well with 256x256 textures, and the time to think about that restriction is after this splatting mode is working.
Now that the explanation of what and why is out of the way, I am running into problems with the volume textures. Given that I have no experience with them, this is expected, but I am hoping that someone will see the error of my ways.
The texture file is made from 16 png images, 256x256. I am using nvdxt to create a DDS file which looks fine when examined with the DirectX Texture Tool (from the SDK). Fine meaning there are 16 slices, and DXT5 compression is being used. I can move from slice to slice, and the textures are correct. (Note: for simplicity, the textures are uniform colors so I can tell what slice is being sampled).
Even better news is that when I use PIX to capture a frame, I can see the texture unit being loaded, and the texture attributes are correct. (Note: getting everyone to stop making mipmaps was a gotcha). Here is a screenshot from PIX so we can see what DirectX has loaded:
Note also: PIX has some nice features. Being able to browse the textures, and showing the floating point coordinates in the toolbar is an unexpected bonus.
So what happens? The wrong color is being returned by the fragment program, which in turn means the wrong color is being returned from the tex3D lookup. Now I cheated a little, and forced (0,0,0) as the volume coordinate to sample. That should be guaranteed to be a valid point, and a corner of the volume. Given uniform colors for the slices, there are only two colors which can be returned no matter how the volume is rotated.
The problem is: I get some oddball gray which is not in any of the slices, and certainly not the blue or yellow which are the first and last slices.
Ogre is loading the volume correctly, it is assigned to the correct sampler. The (0,0,0) coords are in fact being used for the lookup.
So I conclude that my understanding of what tex3D wants to see in a volume texture is wrong. Any suggestions?
Edit: of course the minute I post this I have a brainstorm and may have fixed things. Two problems:
1) I was missing the "tex_address_mode clamp" in the material for the volume
2) There appears to be an interpolation between slices, so an offset needs to be added to Z so that the height is midway between slice boundaries. For 16 slices, to get to slice 2 Z will be 1/16+1/32. The floating point color values are a little off, but the integer values look fine.
Time to investigate more complex textures to see if this interpolation is going to continue to be a problem.