1

Something I'm wondering about, that's probably not possible unfortunately, but thought I'd ask - I'm setting up a deferred lighting shader that takes in 2 textures and outputs to 2 render targets. Their channels are:

Input Tex 1: Color Texture
  Channel 1: R
  Channel 2: G
  Channel 3: B
  Channel 4: A

Input Tex 2: Normal + Specular Texture
  Channel 1: X
  Channel 2: Y
  Channel 3: Z
  Channel 4: Specular Amount


Output Target 1: Color Target
  Channel 1: R
  Channel 2: G
  Channel 3: B
  Channel 4: A

Output Target 2: Normal+Specular Target
  Channel 1: X
  Channel 2: Y
  Channel 3: Z
  Channel 4: Specular Amount

Pretty simple. Except - when outputting to the Normal+Specular target, I want to mask the pixels that are written using the Color texture's alpha channel to control the amount of blending. But - I'm outputting a vector4 as my second color from the shader, whose channels are all used up.

So is there any way of having Direct3D use an alpha value temporarily as a blend parameter, use it to "mask" my 4 norm+spec channels, then discard it after use? Or to have render target 2 use render target 1's alpha as its blend parameter?

I know I can represent a normal vector using only 2 components - e.g. store X & Y then recalculate Z on the fly - but the process would be simpler & probably perform better if I could get away with leaving them unchanged - so hoping to find a solution that way.

Thanks!

QuadrupleA
  • 876
  • 6
  • 23
  • How about using a third render target? There could be stored material information like specular and maybe for the future an emmisive part. Further you could store the depth for many funny post effects :) – Gnietschow Jun 10 '13 at 21:51
  • This is not possible afaik, you will have to resort to packing your normals using spherical coordinates if you need to alpha blend the normal buffer I think. – gareththegeek Jun 11 '13 at 13:22
  • Thanks - both of those approaches would work I think - I'm trying the spherical coordinates approach right now. – QuadrupleA Jun 11 '13 at 16:52
  • This has been answered here: https://computergraphics.stackexchange.com/questions/94/is-it-possible-to-alpha-blend-multiple-render-targets-using-a-specified-alpha – George Jan 27 '18 at 15:48

2 Answers2

0

Interesting problem! Just thinking aloud, I wonder if you could write the mask value to the stencil channel of the depth buffer and make use of that when masking?

Justin R.
  • 23,435
  • 23
  • 108
  • 157
  • Interesting - don't know the stencil buffer that well, but if it were 8 bit and could be used for blending, that might work really well. (Note: just checked - probably wouldn't work, as I need more than a simple pass/fail mask - i.e. an 8 bit alpha mask rather than 1-bit - and doesn't look like you can use stencil buffer in the blend function). – QuadrupleA Jun 12 '13 at 03:51
  • @QuadrupleA you should be able to use the full 8 bits of the mask (assuming that your depth buffer is declared in the usual 24-bit depth + 8-bit stencil format), but yeah I'm not sure if/how it can be used in blending. It was just a thought! Good luck, and when you find a solution please append it to your post as I'm curious about this. – Justin R. Jun 12 '13 at 17:16
0

So, to follow up on this one - I ended up just encoding the XYZ normals into two components using a Spheremap transform technique (#3 mentioned on the page http://aras-p.info/texts/CompactNormalStorage.html#method03spherical ).

So I'm writing the same alpha value to both targets to control blending - couldn't find any other way.

QuadrupleA
  • 876
  • 6
  • 23