Download

Using Stencil buffer

Hi all! Could you explain me how I can repeat this stencil effect in unreal? https://www.ronja-tutorials.com/post/022-stencil-buffers/

https://www.youtube.com/watch?v=PiQ_JLJKi0M

Yes, I have seen this video, but it doesn’t tell how I can make similarity effect. I am trying to make shader but the result is wrong. Now I have a mask but it works until target object in front of stencil object, and I need it to work then the target object behind the stencil object. As in the unity tutorial which I posted in the first message.

It shows you how to enable and use the stencil buffer. I assumed that was your problem.

I don’t understand what this means.

For the portal you need a plane mesh and a material for it. The material for the portal itself is just an empty translucent material that is set to allow writing to the depth buffer (details panel of the material). The portal mesh should be set to not render in main pass and to render into the stencil buffer at a given index (these are in the details panel of the static mesh actor.)

You then create a translucent material for your object that reads from the stencil buffer to determine what areas are opaque vs. what is translucent. All of this was in that article, I’m just repeating it basically, so I don’t know if this is relevant to what you’re trying to accomplish. If your issue is with something else then you’re going to need to be a lot more specific…

Result:




I don’t know how it works in Unity but in UE4 you can’t read from the stencil buffer in a masked material, which means you have to use a translucent material. This makes it an expensive effect, and you’ll end up with the usual problems with translucent materials, namely you may get inconsistent lighting or sorting issues.

Thanks a lot for the detailed explanation. But I have another question, how did you create a translucent material so that you have active inputs. With this type of material, my inputs are inactive

Ops, I found the answer about translucent material. Thanks again for your time and help.

Under the translucency rollout of the material there is a setting called “Lighting Mode”, set it to one of the Surface options. In my material I used Surface Forward Shading, which is the most expensive one, but it has the fewest lighting artifacts.

No problem. For whatever it is worth, here are a couple of other ways to accomplish (somewhat) similar effects that might be worth looking into: Render targets, Cross product

Thanks to both of you for the information, as I had doubts in a similar project. (https://forums.unrealengine.com/deve…-shader-effect)
However I get gaps in the mesh materials. I don’t know if it could be a problem with the mesh or the stencil.

Any ideas? This is my mesh material:

Greetings.