Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved 2.5D lighting using 2D lights (isometric)

Discussion in '2D' started by venediklee, Mar 8, 2023.

  1. venediklee

    venediklee

    Joined:
    Jul 24, 2017
    Posts:
    145
    Edit: solved, read the first comment

    Hi, I am trying to implement isometric lighting using 2D lights and pixel perfect camera. I am very close to a full solution but when the pivot of a gameobject is offscreen, it fails because the _LightTexture_0_0 is only rendered within the camera frustum(or the scene view camera frustum).

    So does anyone know how I can draw the Light2D batcher result of a larger camera to a render texture? Or how I can add padding to pixelperfect camera? I also tried rendering everything to a render texture with a larger non-pixel perfect camera and blitting that render texture to the smaller pixelperfect camera but it ̶d̶i̶d̶n̶t̶ ̶d̶i̶s̶p̶l̶a̶y̶ ̶a̶n̶y̶t̶h̶i̶n̶g̶ wasn't pixel perfect even when both cameras used pixel perfect. Any other solution is welcome

    The images&gif and the package are from 2023.1 beta

    example gif: when the pivot of the lowest pillar leaves the camera frustum the shader fails because LightTexture doesnt have "padding"
    2023-03-08_17-53-31_AdobeExpress.gif

    shader for the pillar and the cube:
    upload_2023-3-8_18-5-51.png
    the light texture in the shader(you can also get this by using a sprite custom lit shader and using the Light texture node):
    upload_2023-3-8_18-6-20.png
     

    Attached Files:

    Last edited: Mar 10, 2023
    X2DGmDev and Neil-Corre like this.
  2. venediklee

    venediklee

    Joined:
    Jul 24, 2017
    Posts:
    145
    Correction: It looks like rendering with a larger non-pixel perfect camera to a large render texture; then rendering a screensize region of that rendertexture with a pixel perfect camera works, I don't know why I was getting non-pixel perfect behavior yesterday.

    I'll update this post with a guide and a demo scene when I have the time
     
    X2DGmDev and Neil-Corre like this.
  3. blizzy384

    blizzy384

    Joined:
    Dec 22, 2021
    Posts:
    8
    Thank you so much! This is exactly what I would need. Would be very appreciated if you would provide guide and a complete example.
     
  4. venediklee

    venediklee

    Joined:
    Jul 24, 2017
    Posts:
    145
    I’ll write a small guide alongside possibly a guide for geometric 2d shadows(shadows bend when it hits a wall etc) tomorrow
    edit: had to fix a camera order related bug, I'll write the guides & repositories first thing in the morning tomorrow!
     
    Last edited: Sep 9, 2023
    X2DGmDev likes this.
  5. blizzy384

    blizzy384

    Joined:
    Dec 22, 2021
    Posts:
    8
    Thank you very much Venediklee!
     
  6. venediklee

    venediklee

    Joined:
    Jul 24, 2017
    Posts:
    145
    blizzy384 likes this.