Could you make this with a shader?

So imagine a stereotypical stealth game where the enemies have vision cones projected on the floor, like so:

5823049--617035--visionCone.png
Top down view of a vision cone being rendered on the floor, taking obstacles into account

I currently have a system that uses A LOT of raycasts to detect what shape the cone should be and then transforms a mesh to take on that shape. However, I was wondering if it’s possible to do this with a shader. It would most likely be better for performance, as I currently see a slight dip in FPS if I have too many of these cones in my scene at the same time.

Regardless of whether you know how to do this (that would be great!), could someone tell me whether they think it’s even possible in the first place? (Preferably with Shader Graph,but I’d settle for a coded shader. :slight_smile: ) The main thing I’m unsure about is whether it’s possible to make obstacles cut into the cone. Couldn’t find anything on Google

Thanks!

One last bump; anyone who can make an educated guess on whether this effect is even possible with a shader?

this might come closest,

for 2d visibility, there are better options than full raycast
2D Visibility / Shadow « Unity Coding – Unity3D *see links here

1 Like

Hey thanks! I’ll give those links a read, looks very promising!

In addition to that distance field/raymarching technique, you could use polar to rect coordinate conversion, then do the pixel-level lighting/fading etc. there. There’s a few articles out there and discussions on some forums. But that technique requires a few passes etc. so it’s not probably possible (at least without customization) with shader graph.