0
\$\begingroup\$

I am trying to achieve a day/night lighting system similar to the game RimWorld. Short preview of what I want can be seen here: https://giphy.com/gifs/VgzcwtjueP7BrYSrXe

Instead of using Global Light 2D, for this sort of system, I assume I need to use Directional Lights or Point Lights.

How can I make it that no matter the map size, the perspective of the light will always remain similar? (looking like the sun rises at east and sets at west)

More importantly, how can I cast shadows for objects in my world? There is a shadow caster 2D component, but most of my shadow casting objects are tiles on a tilemap, which are super light in performance.

I've been able to add ShadowCaster2D to a GameObject, and then attach that GameObject to each individual tile (that needs to cast shadows, such as walls and trees), and it just seems to crush performance. Should I use the built-in ShadowCaster2D for this, or is there another way that is more performant?

\$\endgroup\$
3
  • 1
    \$\begingroup\$ I'd look into CompositeShadowCaster2D's. I assume it's an optimization technique similar to Mesh batching. In that it'll automatically combine all your shadowCaster2D's into a single shadowCaster2D to reduce computation. \$\endgroup\$
    – Charly
    Jul 29, 2021 at 2:53
  • \$\begingroup\$ I'll certainly look into this more, however, the documentation is very vague. Would this only work with ShadowCaster2D's that are connected, ie, near each other, such as walls? What happens if I try to merge Trees that are casting shadows, but are a great distance from each other? I'm still open to other suggestions on how to do shadows, maybe using some shader magic, but I'd prefer working with the URP lighting system since it's all very connected and simple to use. \$\endgroup\$
    – caleidon
    Jul 29, 2021 at 11:06
  • \$\begingroup\$ Seems like CompositeShadowCaster2D really doesn't do much. Only merges shadows that overlap and makes it look different, it might not even have a significant performance benefit. I need shadowcasting for a map as big as 500x500 tiles, where there could be thousands of objects casting shadows. Not sure if some sort of culling would help here, but any starting point is better than what I currently have - nothing \$\endgroup\$
    – caleidon
    Jul 29, 2021 at 14:27

1 Answer 1

0
\$\begingroup\$

I've solved the daylight cycle problem and all my other lighting problems by using the following package from the Unity asset store: Smart Lighting 2D

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .