Download

Detect that a material is inside a volume

Hello everybody !
I manage to make an effect to visualize to sight of the units in my RTS game.
I use a sphere and a material that use distance field.
In order to avoid that the sphere detect its own distance field, I uncheck the “affect distance field” box for the sphere.

But when I select several of my units, there respective spheres are drawing the visualization inside other spheres…
I which to merge all these sphere into one big zone that show the total sight of the group, not several circles.
portee_01.png
How can I make my material to detect that it is inside another volume ?
I can’t use distance field here because I already did and I have deactived it for the spheres.
I can add a spheric collision volume easily but I don’t know if nor how I can use it in my material.

Is it possible ?
If it is, can you give me a lead that I can follow ?

It will be awesome if I can found a way to also detect the intersection between 2 sphere to draw something at it as I do with the world and the distance field…
You can say I’m a dreamer… But I’m not the only one :slight_smile:

EDIT : I’ve thinking at using depth fade on my material (it’s a transluscent mat ^^) and didn’t use the distance field in the sphere’s mat anymore.
This way, I can reactivate the distance field on the spheres and the “no distance field solution” constraint is over :slight_smile:

You could use a spheremask in the opacity channel. Use the unit’s world position on the position input and have the radius match that of the sphere you are drawing.

Wokay !
I use the depthFade to detect the world and the distance field to know if I am inside a mesh.
portee_04.jpg
Thank a lot for this : https://answers.unrealengine.com/oauth/authorized?code=45f9a30f93484b3b961737dd9d1131e1
I’m happy :slight_smile:

Best way to do it is combine depthfade and distance field: https://blueprintue.com/blueprint/i6n2oo9g/

Blend function from here: https://forums.unrealengine.com/comm…-edge-blending

– Oh, I see you already came to the same solution :stuck_out_tongue: Could I see your setup to see how our approaches differed?

Here’s my incomplete material :

mat_simplified.jpg

The depth fade detect the world and I multiply all the mat with the distance field part that detect if the mat is inside a mesh or not.
I have a lot of tweaking to do and some aesthetic stuff to work on but on the principle, it’s the way I use this :slight_smile:

Edit : As I see your sample image, I’ve been thinking at push the fresnel a bit on my material :slight_smile:
the blend function seems very cool to me too and I have to read a bit about dithering ! Will do ^^
Thank a lot, wickerman :slight_smile:

EDIT 2 : I have seen in my mail box that you have give me another solution with sphere masks but removed it… It’s a bad solution or just less efficient than the one one I pick ?
Ah ok… I understand the sphere mask option and I will need a sphere mask in my mat per other spheres in my world… It will be very complex to put that in place because i don’t know how many unit my player will have in the game…