Search Unity

Bug Character Shadow

Discussion in 'Open Projects' started by Ruchir, Nov 28, 2020.

  1. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    I don't think it's possible to fix this because of the way the shadow is implemented right now in unity but it still doesn't look good so I pointed it out
    CharacterShadow.png
    CharacterShadow_1.png
    CharacterShadow_2.png
    You can see that the character shadow is applied to objects not directly receiving it, i.e, below the rocks too in this case
     
    cirocontinisio likes this.
  2. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    Also, objects (tree and rocks) in this scene don't cast a shadow on the character, is this intentional or a bug (related to baked objects) 'cause in the opening scene the (one with the two triggers) they do cast a shadow onto the player
     
    cirocontinisio likes this.
  3. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Hey both!

    There's something we can do, and I prototyped it already. Basically inhibit the shadows where the faces of the geometry are facing away from the Directional light. A decent improvement.

    Before:
    Original.png

    After:

    Fixed.png

    This works very well in this scene where the platform is flat and goes down like that. It would look decent in your situation with the tree.
    In the scene with the rocks though, what this does is that if you're on top of the tall rock, the shadow is broken by the rocky steps, so at that point it would look better without the fix. So it's very dependent on the geometry we are talking about.

    The other thing is the projection of the shadow on distant geometry which should be obstructed. This happens in your scene with the rocks in the bottom right corner, and in my pic at the bottom, and it's because of course we are making the character's shadow black while making brighter the environment shadows, so the character one is super noticeable.

    upload_2020-11-28_17-37-48.png

    The part in red should be the same colour as the baked map. We can actually do this easily, since we have the information on that area, so we can subtract those pixels from the black patch.
    The problem is when the character is walking "on" that baked shadow (i.e., he's on the grass in that picture) then you expect the black shadow to be overlapping the baked one.

    So... I don't know how to solve this right now. It would probably require some bit of hacking of the custom HLSL code we use, or something.
    Right now I am inclined to ignore it, or just implement the fix as detailed above, which should improve things and be enough for most cases.

    Ideas?

    That's normal. They are baked, so Unity is not calculating shadows for them every frame. In the opening scene they are not baked.
    You can easily tell baked vs. non-baked objects in this game because the dynamic ones have the black shadow.
     
  4. Smurjo

    Smurjo

    Joined:
    Dec 25, 2019
    Posts:
    296
    I think the problem is that the shadow of the rock (or whatever the geometry is) has a different color than the shadow of character, which isn't natural. If they both were of the same color, the result would be correct.
     
    cirocontinisio likes this.
  5. treivize

    treivize

    Joined:
    Jan 27, 2016
    Posts:
    136
    After some tuning in LightningModel shader graph (basically clamping the shadow value to a certain amount matching the baked shadow area), I have been able to get this result:


    Modified graph:
    upload_2020-12-1_23-45-6.png
     
    XIV_Dis and Smurjo like this.
  6. treivize

    treivize

    Joined:
    Jan 27, 2016
    Posts:
    136
    Is there a way to determine the distance between the shadow and the geometry casting it in HLSL? Because a good solution maybe would be to to cast the character shadow dark when it is close to it, but reduce it quickly to reach the baked shadow value when the distance become bigger than the one between the pig head and its shadow when walking on the ground.
     
  7. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Not really, and that's kind of the whole point. Without knowing how far the shadow is, you can't adapt it to the situation.
    Sure, one could do a raycast and check, but it would be just one for the whole character, you can't do it per-fragment. Which means that if the character is on a ledge, you wouldn't get the effect you want (half of the shadow is black, the other half faded).

    I would say don't worry too much about it. It really depends on the final geometry and I don't think we'll have stuff like bridges, suspended platforms or things like these which would really show the issue.
     
    erizzoalbuquerque likes this.
  8. shuttle127

    shuttle127

    Joined:
    Oct 1, 2020
    Posts:
    183
    But but but, those cool platforms!!! :p
     
    cirocontinisio likes this.
  9. khushalborana537

    khushalborana537

    Joined:
    Dec 2, 2020
    Posts:
    4
    I think I can fix this bug.
     
  10. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    How?
    Also it's not a bug :D
     
    Ruchir likes this.
  11. khushalborana537

    khushalborana537

    Joined:
    Dec 2, 2020
    Posts:
    4
    I mean to say I can do it
     
  12. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Yes, yes. But I was curious on what strategy you are thinking of. Since it's not a bug, there is not just one right way to do it. Can you elaborate a bit?
     
  13. treivize

    treivize

    Joined:
    Jan 27, 2016
    Posts:
    136
    In my opinion, we have to do to solve this problem, it is too sad that we will not be able to propose some puzzle quest with platform like drawn by on the concept art from @laczkyl because the character shadow is not working well on platforms...

    So, following my latest deep thinking of improving outline, I may have found a good compromise to improve the shadow of dynamic objects especially the main character.

    My approach is based on a new Render Pass, through a pass similar to the one used to identify the outline object. BTW, I will rename the variables, classes and methods to be more generic in the ScriptableRendererFeature of my current PR on outline since it can be used for other problem.

    Here, the idea is to do a render pass and rendering only object under a new ShadowMask layer. These object are not casting any shadow and are not normally displayed. The object I used is a simple "capsule" around the character but with a particular shader where front faces are hidden and double side, the red channel is fading away more the surface is far from the center:
    upload_2020-12-12_0-4-23.png

    Next this texture is used in ToonLightingModel to modulate the strong shadow of dynamic object. If the shadow of the character is inside the mask, the shadow is strong and modulate by the mask intensity, when out of the mask the shadow is clamp to the static object shadow amount (a light grey).

    upload_2020-12-12_0-11-6.png

    Here is the result:
     
  14. Alex311

    Alex311

    Joined:
    Dec 20, 2012
    Posts:
    6
    I don't know if it's the same problem, but do you notice the shadow on the character when you climb on the rocks ?

    UOP1_Project - GroundShader - shadow on the character.gif
     
    Last edited: Feb 4, 2021
  15. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Ah no, don't worry: that's just because when you jump, in that moment, the closest Light Probe is below the rocks. We just need to add a new light probe and rebake. I'll do it later on.
     
  16. Alex311

    Alex311

    Joined:
    Dec 20, 2012
    Posts:
    6
    Ok, thank you for your explanation.
     
    cirocontinisio likes this.