Search Unity

Question 2D light position shader question

Discussion in 'Shaders' started by toreman, Aug 20, 2021.

  1. toreman

    toreman

    Joined:
    Oct 1, 2016
    Posts:
    7
    I'm working on a 2D isometric game with same fake 3D effects.

    Im using Universal Rendering Pipeline with the 2D Renderer.

    I have been trying for a few days now to find a way to create a custom shader to be able to create the effect that a light is "under" / behind another object like a tree. Using the default shaders, the 2D lights will just light up all the sprites, with no consideration of y-sort. If a point light is infront of an object (y is lower) then the object should be lit. If a point light is behind an object (y is higher) then the object shall not be lit.

    My idea to solve this would be that if I, inside the shader get access to the light positions and other light properties, can compare the light-y coordinate with the current rendered objects y-coord and then apply the light depending on that.

    I have seached around a lot for example shaders but I have not found a way to get the light positions inside the shader.

    Does anyone have a hint on how to do this? Or if it is not possible, what other ways I can accomplish what I need.