panda3d
panda3d copied to clipboard
Per buffer blend modes
I'd like to advocate for being able to set blending on a per buffer basis (rather than for everything with ColorBlendAttrib). In principle you could set a specific blend func for each but I think the most urgent need is to be able to disable it for auxiliary buffers. People very often use these buffers for non-colour data or in ways that don't use transparency. Right now there is a "gotcha" where they will behave unexpectedly if alpha!=1 due to blending (e.g. when used for normals). It would be very useful to be able to use the alpha channels in aux0 and aux1 for data. Right now they have to be 1 or odd things happen. Furthermore, these 1's are written to memory which is wasteful.
Example use case: I am putting non-rgba data in auxiliary buffers in a multistage render
manager = FilterManager(base.win, base.cam)
self.colourTex = Texture()
self.depthTex = Texture()
self.normalTex = Texture()
quad = manager.renderSceneInto(colortex = self.colourTex,
depthtex = self.depthTex,
auxtex = self.normalTex)
It always treats the auxtex as color data (rgba). Specifically it uses the alpha value to decide how to combine pixel values. I don’t want this – I want a straight overwrite so I can use the 4th channel for data. Right now unless I set alpha=1 it does a blend that is not what I want (or what most people would want I would guess) so the 4th channel is wasted.
Note that I still need the standard blend mode (I am guessing it defaults to glBendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ) for the main color buffer so I can’t just globally change the blend mode. Since OpenGL 4.0 (i.e. 8 years ago) there is glBlendFunci which lets you set the blend function for each buffer separately. The ability to just straight enable and disable blend on buffers has been in since OpenGL 3.0 (10 years ago): glEnablei( GL_BLEND, i)
A per buffer attribute that effective calls glDisablei( GL_BLEND, i) would provide the basic functionality and enable a lot of useful things.
It sounds like adding a bitmask field to ColorBlendAttrib to specify which (numbered) targets should be enabled/disabled for blending should satisfy your use case. This should be fairly simple to add.
I'm happy to take on this task within the coming week (if noone beats me to it).
In the long term it may be better to expose the per-target blend settings as you point out, though if noone needs that functionality until then, it may be better to wait with that until the designs for improving the render target API have been finalized.
rdb: That would be great. I just wanted to say that I am not currently limited by not having this feature. I worked about it by using a second auxiliary texture (aux1) for now. I still think it would be useful to have.
See #1271 for additional use cases justifying this enhancement request (that I overlooked :) )