How to get light 2D position in shader?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By raphaelkox

Hi There,

I’ve been banging my head with this problem for a few days now.

I want to check in shader if a light is “lower” in Y position in relation to the object (i have it’s Y position in a shader param)

If the light is bellow object, it proceeds, if not the light is 0.

At first i thought i could do this:

float light_y = current_world_position.y + LIGHT_VEC.y
if(light_y > object_y){
} else {
    LIGHT =  vec4(0.0);

but then it hit me, that the LIGHT_VEC is probably normalized.

So what i want is: find the global position for the current fragment, and the global position of the light (or distance vector to the light, so i can sum it’s Y component to the position and find the light)

Is that possible as of now?
If so, how could i go about it? (FRAGMENTCOORD returns strange values, and POSITION is not available) Tested using Godot 3.0.2 and 3.0.3 rc1

Thanks in advance!

+1 This will be extremely powerful in 2D, if anyone has any resources on this, please share as this type of information is barely available if any at all.

The_Black_Chess_King | 2020-11-10 23:46