Render Invisible (Transparent) Object that Obstructs View

Hi community,

The ultimate goal is to render individual parts of objects with a transparent background.

This is possible using save to screenshot, and saving it as a png, but my issue is with applying a transparent texture for an object that “crops” part of the main model. Normally, a transparent texture means that objects behind the blocker gets rendered but I want the blocker, well, to block it out.

I can’t do something such as a white blocker with a white background, as it needs to be transparent. I don’t know enough about textures and rendering, so any help would be greatly appreciated (code examples, things to look into, technical approaches, literally anything!).

If I’m understanding the problem correctly, perhaps you could arrange the render-order such that your “blocker” is rendered before the things being blocked. Since objects are rendered to the depth-buffer when where transparent, depth-testing should result in the blocked objects being occluded where the “blocker” has been rendered, transparent or no, leaving just the backdrop to show through.

Thanks for the suggestion! I forgot to mention a small detail that some parts of the to-be-rendered model are in front of the blocker, which I still want to be rendered. Everything behind the blocker should not be visible. Will this approach still work for this situation? Or will rendering the blocker first block what’s in front of it?

It should work, I think.

In essence, it relies on the depth-buffer–which is what’s generally used to get accurate occlusion of one thing in front of another.

The main difference made by rendering one object earlier than the rest is that the rest haven’t been rendered yet, and thus that one object’s transparency will mix with the backdrop, and not some other object. Then, when the other objects are rendered, those behind the blocking object will in effect be “too late”: depth-testing will cause them to be treated as occluded, and thus they won’t draw pixels in the blocked regions.

I clearly don’t know much about the depth buffer lol, and I’m glad someone who does was able to give me a solution. Thanks!

1 Like

Real quick, I finally got around to messing with the code lol. For reference, you’re totally right and here’s some example code for anyone else who’s curious:

#This assumes there is a png with only transparent pixels
#The image size is also (power of 2) by (power of 2)

showB = #however you set up your showbase-inherited object

sphere = showB.loader.loadModel("models/misc/sphere.egg")

sphere.setPos(0, -2, 0)

transparent = showB.loader.loadTexture("transparent.png")

sphere.setBin("background", 0)
1 Like