2D Light with sprite illumination

2DDL Documentation

In some situations you’ll need the sprite to react to the light in the scene not only in shadow but also inside so he turns black when he is away from light sources. Here you’ll learn how to do exactly that.

 spriteIlum

Now, we’ll get this effect with a simple set-up inside your project.

1. Create a new scene

2. Add a gradient 2D Light

3. Add a Caster, my caster is a star.

4. The setup of the 2DLight parameters don’t necessary have to be exact, but the tutorial should work better with the given values below:

spriteilum2

Note that the 2DLight and the caster have 10 units in between, the 2DLight position is (10,0,0) and the Star is at (0,0,0).

5. Let magic begin! For this, we need to change the Star Material, Create a new Material with shader “Sprite-Diffuse” and assign it to the Star Material property.

6. You should see the star become dark because a Unity Light doesn’t exist in your scene thus it won’t light the star.

spriteIlum3

7. This is the most important step. First, add a “Point Light”  GameObject –> Light –> “Point Light” . You’ll need the correct setup for the light to reach the Star surface. To do this, set the point light you just created as a child of the 2DLight GameObject in the scene.

Next, set the “Point Light” position as (0,0,-1).

Z = -1 because want to “Point Light” pointing the Star face towards the main camera.

8. And lastly, play with the values like “Range” and “Intensity” from Point Light. I used a Range of 30% more than the 2DLight radius (20) and Intensity to 3;

PLEASE: Play with 2DLight, Point Light and  the Render settings value to achieve amazing effects.

Demo: