Search Unity

Shadow artifacts (flickering) with deferred lighting.

Discussion in 'General Graphics' started by Sparty, Oct 16, 2012.

  1. Sparty

    Sparty

    Joined:
    Aug 26, 2010
    Posts:
    83
    Im getting weird shadow artifacts In the editor view as well as game view. I am using deferred lighting (forward lighting has no problems with the shadows).

    Some settings (all tweaked, but still no luck fixing this).......

    Directional light

    Shadow type = soft
    Strength = .8
    Resolution = Fantastic
    Bias = .35
    Softness = 4
    Softness fade = 1

    Quality = fantastic
    Shadow resolution = Very high
    Shadow projection = Close fit
    Shadows cascades = Four
    Shadow distance = 300 (lower numbers have not helped)

    Heres what it looks like.
    http://youtu.be/K7yb66C3bbI


    Thanks for the help!

    -Eric Provan
     
    Last edited: Oct 16, 2012
  2. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    What is your camera's near and far clip planes set to? Try increasing the near clip plane.
     
  3. Sparty

    Sparty

    Joined:
    Aug 26, 2010
    Posts:
    83
    Fixed! Far clipping is 10,000, and the near is .1. Changing these numbers did nothing to fix the problem. However, it got my thinking. I scaled everything in my scene down to a much smaller scale. Still no luck, but, when I scale everything in my my scene much larger, the problem is fixed.

    This leads to a new problem though. My game is very far along. I'm afraid that scaling every one of my scenes way up may break many things. Perhaps this knowledge can lead to a more simple solution that doesn't involve scaling every thing way up?

    Thanks for the help!

    -Eric
     
    theANMATOR2b likes this.
  4. Sparty

    Sparty

    Joined:
    Aug 26, 2010
    Posts:
    83
    Just to confirm. While Scaling everything up from 1 to 4 fixes the shadow issue, it does indeed break my game :(
     
  5. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    What numbers did you try adjusting the near and far clip planes to?

    What size is your level... if you place a default Unity cube next to one of the houses how big is it relative to the house?
     
  6. Sparty

    Sparty

    Joined:
    Aug 26, 2010
    Posts:
    83
    Default cube is about the size of two of the houses windows. I have tried near clipping 0.001 to 5.0 and far from 100 to 1000000.

    Thanks
     
  7. Sparty

    Sparty

    Joined:
    Aug 26, 2010
    Posts:
    83
    Someone on youtube mentioned that I should mess with the shadow bias on my directional light. I have done this, but it wont let me go past the setting 0.5. Does anyone know of a way to force is to go above 0.5 bias?
     
  8. Sparty

    Sparty

    Joined:
    Aug 26, 2010
    Posts:
    83
    Actually, while I'm still curious about upping the bias past 0.5, I really dont see how it could help. Bah, this is a tough one. It would take me 2 months to get my game back to were it is if I end up having to scale everything up to 4.0! =(

    -Eric
     
  9. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Ok, a few more things to test. How far away from the world origin point (XYZ = 000) is the directional light and this particular part of your level?

    Does this flickering happen in other levels or other parts of this level?
     
  10. Sparty

    Sparty

    Joined:
    Aug 26, 2010
    Posts:
    83
    This part of the level is about 1000 units from the light which is 0,0,0. Moving the light around didnt help anything. Flickering happens 100% in all 11 levels of my game. Its always been a problem, but it seems like it recently got worse.
     
    Last edited: Oct 17, 2012
  11. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Ok, unfortunately it might be bug report time. If you can isolate a small portion of your level that reproduces the issue and can send that in as a bug report that would be much appreciated. Please PM me the case number if you do report the bug.
     
  12. Sparty

    Sparty

    Joined:
    Aug 26, 2010
    Posts:
    83
    Doh! Not good. I am going to investigate how much work will be added if I have to scale everything up x 4. I have a feeling its going to be very very time consuming, but its at least worth investigating. I cant imagine trying to figure out all ther raycasting distances again =(
     
  13. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    It's probably more time consuming than sending in a bug report to see if we can fix it on our end ;-)

    A bug report would be appreciated... scaling up your entire game is a really ugly workaround.
     
  14. Sparty

    Sparty

    Joined:
    Aug 26, 2010
    Posts:
    83
    Woohoo! I have finally made some headway. So, if i group everything in my scene with the pivot near the center of everything, and then set the group to 0,0,0. Shadows for fine again. This leads to new problems, but nothing like what scaling would have down.

    Im still going to report a bug, but my project is huge, so I just need to sit down, duplicate it, and make it much smaller so I can attach it to the bug report. Thanks for all the help so far.
     
  15. Sparty

    Sparty

    Joined:
    Aug 26, 2010
    Posts:
    83
    A friend did some more testing.
    "I tested it, moved objects from center on X axis and shadows start weird things from 1300-1400 distance."

    -Eric
     
  16. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Looks like floating point errors somewhere due to numerical ranges. As a guideline everyone should embrace the 1 unit = 1 meter concept, because it generally fits quite well with numerical ranges and also physics and even the unity editor itself.

    If the problem is within the editor view itself, it could be just the editor's camera clip ranges are way off. To fix that:


    1. select object
    2. mouseover the scene view window
    3. press F to focus on it.

    This will fix z buffer errors within the actual unity editor environment. I add this in case future readers stumble across potential similar problems that may be related.
     
    Last edited: Oct 20, 2012
    Martin_H likes this.
  17. Morning

    Morning

    Joined:
    Feb 4, 2012
    Posts:
    1,141
    Can it really be float point issue though? If it's only at a thousand units, then there's still 3 more numbers after the decimal. That should be enough for things, right?
     
  18. Sparty

    Sparty

    Joined:
    Aug 26, 2010
    Posts:
    83
    "If the problem is within the editor view itself", No, unfortunately its happening in the editor as well as in game.
     
  19. Julien-Lynge

    Julien-Lynge

    Joined:
    Nov 5, 2010
    Posts:
    142
    Just FYI, I'm still seeing this error in the very latest version of Unity (4.5 and 4.6 beta) several years later. We have a part of our scene set up about 700 units from the origin, and we see shadow flicker on just a couple of our meshes. Interestingly, it only happens in play mode - you don't see it in the scene view in the editor, and you don't even see it in the play window when moving a camera around but not playing. You have to actually hit play and move the camera around, and you'll see shadow flickering almost as if the shadows are z-Fighting with the mesh.

    It does seem to be some sort of a zBuffer issue. It's worst on our camera that was set to (0.03, 500) on the clip planes, better for default values of (0.3, 1000), and almost entirely fixed if we set the near clip plane to 1.

    Did anyone ever submit a bug on this? Do you have a bug report number?
     
  20. Loden_Heathen

    Loden_Heathen

    Joined:
    Sep 1, 2012
    Posts:
    480
    Just to chime in here as this is a problem we faced as well;

    Our game is set in space with rather large distances at play; we do use 1 unit = 1m at the moment and would prefer to stay with this if at all possible.

    We had the shadow flicker issue always but it got rather bad in 4.6 and 5b so set out to sort it. For us the solution was simply to set the camera clip to 1,10000 which is no problem in our scenes. Hope this proves useful to others.
     
    theANMATOR2b likes this.
  21. ZTORION

    ZTORION

    Joined:
    Sep 27, 2014
    Posts:
    13
  22. Loden_Heathen

    Loden_Heathen

    Joined:
    Sep 1, 2012
    Posts:
    480
    Just a few notes on this one as we have moved further in development we have recently switched to a 2 camera approach where we have a (Near) and (Far) camera setup in the scene; we have also adjusted scale to behave as 1 unit = 10m so Near camera renders 1 - 1000 and far 1000-5000 given the 1:10 unit ratio we have an effective 10-50,000 view distance.

    This is a rather specific set up for our game which being set in space where the usual subject observed is hundreds of m in length makes this no problem. This also means we have to scale physical settings by 10. To make this a bit easier on us we have our scene structure such that all scaled 'field elements' as we call them are under a GameObject whose scale is (0.1,0.1,0.1) so the natural transform scale of objects (1,1,1) is used on the elements them selves handy as only specific scenes are scaled like this.

    This sorts out the flickering issue for us and while specifc to our game a similar approch may work for others e.g.

    multiple cameras handling different distances we only use 2 but I expect more could be use; the idea is that each camera is only responsible for a given range the closest of which being nice a short thus the up close shadows are on a camera with a range < 1000 units
     
    theANMATOR2b likes this.
  23. DGart.work

    DGart.work

    Joined:
    Mar 27, 2015
    Posts:
    199
    this problem occurs when objects are far away from 0,0,0 point try to move everything so that center of your scene is at 0
     
  24. XDSoftworks

    XDSoftworks

    Joined:
    Jul 20, 2015
    Posts:
    54
    i have tried just about everything to fix the shadow glitches. rescaling the game up and down, moving objects closer to the 0,0,0 but nothing worked... however there is one thing that works and it requires a ugly and huge scale increase to prevent clipping. just set the cameras near clipping pane to 4 (as a minimum) recommended as 6 then scale your project up to match it. hopefully your project is small and is a render test like mine! good luck
     
  25. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,080
  26. skrad

    skrad

    Joined:
    Jul 18, 2012
    Posts:
    17
    Similar issue here. I have one directional light in the scene which is rotating.
    I think, I have tried everything shadow related to solve this issue, only thing that helps to decrease the flicker is to increase the shadow quality, but even on max settings the flicker is really bad.

    Scaling up did not work for me, but I can confirm that moving the flickering mesh to Zero world position did get rid of the flicker on that particular mesh completely. However I have a big scene so this is not really a fix for me.
     
  27. XDSoftworks

    XDSoftworks

    Joined:
    Jul 20, 2015
    Posts:
    54
    yeah. i can't remember what version i had when i tried that XD, unity 5.2 seems to have broke it for me.
     
  28. stationx

    stationx

    Joined:
    Jul 9, 2012
    Posts:
    251
    hm..I am having these issues as well. Somebody already got a solution for this? Looks indeed a problem with large scenes.
    The flickering issue indeed remains when placing objects far away from 000.
     
  29. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    There are now more options in Unity 5 compared to the version that is mentioned in the original post. Besides that, there are by far not enough information that anyone could help you.
    It is clear that the precision around the origin is better. I have seen people who have a huge offset to the origin, instead of constructing the world around the origin. I have seen people using ugly sizes for their objects, like 100 bigger than in the real world. I have seen people using ugly clip plane values. I have seen people using too extreme shadow values.
    If none of those is the case for you, you may have to shift the whole world in order to avoid those issues. That is not easy, especially when physics is being used. But it can work.
     
  30. skrad

    skrad

    Joined:
    Jul 18, 2012
    Posts:
    17
    I have given up trying to find a solution, because this is clearly a bug. At least in my case, don't know about yours. Only workaround is not using shadows the way I wanted to, or disable shadows on objects with slim mesh, because in my experience slim meshes suffer the most from this.
    I guess this is the reason that scaling up worked for some people, not for me though.

    I am using unity version 5.1.2f1
     
  31. stationx

    stationx

    Joined:
    Jul 9, 2012
    Posts:
    251
    Well, the issue can be easily reproduced. Create a cube with a plane, place it at X = 10000 and see shadows flickering with default settings. The only thing so far I have seen that can reduce this issue is by creating a parent game object and scale this GO with +- 0.1f. That would mean that this very same cube + plane with original is placed at x = 10000, is now at x = 1000. Currently, it looks like that everything in a radius of 3000 units is getting correct shadows, while how bigger the radius, the more the flickering appears. Nothing like changig bias, clip planes did seem to fix the issue. It clearly is related to stuf that goes beyond large units. (e.g. larger then 3000 or 4000 units)

    To me, this really is a bug in Unity, it makes it almost impossible to create large open world with normal units. (1m = 1 unit)
    Indeed, scaling the world down, makes the flickering less but that indeed also means scaling al physics down, all Speed parameters of FPS controllers , al jump heights etc etc etc...perhaps shifting may have some effect as well, but didn't try that yet.
    I am aiming for high quality, realistic open worlds, that seems to be very hard to do in Unity. (it was in v4 almost impossible and didn't get easier in v5 either. )

    Regards! T
     
  32. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You guys are mixing very different topics and make it a lot more difficult than needed. This thread was started in 2012 and you have a regression between Unity 5.1.x and Unity 5.2.x. That's definitely not the same problem!
     
    theANMATOR2b likes this.
  33. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I don't know whether the shadow computations could be changed to compensate for this huge distance, because graphics cards are doing 32 bit computations. I assume there would be possibilities to achieve that, but that wouldn't be a good approach in my opinion.
    When you are very far away from the origin it is clear that one after the other thing is going to behave wonky due to the floating point imprecision.
    That's why there was more than one discussion in this forum about built-in origin shifting. This would also solve the shadow flickering you are experiencing. I just had a look at Unity feedback and couldn't find an actual entry for it that is actively voted up by the community. That's pretty surprising.
     
  34. MrIconic

    MrIconic

    Joined:
    Apr 5, 2013
    Posts:
    239
    Has anyone fixed this abomination of an issue?
     
  35. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    There are different ways to minimize the effect. But it would definitely be useful to get more information about your actual use case.
     
  36. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,279
    We have seen shadow flickering, particularly at higher resolution with thin geometry and worst with lots of lights but our scene is small and centred on origin. But to us the shadows in deferred rendering mode just seem buggy, prone to problems in certain scenes and difficult to track down the cause (to make a clear bug report)
     
  37. tmammela

    tmammela

    Joined:
    Sep 28, 2015
    Posts:
    27
    Here is one shadow related issue I have reported:

    http://issuetracker.unity3d.com/iss...artifact-when-is-viewed-at-from-certain-angle

    But it's not the only one I'm experiencing. Usually while the editor has been running for over an hour, the shadows start flickering and then they will dissappear until I restart the editor.

    I am not happy at all with the Unity 5 shadows, they are very buggy and they never look quite good even during that small moment when they are working "correctly".
     
  38. skrad

    skrad

    Joined:
    Jul 18, 2012
    Posts:
    17
    Anyone has try 5.3 yet? is there any improvements regarding this?
     
  39. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,279
    I found in our case the shadows were fine on a good graphics card (gtx 970) while they flicker in resolution or dissapear completely on mobile gpus or more basic cards. This does not make much sense though as the program is not expensive in VRAM use
     
  40. stationx

    stationx

    Joined:
    Jul 9, 2012
    Posts:
    251
    In my case, i solved the issue by moving my world around while the camera is always at zero. Not a nice workaround, but seems to working.
     
  41. frankn

    frankn

    Unity Technologies

    Joined:
    Nov 15, 2015
    Posts:
    10
  42. TorQueMoD

    TorQueMoD

    Joined:
    Feb 1, 2010
    Posts:
    16
    I was having the same issue but increasing my near clipping plane to 1 fixed the problem. As far as I can tell the far clipping plane doesn't really make a different to the shadow flickering.
     
  43. Mogulbasher

    Mogulbasher

    Joined:
    Feb 26, 2014
    Posts:
    42
    We fixed this issue by dropping from 4 cascades to 2 cascades in the shadow quality settings. Shadows look aweful but at least they stay on.
     
  44. harrycollin

    harrycollin

    Joined:
    Jan 10, 2016
    Posts:
    1
    I'm working with a very large scene and the further away from 0,0,0 you get the worst it is. The shadows seem to flicker and makes models look like they have z fighting all over. Changing the near plane to a higher setting does fix the issue although that's not an option for me. I hope this gets fixed soon.

    This seems to be related :) https://issuetracker.unity3d.com/is...s-far-away-from-origin-needs-reverse-fp-depth
     
    Last edited: Feb 9, 2016
  45. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    http://unity3d.com/unity/roadmap
     
    harrycollin likes this.
  46. TorQueMoD

    TorQueMoD

    Joined:
    Feb 1, 2010
    Posts:
    16
    Decreasing the cascades shouldn't affect the visual quality of the shadows... the cascades just set up the LODs for the shadows as far as I can tell. If you switch down to 2 cascades, just increase the split to closer to 50/50 so that the shadows still look good when you're close to them.
     
  47. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    509
    andrejpetelin likes this.
  48. jason-fisher

    jason-fisher

    Joined:
    Mar 19, 2014
    Posts:
    133
    This is probably resolved in the latest 5.5 beta:

    Graphics: Improve shadows precision for large worlds

    Use reverse-float depth buffer for improved depth buffer precision on modern GPUs. Particularly improves directional light shadowing for large view distances.​
     
  49. snair692

    snair692

    Joined:
    Feb 2, 2016
    Posts:
    36
    This doesn't make a lot of sense to me, I have a huge scene with tons of shadows (9,999 x 9,999) and I haven't had any of these flickering issues described here.

    I will say that I've had a lot better luck using deferred over forward rendering, in general.
     
  50. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    Update your graphics card drivers.