Search Unity

Outline on Shadows URP

Discussion in 'Universal Render Pipeline' started by Gionagx, Sep 22, 2021.

  1. Gionagx

    Gionagx

    Joined:
    Nov 9, 2020
    Posts:
    9
    Is there a way to create Shadows with outline in URP like in Sable?
     
    Gyro_Zeppeli likes this.
  2. Jonas-Mortensen

    Jonas-Mortensen

    Unity Technologies

    Joined:
    Jan 3, 2020
    Posts:
    110
    Anything is possible in URP! ;)
    This can be done as a post processing image effect. The image effect will do edge detection on the scene color, depth and normals and draw strokes based on that. The shadows would get their stroke because of the big color difference between lit and shaded areas.
    There is no off-the-shelf solution provided by URP but I really recommend this article by Alexander Ameye. In the article, Alexander uses his own depth+normals prepass. This could be handled by URP by using the ConfigureInput() function meaning that only the image effect pass would be needed (in terms of custom passes). Alexanders solution however should still be perfectly fine!
     
    Last edited: Sep 22, 2021
  3. Gionagx

    Gionagx

    Joined:
    Nov 9, 2020
    Posts:
    9
    Thank you so much !!!!
     
  4. Gionagx

    Gionagx

    Joined:
    Nov 9, 2020
    Posts:
    9
    Thanks again for the help, however, I'm encountering a problem with this shader. I'm using 2D sprites in a 3D environment and, with unity's base Sprite shader, I can see outlines through them (as you can see in the screenshot). Moreover, with a custom shader that I use to apply normals to a sprite, I can see outlines on the border of the generated sprite mesh (which shouldn't be the case since it's transparent). Is there any way to fix this?
    This happens with all sprites (even with world space UI) so it must be something connected to sprites rendering.
    photo5940279829154870544.png photo5940279829154870543.png
     
  5. Jonas-Mortensen

    Jonas-Mortensen

    Unity Technologies

    Joined:
    Jan 3, 2020
    Posts:
    110
    @Gionagx
    If there is an outline, it means there is a hard transition in at least one of the three buffers (depth, normal, color) that the edge detection is performed on. Have you ever used the frame debugger? You should be able to find the depth+normal pass in the frame debugger and see what it looks like. My guess is that:
    • The sprite in the top image is not writing to depth, and so the depth data (from behind the sprite) causes outlines to be drawn
    • The mesh in the bottom image draws normal data to an alpha clipped area meaning the normal buffer actually contains a transition in those areas although not visible on the color
     
  6. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    Hey @Gionagx just wanted to add something: this article here https://alexanderameye.github.io/notes/rendering-outlines/ also has a section regarding ‘edge detection’ that might be of interest. The post that @Jonas-Mortensen shared has been written a while ago and in newer versions of URP you don’t need generate a custom depth-normals texture because it’s already done for the AO pass in URP.

    I just peeked at my own shader code in a more recent project and I do something like this:

    Code (CSharp):
    1. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
    And then you can call the function ‘SampleSceneNormals’ to access the normals value and use it when detecting discontinuities. About your issue, I think Jonas is right about the sprite not writing to the depth buffer.
     
    PolyCrusher and Jonas-Mortensen like this.
  7. Gionagx

    Gionagx

    Joined:
    Nov 9, 2020
    Posts:
    9
    I tried to remove the outline from sprites but i didn't find any solution, do you guys know of a way to make it that the outline render doesn't hit the sprites?