Search Unity

Question Why is Shadow Acne much worse on default LWRP shaders and Amplify Shaders

Discussion in 'Shader Graph' started by nickrart, May 28, 2019.

  1. nickrart

    nickrart

    Joined:
    Mar 24, 2017
    Posts:
    31
    Shadergraph has great results visually, but doesn't have certain features so we use Amplify sometimes. But Amplify has the same terrible shadow acne as default shaders. What is Shadergraph doing that default isn't? And is it something I can write into the shadowcaster for AmplifyShader template?

    LWRP/Particles/Lit and LWRP/Terrain/Lit also don't receive this shadow acne

    LWRP version 4.10

    Shadow settings are:
    Distance 50
    NoCascades
    DepthBias 0.05
    Normal Bias 0.1
    Hard Shadows

    shadow_acne.jpg
     
  2. nickrart

    nickrart

    Joined:
    Mar 24, 2017
    Posts:
    31
  3. nickrart

    nickrart

    Joined:
    Mar 24, 2017
    Posts:
    31
    Or is this more appropriate for a different forum
     
  4. nickrart

    nickrart

    Joined:
    Mar 24, 2017
    Posts:
    31
    I can see Shadergraph is doing some extra calcs for tangent/normal etc. Is this what makes it look so much better?

    Code (CSharp):
    1. // Vertex transformations performed by graph
    2. float3 WorldSpacePosition = mul(UNITY_MATRIX_M,v.vertex).xyz;
    3. float3 WorldSpaceNormal = normalize(mul(v.normal,(float3x3)UNITY_MATRIX_I_M));
    4. float3 WorldSpaceTangent = normalize(mul((float3x3)UNITY_MATRIX_M,v.tangent.xyz));
    5. float3 WorldSpaceBiTangent = cross(WorldSpaceNormal, WorldSpaceTangent.xyz) * v.tangent.w;
    6. float3 WorldSpaceViewDirection = _WorldSpaceCameraPos.xyz - mul(GetObjectToWorldMatrix(), float4(v.vertex.xyz, 1.0)).xyz;
    7. float4 uv1 = v.texcoord1;
    8. float3 ObjectSpacePosition = mul(UNITY_MATRIX_I_M,float4(WorldSpacePosition,1.0)).xyz;
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Is your sphere receiving any shadows?
     
  6. nickrart

    nickrart

    Joined:
    Mar 24, 2017
    Posts:
    31
    Yes. That example is a plain Shadergraph without nodes
     
  7. nickrart

    nickrart

    Joined:
    Mar 24, 2017
    Posts:
    31
    Quote from Amplify Shader people.
    I didn't look into it, but just by looking I would say it's shader graph that is wrong here. That's because the different shadow bias values are global values that used in individual shaders to make sure your shadows look correct in your scene setup, so when you change these all your materials look correct. You absolutely have to use some values (otherwise you'd always get shadow acne) but considering shader graph version doesn't have any acne means they are using their own values that most likely can't be edited. You probably wont find these values by opening the shader code, they defined and used in the built-in shader code. (it has nothing to do with those matrices transformation, and yes ASE can do those as well through transform nodes) In order to detach this global setting the shadow and depth pass must be rewritten to use material values instead. This would mean a huge endeavor for us, but if absolutely need it you need to create your own template (copy for an existing one) and edit the depth and shader passes to do shadow differently. I don't know for sure how difficult this is, didn't try it, I'm just giving you an entry point.


    So after a little more testing is looks like Shadergraph simply multiplies the global values. It isn't actually 'better' it just uses a different range. If i set the Bias values to look good for Default and Amplify then the shadows for Shadergraph become too skinny. Another example here, the object in center looks like its floating

    shadow_acne2.jpg
     
  8. nickrart

    nickrart

    Joined:
    Mar 24, 2017
    Posts:
    31
    Seems like Depth Bias 0.1 on Shadergraph gives same look as DepthBias 10 on LWRP Lit and Amplify
     
  9. nickrart

    nickrart

    Joined:
    Mar 24, 2017
    Posts:
    31
    I guess I should submit this as a feature request? Otherwise I'ma have to convert all my Shadergraph to Amplify :( As of now I can't use both. The difference in Shadow bias is too much to look decent for both
     
  10. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    It's just a bug, one that's already been fixed in the more recent versions of LWRP.
     
  11. nickrart

    nickrart

    Joined:
    Mar 24, 2017
    Posts:
    31
    ooooh, cool thanks