Search Unity

Question Shaders and 2D Lights : how to make 2 renderer work in parallel ?

Discussion in 'Universal Render Pipeline' started by PaulKhill, Oct 20, 2020.

  1. PaulKhill

    PaulKhill

    Joined:
    Jul 30, 2020
    Posts:
    15
    Hello all,
    I've been following this video to implement a 2D underwater distortion effect.
    My shader works fine as long as the default renderer is the URPAsset Renderer created with the URP. But I want to use 2D Lights too. Which use 2D Renderer. And works fine too as long as it is set as default on the URP.

    But when it comes to having them both work at the same time, it doesn't work. I've tried adding a rendrerer to the Renderer list of my URP, but it doesn't seem to be using both. Ideally I'd like to set one the URPAsset renderer for my distortion shader (and that one only) and 2D Renderer for the rest. Any idea if this can be achieved ?
     
  2. PaulKhill

    PaulKhill

    Joined:
    Jul 30, 2020
    Posts:
    15
    Hey ! Thanks for the tips, there is some progress, but I'm not there yet.
    So I've setup a second camera, and two things can happen :
    - I set my main camera with 2D Renderer. 2DLights are created, and shader appears BUT doesn't take into account the 2DLights (distortion happens on the unshadowed background)
    - I set my main camera with UPRForwared. 2DLights aren't created, shader appears.

    I've tryied tweaking some of my cameras options to not avail. I'm thinking maybe there's something I should do in the shader ? Like tell him to get its screen color from another camera ?
     
  3. PaulKhill

    PaulKhill

    Joined:
    Jul 30, 2020
    Posts:
    15
    Thanks again ! Learning a lot.
    Basically, this is a 2D game. So both cameras would be 2D Cameras.
    Most of the game happens underwater, and lights are quite important to the feeling of the game.
    I've successfully manage to implement 2D lights, but I'm trying to add a distortion shader to the water so that everything behind it is distorted (as i you where, you know, underwater).
    The shader works, it distorts the level, but as if the level wasn't lit (or as if no shadows were cast).
    Here's a screen as well as the configs of my two cameras.
    I just changed the shader from unlit to lit, to no extend.
     

    Attached Files:

  4. PaulKhill

    PaulKhill

    Joined:
    Jul 30, 2020
    Posts:
    15
    Hello yuta1985, sorry to up this, any ideas ? :)