Search Unity

Question How can I add "post-effects" to "_ShapeLightTexture0" (after light render, but before scene render)

Discussion in 'Universal Render Pipeline' started by Andrew900460, Sep 21, 2021.

  1. Andrew900460

    Andrew900460

    Joined:
    Aug 9, 2017
    Posts:
    40
    TLDR: Start reading from where it says "Actual Question"

    To preface myself here. I understand if accomplishing this requires interacting with API's that are not deemed "public" yet. And it may be unrecommended to attempt this. But I don't care, part of me wants to do this to learn about rendering, and how URP and SRP works, and what they provide to allow me to create custom effects. The purpose of this new pipeline is to allow people more control over how their games look, and that is what I want to use URP/SRP for. And I'm not waiting for something to go out of "experimental" to use it.
    Anyway.

    Essentially, I have been doing personal research into how the 2D renderer in URP works, and how it actually renders its 2D lights and shadows. I've looked at the source code in the package folder trying to learn all the "key names" of things that are going on within the 2D renderer. Because I personally want to be able to extend what the 2D renderer can do for my own projects.

    Because I don't want to have to write my own code for rendering 2D lights when someone has done it for me already. BUT, I do want to be able to take what the 2D renderer provides and apply custom effects.

    Actual Question starts here

    From what I understand, there is an internal texture that is used for rendering 2D lights ("_ShapeLightTexture0"). Before the sprites are actually rendered, the lights are rendered to this separate texture. And I believe that there is also a separate "ShadowTexture" which holds data for where there are shadows? But after looking at the Frame Debugger, it looks like the shadows are rendered directly to the Light Texture. Either way.

    What I am actually wondering about is how I would go about applying some effect to the "_ShapeLightTexture0" texture, BUT BEFORE the part of rendering where that texture is used to actually render the scene. So the lights will inherit this "post-effect".
    Like: "Render Light Texture" --> "My Custom Light Effect (shader)" --> "Render Scene Sprites (sprite-lit)"

    I'm trying to figure out which classes in SRP I need to use. Whether it be "ScriptableRendererFeature" or "ScriptableRenderPass" or some other class I've yet to discover. I am stuck looking at the 2D renderer code looking for an idea of how to "inject a render pass" after the lights have been rendered. But I just can't find anything.
    Or in a more general sense. How I am supposed to add my own "render passes" and determine if they should happen *before* or *after* other passes that exist inside the existing renderer.

    Essentially, I want to put something between those 2 green arrows in this image. hdsgdthdfh.png
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    Hi, the 2D Renderer isn't very extensible right now. Not sure what's possible with passes.

    At worst, you may need to fork it. Forking a package takes a bit of extra work. You need to download the source code from Github and add the folders of the packages as a disk directory in the Package Manager. Then you can modify the source without it auto-reverting.

    A notable example of someone who has done this is @ThundThund, see this thread.
     
    Last edited: Sep 21, 2021
  3. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    346
    There's only one texture, the one you mentioned, _ShapeLightTexture0, there is no "shadow texture". The light texture is used for calculating the color in the sprite lit shader for a group of geometry. It is overwritten several times per frame depending on the configuration of the sorting layers of the lights and the sprites. There is no possibility to manually write to it without modifying the code of the Renderer2D class and enqueueing a custom ScriptableRenderPass.