Search Unity

Question Possible to change "normal bias" for shadow maps to use fragment normal instead of vertex normal?

Discussion in 'High Definition Render Pipeline' started by LordQuaggan, Jul 21, 2021.

  1. LordQuaggan

    LordQuaggan

    Joined:
    Mar 22, 2020
    Posts:
    6
    Edit:

    After considering this further, I have realised my initial request is pretty much impossible, as fragments obviously cannot change position during rendering, whether creating a shadow map or not, as otherwise there would end up being gaps. I have found that creating a separate game object for shadowcasting that is smaller than the main one works reasonably well, although there is still the issue that increasing the normal bias from 0 still causes artifacts when receiving shadows. Therefore, my new question is whether it is possible to prevent the camera's normal bias from being applied to certain game objects?

    Original post:

    I have been creating some volume shaders (applied to the bounding boxes of the objects) using Shader Graph with HDRP in unity to render objects such as spheres perfectly - i.e. without any triangles.

    I have managed to get almost it mostly working correctly as if it was a mesh of that shape (by offsetting the depth and assigning the normal based on ddx and ddy of the computed intersection point), however one issue that remains is that shadows have some pretty significant artifacts. If the "normal bias" for the light source is reduced to 0, it is clear to see that these objects are able to cast and receive shadows correctly:

    Capture.PNG Capture2.PNG (Box collider is used to show underlying cube geometry)

    However, having a normal bias at 0 causes many artifacts, not just for these volume objects but across the scene.

    Capture3.PNG

    Unfortunately, changing this normal bias setting breaks shadows received by these volumes as it appears Unity uses the vertex normal instead of the fragment normal when applying this bias, causing the underlying cube geometry to show become evident in how the shadow is drawn.

    Capture4.PNG

    And as the normal bias is not in the direction of the actual normal, where this is at it's most extreme the self-shadowing artifacts are still visible!

    Capture6.PNG

    Therefore, I was wondering if there is some way to change the behaviour of this "normal bias" setting as to use the fragment normal instead. Any help would be greatly appreciated!
     
    Last edited: Jul 22, 2021