1
\$\begingroup\$

I'm trying to implement color correction with the 3d lookup table. The lookup table is actually just a 2d texture 256x16 and consists of 16 squares which one is 16x16.

When it comes to rendering, I pass 2 textures to shader: first one is whatever I rendered on the screen and the second is a lookup table. Shader takes RGB components of the rendered image, and uses it to find a replacement in a lookup table.

And there is two problems: first, I can't use filter to smooth colors (16 for each dimension is not enough) because it also smoothes the line between two contiguous 16x16 squares and that's inappropriate; second problem is no interpolation for a B-component.

Using a volume texture could solve both problems, but, unfortunately I'm short on time and there are not so many information about using 3d-textures in shaders. So, here's my questions.

  1. Is it possible to pass a 3d-texture to shader (HLSL)?
  2. If it is possible, could the filter be applied to the 3d dimension?
  3. Maybe there is a better way to implement color-grading that I don't know?
\$\endgroup\$
1
  • \$\begingroup\$ x/y could represent your r/g and the actual value at that point could represent the b. Could use interpolation between adjacent x/x y/y to produce more precision with additional overhead perhaps. \$\endgroup\$
    – Evan
    Commented Sep 4, 2013 at 18:12

1 Answer 1

2
\$\begingroup\$

Yes, you can use a volume texture in HLSL and get hardware interpolation along all three axes.

  • In D3D9, create a sampler3D variable and use the tex3d function to read it in the shader.
  • In D3D10-11, create a Texture3D variable and use its Sample method to read it in the shader.

In either case you must have created the texture as a 16x16x16 3D texture from the main application, not as a flattened 256x16 2D texture.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks, this is encouraging. Maybe you know what should I do with an image to be able to pass it to D3DXCreateVolumeTextureFromFileEx() function? I'm currently using .tga and, as MSDN says, I can use the same file format for both, 2D and 3D textures. But what it doesn't say is the way to prepare an image for assigning it to the volume texture. \$\endgroup\$ Commented Sep 5, 2013 at 6:19
  • \$\begingroup\$ @KirillDaybov The usual way to load a volume texture is with .dds format, which can store a 3D texture directly. You can create a .dds volume texture with the DirectX Texture Tool in the DX SDK. I don't think you can load directly from a 2D TGA to a 3D volume texture. You'd have to load the TGA yourself, extract the individual volume slices into a 16x16x16 array, then use D3DXLoadVolumeFromMemory. \$\endgroup\$ Commented Sep 5, 2013 at 16:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .