This may be more of a GPGPU question, but anyway…
I am trying to write a shader and program that does this for each pixel:
First overdraw : Write to Red channel
Second overdraw: Write to Green channel
Third overdraw : Write to Blue channel
Fourth overdraw: Write to alpha channel
Ideally (in magic GPU land), I could could increment the stencil on each render and use that count to select the output channel.
I am aware that I could accomplish this by depth peeling and using a color mask for each layer, but I would like to do it in one pass.
I assume this is probably a common GPGPU problem as I am essentially trying to store a list of output data at each pixel.
My current solutions to this problem are:
- Mess with the blend states
a) Use 2 Render targets cleared to (0,0,0,1) and (0,0,0,0)
b) Output “Value” from shader are (value, 0,0,0) and (value, 0,0,1)
c) Use seperate blend modes DST_ALPHA, ONE_MINUS_DST_ALPHA for RGB and ONE, ZERO for alpha.
This gets me two outputs, but seems really wasteful for two values and I would like more than two values in the output list.
- Go nuts with bit logic.
a) Break the 8bit output value into 4x2 bits and output each two bits into RGBA channels as high bits.
b) Use blend mode ONE, CONSTANT_COLOR (const color being 0.25) to shift existing bits down two places, then add the new bits to the top.
I have not tried this approach yet - not sure if floating point conversions will mess with it. But it does involve a bit of bit logic to disassemble and re-assemble - something I would not prefer to do.
So - does anyone have any ideas?
(FYI: this is more of a research project, so I can use Geforce8 extensions etc. if need be)