Vision cone using post process material

Hello guys.

I’m trying to make a dynamic vision cone using post process materials.

I’ve manage to calculate the cone in the material from player location and forward vector with a desired angle and max range.
Everything inside this will return a value 1 or 0 (where 1 = Outside the cone / 0 = Inside the cone). It’s then plugged in a lerp node in the alpha pin.
Then lerp pin A is "SceneTextuce:PostProcessInput0 * DarkeningFactor (Basically a value between 0 and 1 to control how much we darken the orginal material outside the cone)
Lerp pin B is only the “SceneTexture:ProcessInput0”

It works pretty well, but as you can see, it’s not dynamic with meshes and don’t darken behind them from the player location.

It’s all done from comparing the player location with the node “Absolute world position”.
(see image 3)

I tried to check if a custom depth was closer (Image 2, From the 2 upper red node) to the player location than the absolute world position value by getting the distance between player location and absolute and checking the stencil behind but it doesn’t have any effect.
I think I’m probably doing it wrong but I don’t really understand how to get the occlusion dynamically from the character when there is the wall inside the cone.




1 Like

If anyone ends up here.
I finally ends up with a solution, but that wasn’t an easy one, took me a looooooooooot of research, and TOO MUCH MATH. If you don’t remember how to calculate cosine or even what it is, it’s fine me neither 2 days ago :')

All calculated and drawn by the GPU without masking or anything.
Kinda proud on that one ahah

Maybe I’ll do a more detail post of what I did but for now I need to touch some grass

1 Like

What is the usefulness of this ? Can one use this to decrease the complexity of materials outside of the cone for example ? Or maybe the engine already does this anyway ?

Well it’s a PPM so yes I think you could do different thing.
I’m just reducing the intensity of the texture color outside the cone. That makes the darkening effect around.
But you could replace this by what you want, like maybe a noise effect in a texture that looks like fog, you make it move and it will look like a very smoggy environment around but not in front.
And this for both inside/outside the cone. Because it just modify the original texture.

Technically the cone size/angle can be set dynamically too, but I didn’t done that yet.
It even could be inverted, and now instead of modifying outside of the cone, you can modify the inside, so you could drawn like a scan effect or something.

I think with some modification you could even highlight specific custom stencil to only see them inside the cone, or just let them be visible even if hidden from the player perspective (kinda like the eagle vision in AC). And like I said, the angle could be modify, so it can be circle around player position instead of a cone.

I just don’t think there should be multiple instance of this PPM running at the same time because it should have no bounds and it’s done on every Pixel by the GPU (which is crazy fast for that) but still, I don’t think this should be done multiple times.

There are many possibilities I think, but not without understanding how it works, I’m gonna finish it and fix some things and I’ll try to mess with it a bit to see what else can be done.