-
Notifications
You must be signed in to change notification settings - Fork 7
Home
Here you'll find info on how to use the Unity2DShadows project in your games. It contains code documentations as well as code examples and guides on how to use the project completely without code. If there's anything missing, or that needs to be corrected, please send me a message and I'll fix it!
The demo is offline at the moment. Will return shortly
Below will follow a quick-setup guide for how to use the project in your games, but in case you just want to check it out, there's a live-demo available here.
The Unity 2D Shadows project or package is a unitypackage that enables dynamic, pixel perfect 2D shadows. It is shader based, meaning it is fast, executing on the GPU. It has been tested on Windows and Mac machines, but no tests have been made on any mobile device nor any linux computer, this might change.
In order to get set up, download either the entire project from here, or just download the .unitypackage file. Both will do the same thing.
The project is based around a few scripts and shaders, these are the essentials that are REQUIRED for the shadows to work:
- Scripts
- LightSettings
- LightSource
- ShadowController
- LightSourceEditor
- LightEditor (optional)
- Shaders
- Occlusion
- Light
- Distance
- Blend
- Accumulation The LightSource and the LightEditor MUST be placed in a folder named "Editor" in the root of your Assets folder in order to work. They're not absolutely required for the shadows to work, but make it a lot easier to work with the project.
The scripts can be found under 2DLighting/Scripts, while the shaders can be found under 2DLighting/Resources/Shaders. The Editor scripts can be found under Editor.
with a light, a shadowcaster and a background affected by the lighting.
In order to do this we have to create a new Unity project and import the .unitypackage.


Next we need some sprites, one for the shadowcaster and one for the background.
Now we create two sprite objects and attach the sprites we want them to have as well as naming them appropriately
Next, attach the LightSettings2D script to each of the objects
And turn on Recieve Shadows on the background, and Cast Shadows on the shadowcaster

Now we attach the ShadowController script to any object we want, I'll attach it to a new gameobject and name it appropriately. This can also be done by dragging in the ShadowHandler helper prefab in the prefabs folder. Select Multiplicative in the Blend Mode dropdown if it's empty or set to Additive.

Also make sure to set the Rendering Camera to the Main Camera.
Finally, create a new empty gameobject and attach the LightSource script to it. This can also be done by dragging in the Light helper prefab in the prefabs folder. Modify the light settings to your liking, like setting the angle of the cone of light, changing the Intensity (values > 1 will create funky results), changing the color and size of the light, or ramping up or down the blur amount (high blur values will cause artifacting)
Have fun!









