Material Render Over Other Material

I have a body model, big eyes on top, and a flame model that goes around them both. The flam is cool and transparent but still obscures the eyes, is there a way to make it so that the eyes render over specifically their separate flame material?

They are super simple materials with basic constant coloring without any textures or anything, just simple materials to color the different models.

I am just finding the eyes under the flame on the actual body to be too hard to see, would prefer them visible almost like they were on top of the model.

Is this possible to just render one material over another specific material for example? Or maybe render 1 model over another specific model only if that is not possible?

1 Like

Does the flame model move, or is it static? How closely does the flame conform to the body/eyes model? It might help to see what you’re working with; descriptions alone can be kind of hard sometimes when talking about multiple complex shapes.

You could potentially grab the polys that cover the eye area and apply a transparent material there, or an instance of the normal flame material with lowered opacity. To make it work well, the flame would have to be close, and might require some edits to the flame’s mesh, so it’s not ideal. I personally wouldn’t want to do that if I could help it. Painting an opacity mask on the flame in front of the eyes might work best, if the flame is fairly close to the body/eyes and its UVs are unwrapped properly. Or even if they’re not, possibly.

Might also be possible to calculate a line from the camera to the eyes, then use the coordinates where the line passes through the flame to alter the flame material in just that area, but if that’s possible it might be a lot of work to get it right, and I wouldn’t want to try it myself.

2 Likes

flame eyes

Like this, the part of the flame around body I want to stay in place, but the top of the flame I will be trying to have wiggle around as you move. The distance is a little bit big, eyes bulge off the body underneath just a bit.

Ideally being able to just make the eyes render over the flame would be ideal or something like that. Don’t want to move them in case the flame goes out and they now float instead of being against the body, not to mention how odd that already might be even under the flame. I tried modifying the flame model, and that may work, but definitely should be a last resort as it can be a little odd looking.

1 Like

Having done a little more research on the subject, I think you may find this useful:

(87) How to Create Masks With the Custom Stencil Buffer | Tips & Tricks | Unreal Engine - YouTube

In this video, they do something a little different than what you want, but it should be similarly applicable. You should be able to use an inverse mask based on the eyes to not render the flame, I think. I have not tried that out yet, but I’m thinking that I might.

1 Like

Thank you, still fairly new to this. I will try to look into that in a bit and see if I can figure out how. I watched it, think I know generally what to do, but haven’t done inverse mask or any post processing ever yet for that matter either.

Probably going to delay just a little while I try to finish figuring out the other parts of my character. Try and see a bit more progress before getting stuck on trying to figure this out. Going to be my first character ever made and animated for ue4 which is why I made it fairly simple, did not foresee this issue. Going to make sure I learn the process for animation and all that real quick, already learning shaders a little thanks to this guy after trying to get the gradient of the flame. xD

Just trying to not get stuck on things and make progress. Have an issue with perfection and then doing nothing cause I get stuck on one thing big or small.

1 Like

I figured it out!

Once you have the eyes in the custom stencil from that video, this material should work for the flame:


You don’t need the post-processing volume, you just need the eyes in the stencil so that it can make a mask to use in the material. The flame material also stays in the surface domain, rather than post-process. This material will also let you shift the opacity for the eyes with a parameter (named secondary opacity in my material), so that you don’t need to have the opacity over the eys at zero.


image

2 Likes

Thank you very much! I will have to try it really soon. You even thought of the opacity of the eyes to account for not always wanting it to be completely perfectly on top, but still have a small amount of overlap.

Really appreciate it, figure it probably helps you expand your knowledge too though as well. Might eventually start looking on here for challenges to learn and solve through helping eventually too. hehe

I will reply or message you personally to let you know how it went.

1 Like

Got it to work perfectly. Thank you!

Only wish I understood the multiply subtract and mask stencil parts of the nodes.

  1. I don’t see the reason to multiply them together instead of just having a lower opacity level? Removed and works fine without.
  2. Purpose of the subtract, and why does yours have a black box where mine is just an A and B? Removed and works fine without.
  3. Mask? What is difference between (R) and the rest that leads you to decide it over the other options?
  4. With the custom stencil, are you able to differentiate between different stencil numbers?

Other than that I am all good, Thanks again!

You can absolutely do it simpler than I did. It was very late at night for me when I finished with it, and it was a bit slapdash. The simplest way would indeed be to hook the mask (or custom stencil) directly to the Lerp alpha channel, Primary to A, and Secondary to B. This would allow completely independent control of the two opacities. That said, there are some functional differences between the results of the simple way and the way I built mine.

  1. Having the Primary and Secondary multiply for the Lerp B channel means that the main opacity and the masked opacity scale in ratio when Primary is changed, and that ratio is controlled by Secondary. In most cases, the simple option would probably be better, doing any ratio maintenance in a blueprint or something if it’s required for some reason.

  2. The subtract node is simply a mistake, and a redundancy that diminishes the effect Secondary should have on the material’s opacity. It was a leftover from earlier experimentation that I didn’t catch because it didn’t break the way the material worked. It works better without it though, and having it doesn’t really give us any benefits. You can toggle the display box on most nodes by clicking the arrow at the top right of the node.

  3. It just happens to be a one-channel mask. Any single-channel would have been fine. I used it because that’s what the guy in the video I linked used. I’ve figured out that for our purposes, we actually don’t need it all, and can go directly from the CustomStencil to the Lerp alpha channel, since the stencil is already grayscale (which is a single channel). I’m not as familiar with the mask node as I’d like, but I believe it takes a color input and gives the color of just the channels you pick. For example, fed a color with RGB values of (0.3, 0.5, 1), an R-mask would give (0.3, 0, 0). An RB mask would give (0.3, 0, 1).

  4. Different objects can have different stencil numbers, but it seems like that’s only useful for post-processing. The description on the CustomStencil node seems to indicate that it’s based on all opaque objects rendered in CustomDepth. Since all of the stenciled objects are in custom depth, it seems like we’re out of luck on that one.

1 Like