# Question 2D Sprite Shader light intensity based on y position.

Discussion in '2D Experimental Preview' started by SpudGums, May 19, 2020.

1. ### SpudGums

Joined:
Mar 10, 2015
Posts:
10
How would I get the 2D point light positions in a shader using the Universal Render Pipeline in Unity?
I'm trying to simulate a 3D effect by reducing light intensity from lights that are above a sprite in the Y position.
I duplicated the Sprite-Lit-Default shader and easily managed to change the output by doing a lerp between the sprite's default color and black.

I Just changed
o.color = v.color;
to
o.color = lerp(v.color, black, lightYPos);

The problem is that I can't really get the Y pos from the light sources, and I only know it works because I manually set the lightYPos from 0 to 1 for testing.

Anyone knows how I can manage to get the point lights positions from a shader?

The effect I'm trying to achieve is like this one:

This is from a Gamastra article where the Graveyard Keeper developers share how they did some of the effects in their game.

They say that "There is a shader that calculates the distance between a light source and a sprite on the vertical axis. If it’s positive (the light source is in front of the sprite), we illuminate the sprite like we always do, but if it’s negative (the sprite is blocking the light source), then the intensity of lighting is fading depending on the distance at a very quick rate."

Would love some help on how I can retrieve point lights positions in the URP 2D Sprite Lit Shader...

2. ### RafaelGaju

Joined:
Apr 8, 2020
Posts:
6
"What I ended up doing was just publishing the light's position to a scriptable object and reading that from a script that's on each tree object. Then I have all the positional data I need, so I pass (transform.position.y - lightPos.y) into a sigmoid function and then pass that value to a copy of the 2D/Sprite-Lit-Default shader"

This is what someone on Reddit did to get a similar effect

here is the post: