How do you achieve Height based Opacity?

Hi,

I saw the tutorial about Location based Opacity and wonder if it would be possible to do something similar that is based upon a height, reltative to the character position. This could be used in a top down game to blend away ceilings etc. in buidlings when you enter them. How can this be done?

But how can I then drive the opacity with it? :smiley: Im really new to materials, so I need a little bit in depth advice. In code I would just compare the current height of the thingy in the material that you can get with get absolute height to the player height + a little offset and then just set the opacity to zero. But there seem to be no branches etc. in materials that blueprints have. Very confusing to me.

You can pass the player’s position in Z into the material via a scalar parameter.

Cheers,

Si

You could do something like the following:

Here I am passing in two parameters into the material.

Player Height = The player’s world position in Z.

Fade Height = The height over which you want to fade. At player’s height the opacity is 1, at Player’s Height + Fade Height it is 0.

I take the world position of the pixel, mask it to just B(aka Z), subtract the player height and clamp it between 0 and FadeHeight. So now the value is from 0 to FadeHeight. Everything below the player is at 0. Anything above PlayerHeight+FadeHeight is now FadeHeight. So dividing by FadeHeight gives us a value from 0 to 1. Take 1-that and we have a value from of 0 below the player, 1 at FadeHeight above the player and a smooth linear ramp between which we can feed into the opacity.

Hope that makes sense.

Cheers,

Si

oops. Posted my comment as a new answer…doh

Hey, this works perfectly. Thank you kind sir :slight_smile:

Ok now one more problem I see with this. I can now basically cut off meshes visisbility by making them translucent. However, this leaves some very ugly looking side effects: You can now see inside the mesh, which doesnt look that good. Is there a way to maybe fill the cut off surface with a color or material, so it doesnt look as weird?

You could compare the height of the player vs each object in the Actor’s code or BP and feed the opacity for the whole object into the material directly as a parameter.