"Transparently hiding" parts of an object

Here’s a challenge (maybe not?) :slight_smile:
Look at the attached image -
Image
The scenario is that I have two boxes, one is closer to the camera than the other.
The closer one is completely transparent, and I wish to have it’s “transparency” feature “project” onto the other box: The remote box is blue, however, the projected part of the transparent closer box becomes transparent as well, making the gray background visible.
This could also be seen as a “window”.

I would appreciate pointing me out to the right direction, for example: “look into alpha channels and camera viewing mode parameters” etc, since I don’t exactly know where to look.

Thanks in advance for reading!

Amir.

Your code looks fine to me.

Haha :smiley: point taken,
but my problem is I don’t know what exactly is the “setting” I should use to achieve this goal - That’s why I’ve only asked for a general assistance, knowing that without code there isn’t room for specific advice: Is it even possible to use two box geometries that way, is that objective feasible, what are the parameters to design such a scene and so on.
If it’s too general I understand, but just pointing out the right direction so I could inquire myself before further asking would be much appreciated.

Seriously, even saying “yes, this is possible, look into X and Y topics and from there take it to Z” or saying “no, I don’t know of such a possibility to design a scene” would save me a lot of search and frustration and would be of assistance to me.

Thanks.

I think that all solutions will involve rendering your ‘punchthrough’ objects into separate buffer (stencil? is it still used in opengl at all or everybody just uses alpha+shaders?). Then, either draw background and then draw rest of scene filtered by that stencil buffer, or draw background, draw scene and draw background again in punchthrough places.

1 Like

What if you just let the transparent object in the opaque bucket?
The first object will be rendered using the background as the blending source, then the depth test will prevent the second object to be rendered over the first object.
Usually people come here with the opposite issue :stuck_out_tongue: (tansparency fail I can see the background through objects)

1 Like

OK thanks guys I’ll look into it!

Queue buckets are the first thing to check.
Then there are “extra parameters” that control transparency handling (among other things).
Both aspects are addressed in the tutorials. Don’t skip the “advanced” section, all material is relevant.

1 Like
@amirkr said: Haha :-D point taken, but my problem is I don't know what exactly is the "setting" I should use to achieve this goal - That's why I've only asked for a general assistance, knowing that without code there isn't room for specific advice: Is it even possible to use two box geometries that way, is that objective feasible, what are the parameters to design such a scene and so on. If it's too general I understand, but just pointing out the right direction so I could inquire myself before further asking would be much appreciated.

Respectfully…

The problem is that there are about 4 or 5 things you can do to mess up transparency. We don’t know if you’ve failed to put something in the transparent bucket. We don’t know if you’ve failed to set blending, etc… all of which are easy hits if you search the forum for “transparency”.

If you’d shown us what you tried already then we could have zeroed right in on what to tell you rather than repeating advice that already appears on the forum every two days.

My guess was that you never put the object in the transparent bucket. Already you’ve gotten one response that assumed you had already done that and were seeing problems from it. You see how this looping gets pretty confusing after a while.

1 Like

Thank you all, I’m working on it and when I have the exact solution to this issue I’ll post it here for future inquirers.

@pspeed said: Respectfully...

The problem is that there are about 4 or 5 things you can do to mess up transparency. We don’t know if you’ve failed to put something in the transparent bucket. We don’t know if you’ve failed to set blending, etc… all of which are easy hits if you search the forum for “transparency”.

If you’d shown us what you tried already then we could have zeroed right in on what to tell you rather than repeating advice that already appears on the forum every two days.

My guess was that you never put the object in the transparent bucket. Already you’ve gotten one response that assumed you had already done that and were seeing problems from it. You see how this looping gets pretty confusing after a while.

I just want to make clear that you’ve already given me much needed advice so I’m only posting this to clarify things if you have any further suggestions, this was already somewhat helpful.

The thing is, I have no code set up (well, of course I do for the general project I’m developing, but not for this specific task).
I was asking so I could get advice in the form of “how to” (or a suggestion).
If I DO want to put my question into “code”, it is something like this:

[java]
Box b = new Box(Vector3f.ZERO, 1f, 1f, 1f);
Geometry g = new Geometry(“Image”, b);
Material mat = new Material(assetManager, UNSHADED);
mat.setColor(“Color”, ColorRGBA.Green);
g.setMaterial(mat);
rootNode.attachChild(g);

Box b2 = new Box(Vector3f.ZERO, 1f, 1f, 1f);
Geometry g2 = new Geometry(“Image”, b2);
Material mat2 = new Material(assetManager, UNSHADED);
mat2.setColor(“Color”, ColorRGBA.Red);
g2.setMaterial(mat2);
g2.move(1f,0f,0.5f);
rootNode.attachChild(g2);

Box b3 = new Box(Vector3f.ZERO, 1f, 1f, 1f);
Geometry g3 = new Geometry(“Image”, b3);
Material mat3 = new Material(assetManager, UNSHADED);
mat3.setColor(“Color”, ColorRGBA.Blue);
g3.setMaterial(mat3);
g3.move(1f,0f,-2f);
rootNode.attachChild(g3);
[/java]

(I’ve added a picture in the end that shows exactly what I want if the text isn’t clear).
There is no transparency here (I know) - If you imagine the scene, it’ll have three boxes: a blue one further away on the Z-axis (to the rear), then a green box, then closest to us would be a red box. The red box only “covers” (from out point of view) a part of the box with the image behind it, while we don’t see the blue box at all, since it is in the back. What I want to do is this: I don’t care about the “color” of the red box at all, but I do want the part of the green box behind the red box to “disappear”, showing the blue box behind, or the background (where there is no blue box). Naturally the red box would have to be transparent to do that (just add it to the bucket, it’s no problem), but the hard part is not the transparency but making such a thing happen.
I’m adding an image to help clarify the issue:
Explanation

Just to explain myself better :slight_smile:

By the way, perhaps I’m trying to “overkill” a much simpler problem: I receive a picture for a texture, which I cannot change (it’s given by file, or downloaded from the net etc). I have a box which uses this texture.
The picture has a certain ratio, say, a landscape of 16:9. But my box has to be a 4x4 square. I could apply the texture, but then it’ll deform and skew the picture to fit. I simply want to “slice” what doesn’t fit (imagine you’re doing it in MS Word, you have a picture and you can simply “cut” what doesn’t fit - you lose a part of the image, but you retain the correct ratio, instead of stretching it.
I could not fine a way to do this, so I thought about having this “transparent punchthrough” object that will be place directly before the box with the image and “make a part of it go away”.

Just change the texture coordinates of the box based on the image size.

1 Like
@pspeed said: Just change the texture coordinates of the box based on the image size.

Thanks! It did the trick :slight_smile: