I want to create a render target that is 32-bit, with 16 bits each for alpha and luminance. The closest surface formats I can find in the DirectX SDK are:

D3DFMT_A8L8    // 16-bit, 8 bits each for alpha and luminance.
D3DFMT_G16R16F // 32-bit float, 16 bits for red and 16 bits for green.

But I don't think either of these will work, since D3DFMT_A8L8 doesn't have the precision and D3DFMT_G16R16F doesn't have an alpha channel (I need a separate blend state for alpha).

How can I create a render target that allows a separate blend state for luminance and alpha, with 16-bit precision on each channel, that doesn't exceed 32-bits per pixel?

  • 1
    \$\begingroup\$ I think your only choice is to use multiple render targets for this approach. \$\endgroup\$
    – r2d2rigo
    Jun 21 '11 at 18:35
  • \$\begingroup\$ That's a good suggestion, worth looking into. What about encoding a float into 2 channels? Like, putting luminance in RG and alpha in BA in a R8G8B8A8 render target. Are there good examples of this anywhere? \$\endgroup\$
    – J Junker
    Jun 21 '11 at 22:52
  • \$\begingroup\$ @Junker If that were possible (and Id swear at the end of the day it should be but my knowledge of DirectX is dated) why wouldnt you use the G16R16F format? \$\endgroup\$
    – James
    Jun 21 '11 at 23:31
  • \$\begingroup\$ I'm also looking at getting this working on another target platform, and it turns out it doesn't support G16R16F, so I'm hoping to find a way to encode 2 8bit channels into a 16 bit channel and still support the blend modes for downsampled translucency \$\endgroup\$
    – J Junker
    Jun 22 '11 at 16:53
  • \$\begingroup\$ HLSL shaders are ignorant of the implementation of the datatype they are stored in, so you couldn't really bit twiddle it into two floats. And trying to jam it in there otherwise will be error prone and won't likely match up to the same 16 bits that you'd expect. You could use MRT's and two R32F textures however. \$\endgroup\$
    – Arelius
    Jun 23 '11 at 0:19

There are no formats with a 16-bit alpha channel except for D3DFMT_A16B16G16R16F.

Even if you could deal with encoding the luminance elsewhere, you'd also have to do similar tricks with alpha for your separate blend requirements, but the blend stage wouldn't understand those tricks and would produce unintelligible data.

I would suggest resorting, as suggested in the comments, to multiple render targets and a 'recombine' step.


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.