How to enable transparency on "common filters" display regions

I’m working on a project in which I’d like to render characters over the UI elements for various reasons. To do this I’ve created a second camera and display region for them. This works fine, but it’s causing issues with Common Filters. I’d like to apply bloom to the top display region, but doing so obscures all other display regions. I’ve gathered that this is likely because the fullscreen quad that the filter manager uses isn’t transparent, I read another post of a similar problem which said that I may need to add transparency to the filters.finalQuad, but setting the transparency of the quad using the line below didn’t seem to help.

filters.finalQuad.setTransparency(TransparencyAttrib.MAlpha)

Am I doing this wrong? And is there any way to make common filters not obscure the lower display regions?

The display regions in render order are:

  • Main (effects on this layer work fine, but are optional anyway)
  • UI
  • Overlay (renders on top, I’d like to have bloom on this one)

I’m new here so I’m sorry if this post isn’t up to standards, or if I’m misunderstanding something.

First of all, welcome to the forum! I hope that you find your time here to be positive! :slight_smile:

This is somewhat of a guess, but does the quad actually have any non-opaque pixels? If all of the pixels are opaque, then it will remain opaque even with the transparency-mode set: that mode just causes (semi-)transparent pixels to be rendered as such if present.

To test this, you might try something like setting an alpha-scale on the quad. The result should be uniform transparency, but it should at least indicate whether the above is the issue.

It might be done something like this:

filters.finalQuad.setAlphaScale(0.5)

(This along with setting the transparency mode as you posted, of course!)

Using that, the quad still appears to remain completely opaque, still obscuring the screen.

Hmm… I don’t know then, I’m afraid! For now I’ll bow out in favour of another forum-member hopefully posting.

That’s okay, thank you for your help regardless! :gift_heart:
Hopefully somebody can help.

You forgot to set the buffer color.

buffer.clear_color = LColor(0, 0, 0, 0)

Interesting request.

Here is some example code:

from panda3d.core import *

from direct.showbase.ShowBase import ShowBase
from direct.filter.CommonFilters import CommonFilters

base = ShowBase()

# Load scene into main DR
env = loader.loadModel("environment")
env.reparentTo(base.render)
env.setScale(0.3)

# Create a second DR rendering the same scene
cam2 = base.makeCamera(base.win, sort=10)

panda = loader.loadModel("panda")
panda.reparentTo(base.render)
panda.setY(10)

# Panda should only show up to second camera
base.cam.node().setCameraMask(1)
cam2.node().setCameraMask(2)
env.hide(2)
panda.hide(1)

# Apply bloom to second camera
cf = CommonFilters(base.win, cam2)
cf.setBloom(size='large')
cf.manager.buffers[0].setClearColor((0, 0, 0, 0))
cf.finalQuad.setTransparency(TransparencyAttrib.MPremultipliedAlpha)

base.run()

And the result:

3 Likes

Thank you serega-kkz for the solution, and rdb for helping put it into context! :gift_heart: