Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Strange "shadow" with directional light when the camera is far from the origin.

Discussion in 'General Graphics' started by MioMilo, Apr 23, 2015.

  1. MioMilo

    MioMilo

    Joined:
    Apr 23, 2015
    Posts:
    3
    hello !

    I'm new with unity, and actually working on my first project. I'm getting an annoying bug with my directional light, see by yourself :



    as you can see, in my game you play a "spaceship" who need to avoid obstacle while moving forward. At the start there is no issue, but when I start to be far from the origin ( on the screen I'm about 70 000 in z axis) , I start to have some weird shadow bug.

    I think it's shadow because when I disable shadow on my Iight don't have any issue.

    It also seem to have something to do with Bias, because those shadow change when I change Bias setting on my light, but it don't solve the issue.

    Am I doing wrong when I go that far from origin point ? How can I fix this bug ?

    Thanks !
     
    Last edited: Apr 23, 2015
  2. MioMilo

    MioMilo

    Joined:
    Apr 23, 2015
    Posts:
    3
    Nobody know about this issue ?
     
  3. KingMatthew

    KingMatthew

    Joined:
    Jul 7, 2013
    Posts:
    166
    I would recommend bring the track too you. The spaceship shouldn't move forward, the track should move so that you are always at the origin point. Buggy shadows aren't the only thing that happens far from the origin points
     
  4. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    After around 65k you can easily run into issues, This due to that being 16 bit's worth...
    Either move the entire track, (could easily be a LOT of game objects and their heriarcy's to recalculate), or "restart" the camera + move everything every now and then. (I'd suggest not allowing values to go over 50k if avoidable).
     
  5. MioMilo

    MioMilo

    Joined:
    Apr 23, 2015
    Posts:
    3
    That's what I feared... I got a lot of things to change now.

    Anyway, thanks a lot for the Answer !
     
  6. ZTORION

    ZTORION

    Joined:
    Sep 27, 2014
    Posts:
    13
    I ran into the same problem, but the shadows start to flicker and jump around much earlier. Of course it depends on the camera clip planes, but even with the default values of 0.3 and 1000, it is not possible to move further away from the origin than 10.000 units. I have created a repro setup because it certainly is a bug.

    With the current situation it is not possible to create a flight simulation in Unity that uses realtime shadows.

    [EDIT] note that the repro project was created in Unity 5.1.0f3
     

    Attached Files:

  7. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    A 32-bit float can only store about 7 decimal numbers, which means that, if you're 10,000 units forward, it can store 10,000.00. However, the last digit or two will be approximate themselves. Hence, you start seeing precision problems.

    One solution is to use a floating origin point; that is, when the player moves a certain distance (such as 6,000 m), move them back to the center, and move the world so that things stay the same relative distance. Another is to divide the world into local origin points; but AFAIK that's currently not possible; Unity would have to add code to allow for it. The present shape of the engine seems to allow for only one origin point for transforms.

    I don't know if Unity could implement defaults for either; that's a question for someone who works there.
     
  8. ZTORION

    ZTORION

    Joined:
    Sep 27, 2014
    Posts:
    13
    I dont think that the floating point precision is already an issue at these short ranges. If you set the near clip plane to 0.1, artifacts start already at less when 1000 units away from the origin. Look like in incorrect calculation of a projection matrix for the light. I mean, when the shadow range is 150 or 200 units, there is plenty of precision.

    [Edit] world space precision cannot be the problem, because points lights work without problems even at 50k units away from the origin. So obviously the directional lights are rendering incorrect ranges. Why not allow setting the ranges manually, just like the camera clip planes? That way you could also fix the spot light shadow range bug.
     
    Last edited: Jun 11, 2015
  9. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    The general implication/assumption was that the OP was moving the player forward, not the ground backward. If that was in error, then yeah, floating point imprecision is not the problem, and my post was not helpful for this instance.
     
  10. Tallek

    Tallek

    Joined:
    Apr 21, 2014
    Posts:
    34
    I am experiencing similar problems after upgrading a project from Unity 4 to Unity 5. Our game world is pretty big (flight sim). Everything worked great in Unity 4. In Unity 5, we started having serious problems with shadow flicking and what looked like z-fighting. We started implementing a floating origin, and this seemed to fix some of the problems. We still have some serious shadow issues on some Android devices however, and no matter what I try, nothing seems to fix it (other than forcing OpenGLES2, which fixes that problem but creates many more (and much worse) on my Galaxy s6).

    Here is what I am currently seeing on a couple android devices:




     
  11. WendelinReich

    WendelinReich

    Joined:
    Dec 22, 2011
    Posts:
    228
    bump that @Tallek did you file a bug report, or could you do so? i just got an s6 and I also get strange artifacts (though I dont use shadows)
     
  12. Elaha

    Elaha

    Joined:
    Jun 21, 2015
    Posts:
    3
    Same problem on my s6 too.
    So i had to change shadow Bias 0.5, Normal Bias 1.0, but this measure is only provisional and also shows low quality of shadows.
     
  13. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You guys have to file bug reports or this stuff doesn't get fixed. And if there is no repro scene it may not get fixed.
     
    WendelinReich likes this.
  14. Tallek

    Tallek

    Joined:
    Apr 21, 2014
    Posts:
    34
    I did file a bug report: https://fogbugz.unity3d.com/default.asp?704778_mei2qomsv78l95mj

    Here was the response I got:

    We did some more investigation regarding this issue and it appears that the problem that you see different results in a device is this: the Mali GPU (that's inside Galaxy S6) can use 16-bit floating point precision whenever possible for a performance boost, whereas on desktop everything is 32-bit floating point precision all the time. The issue is not fixable on our end, but the very simple workaround is to increase shadow bias in the light inspector, once that is done, the problem disappears.

    I will be closing this case now. If you have any further questions, don't hesitate to ask!​

    Funny how it wasn't fixable on their end, though it worked great in Unity 4.6 with the project I provided to them. Pretty disappointing...
     
  15. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Did you increase the shadow bias?
     
  16. Tallek

    Tallek

    Joined:
    Apr 21, 2014
    Posts:
    34
    I definitely played with the shadow bias. I don't remember all the details, but I never settled on anything that I'd call a working solution. I think I was seeing the issue regardless of bias, but bias did 'start' to help. Increasing the bias though, causes all my intended shadows to start disappearing.
     
  17. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Well this sounds a bit bad if it was working previously. It would call it a bug, still. Did you reply to the email from the but report? it will reopen the case AFAIK so you can explain about it not being present in 4.6.

    Also is 24-bit depth buffer checked?
     
  18. Tallek

    Tallek

    Joined:
    Apr 21, 2014
    Posts:
    34
    Not sure where that option is. Was under the impression it went away in Unity 5.

    I haven't had much luck with my Unity bug reports. I've submitted several, most of which I've never heard back from. Those I have heard back on, were essentially, sorry-but-deal-with-it responses. I had not replied to this one as my last reply on a similar sort of issue went unanswered. I gave up...
     
  19. thefirstplaybae

    thefirstplaybae

    Joined:
    Feb 15, 2013
    Posts:
    16
    Hi,
    Has anyone found a viable solution for this issue yet? I am facing the same issue with my endless runner.
     
  20. Jerry_Davis

    Jerry_Davis

    Joined:
    Jan 29, 2022
    Posts:
    5
    adjust the bias setting of light shadow, will fix it. that is my solution