Hello! I would like to ask you Unity gurus about possibility to make the following thing in unity: So the main concept is to make a simple shadow for a top-down game, where the objects behind the static obctacles are not visible. The shadow should be just solid black. I dont want to use shadows from point light as it might bring the other effect while overlapping with directional light, and rendering shadows are very expensive for mobile perfomance.
Can the Raytracing be the solution? And the use of ray sensors that form an object or smth?
Or it can be alse interconnected with spetial kind of camera rendering?
I am looking forward to your advice and discussion of that case.
Raycasting is the way, indeed. Though this sort of thing would be a bit of a project!
First off, you’ll want to use a single point as your ‘light source’, rather than a full circle; this’ll make things much easier. To actually draw the shadows, you could use a procedural texture of some sort, but there might be a better way I don’t know about.
Then, there’s three ways you could go about this:
- Cast a whole bunch of rays outwards from the player. This is the simplest way, but it’ll be pretty expensive if you want to keep good resolution for distant objects.
- Cast rays from certain points on the obstacles towards the player. For rectangular objects, you only need to cast four rays, one for each corner. The same goes for any polygon - one ray per corner. For curves, you’ll need a few more, but with some experimentation you should be able to make it look reasonably good.
- If all your objects are simple shapes (rectangles and ellipses), you may be able to use coordinate geometry to derive a solution without any raycasting at all.
This looks like a really interesting problem, so please do let me know if you’d like any further assistance.
Thank you for your reply! I am interested in solving this problem, but procedural texture seems to be a way, but unfortunatelly i have shallow knowledge about it. I thought of the same ways of solving this too.
I was looking for the solution and found some on the asset store:
One is for more complex problems https://www.assetstore.unity3d.com/en/#!/content/4386
and the other i hope solves this current problem https://www.assetstore.unity3d.com/en/#!/content/3787
I can’t decide if i need to use an already made asset, our to find a better realization of this specific problem by myself, but the last asset i linked seems to be very good.
Check out this thread: