Here’s my problem : I have units that have a “scanner” to see the world around them. They assaulted by a lot of foes.
The scanner sight is visualized in game with a spheric static mesh.
I want that the enemies that are outside one of these sphere are hidden in some way.
I’m thinking about 2 solutions :
Using distance field :
I have already activated the distance field in my project and use it a lot.
I can set the material of my enemies to use the distance field generated by the world and the scanner spheres. If the foe is inside something that generate distance field, the opacity of the enemy material is set to 1 and to 0 if it is outside.
This solution seams perfect for me but I have a lot of enemy units… Even if I use ditheringAA to smooth the shader complexity, I’m afraid of the performance cost for this…
Using Stencils :
I can use my spheres has a mask for the stencil I will use to render the enemies.
I don’t know exactly how to do this yet but I’ve seen some samples that let me thinking it will be pretty easy
I think this solution has two problems (maybe just one, I’m not sure ^^)
- The units will be rendered if they are see through the sphere, not only if they are inside… When the camera will see the game from a not so vertical point of view, it can be a problem.
- I don’t know if I will be able to make the appearance and disappearance of the enemies smooth. With the distance field option, I can make a blur zone around the object and I can manage to make the ants appears smoothly.
As you can see, from an artistic and gameplay aspect, I prefer the distance field solution a lot.
But I’m afraid that having hundreds of translucent units at the screen will hit negatively the framerate of my game.
I can imagine that, once the units are render in a specific stencil, I can hide them without using a translucent material and doesn’t need to call the getNearestDistance node…
Is the stencil method a lot more performant than the distance field + translucency option ?
Maybe can you think at another solution for dealing with this ^^.