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.

Feature Request Forward Rendering Light Data in Universal2D

Discussion in 'Universal Render Pipeline' started by Yatsomi, Mar 26, 2022.

  1. Yatsomi

    Yatsomi

    Joined:
    Dec 20, 2015
    Posts:
    3
    Hi there,
    We are developing a Pixel art Game and we have an edge light shader that uses forward lighting data (3D point and spotlights) to calculate the edges. It's fine with URP Forward renderer, but we want to use it alongside 2D Lights. Therefore our shader pass should be "Universal2D". The problem is, there is no information about 3D lights in this pass. So if you for example use GetAdditionalLight() function in a Universal2D pass, you get nothing. URP doesn't support multi-pass either. We got it working somehow using URP Render Features and 2 Cameras, Base(ForwardRenderer) and Overlay(2DRenderer). But there is a couple of problems. 2D light layering got messed up and also we can't see the final result in editor window, but just the play window. I dig a little bit in URP package and tried to get lighting data from somewhere, failed.

    Is it possible to include 3D lighting data in "Universal2D" pass? I'm sure there are some people like me who need that data even in a 2D lighting scene.
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,530
    As a workaround - use render feature to populate your own structured buffer of lights data, queued before 2d passes, and then just use that.
     
  3. Yatsomi

    Yatsomi

    Joined:
    Dec 20, 2015
    Posts:
    3
    Hey man,
    Sorry for the delayed response. I was working on other aspects of the game. Going to test your workaround in a few days and let you know if I succeed. Thank you!
     
  4. Yatsomi

    Yatsomi

    Joined:
    Dec 20, 2015
    Posts:
    3
    So, your idea kind of worked. Not as I expected, but it's a workaround for sure.
    I have stack of 2 URP renderers: Forward and 2D. Using a custom render feature (attached to forward renderer), I got access to renderingData, which contains lightsData that itself contains a list of VisibleLights. VisibleLights includes localToWorldMatrix (position and direction of the light), finalColor (light color + intensity) and spotAngle. I passed all these data to the shader (which is nessecery to calculate light effect) using multiple compute buffers. Finally I calculated lights attenuation for both point and spotlights. Done.

    Thanks man. It was a good idea.