Occlusion material that culls whatever is behind it?

I can’t find an updated or concise answer here, but Im trying to achieve this effect, where the material occludes whatever is behind it-


This link is from 2014 and didnt get to a solution - https://forums.unrealengine.com/development-discussion/rendering/76916-occlude-specific-object-actor-behind-actor-material

I followed this, but this doesn’t occlude the objects behind it - UE4 Tutorial: Occlusion Masking - YouTube

There are a lot of tutorials on showing object’s outlines behind other objects or what have you, but not this. How can I do this?

Hi, you might wanna search for something like “ue4 dissolve mesh” and go from there.

So basically you could use a masked material for any object you want to hide behind the plane. Then in the material check for each pixel whether or not it is behind the plane and if it is, then set the opacity to 0 (hide it), else set the opacity to 1.

Hey @chrudimer thanks for the idea. I’m very new to scripting w Unreal (coming from Unity) and dont know how to implement the second part of your answer. Looked up dissolve tutorials but they don’t reference other objects. Do you have an example graph you could post?

Sure, so you would create a material like this and apply it to the object you want to hide.

This material here will hide any pixel of the object it is applied to, if the pixel is inside the radius parameter of the sphere position parameter and the camera is not inside this sphere. If the camera is also inside this sphere, the pixel will not get hided.
I used a material parameter collection here to insert the position of the sphere, so if you would want to hide objects with different materials inside the sphere you would only need to set the sphere position only once in the material parameter collection (if you would use a vector parameter you would need to set this parameter for each material).

This is not exactly what you wanted since it is a sphere not a plane. For a plane you would need some math and I can’t do this (for each pixel you would need to cast a ray to the camera and see if this ray intersects the plane, if so set the opacity to 0 (hide it), if not set it to 1).
There are some intersection material functions in ue4 that you can start with, if they don’t work you would need to implement the math yourself.

Depending on what you want to use this for, you could make it easier. If for example the plane would have an infinite extend (slice a tunnel for example) then you could just check whether or not the pixel currently rendered is on the same side of the plane as the camera. For that you would do a dot product from the plane normal with the vector from the plane origin to the pixel currently rendered and see if it is positive (pixel is on the side the plane normal is pointing to) or negative (pixel is on the opposite side of the plane normal).

Thank you so much for this. In terms of getting it to work with my setup, while I understand plane math is more difficult, is there any way to cull only the objects that are children of the object? See the attached image - basically I have a box with a hole, and I’d the box to be the occluder.
Again, thanks.

Hmmm, now I think I don’t understand what you’re trying to achieve :slight_smile:

Culling is always per object and happens on the CPU, so if an object gets culled, then the whole object is not rendered. I assumed till now that what you wanted to do would be something like this:

You’ve got a plane or box and you’ve got one or more objects (any other objects should be ignored, like in the image of your first post the character is the only object that gets considered, but the sky and the ground are ignored). And if the plane/box is between the camera and a part of the object (so this part of the object is behind the plane/box from the camera view), then this part should be invisible. If the plane/box is not between the camera and this part of the object, this part will be visible. The part of the object mentioned above would be the pixel currently rendered.

So with this setup I described above, each object that should be affected by the plane/box needs to have a specific material (an material that could be something like I shown in the image above for an sphere instead of plane/box) applied to it.
Then if you would want to use a box instead of a sphere, you would need to change the math inside the material. So you don’t have an actual sphere or plane or box in the level, it all happens inside the material (of course you could create a blueprint that references an actual sphere/plane/box inside the level and sets the parameters inside the material appropriately but this would be only for visualization but has nothing to do with the actual effect, since that logic is inside the material).

So with this setup is does not matter whether one object is a children of another. Each object that should be affected needs to have such a specific material applied to it. The hiding happens inside the material, so it is purely cosmetic since it happens inside the GPU render thread (the GPU render thread happens after the CPU game thread), and the CPU and therefore the game logic will never know about this.

Ok, thank you. Mainly I need to occlude the parts of the child meshes (the ones with color in the image) that are hidden by the outer box. So only the portion BEHIND the outer wall with a hole in it. Given the irregularly of this shape, for the internal material maybe I do 4 planes. Again I understand the plane math is complicated, but do you have any graph examples of what you described

I can give you a high level description on how you could try solving a problem (if I know a way to a solution) or I can try helping you if you encounter a specific problem in the work you do, but I can’t do the work for you.

So you could try implementing it yourself and if the material does not work as you expect it to work you could post an image of what you have so far and I can try helping you from there. [HR][/HR]For general understanding of how unreal engines material editor works, what nodes there are, I find the learning videos on epics learning tab very useful.