Search Unity

Shadows shaking

Discussion in 'Editor & General Support' started by Demostenes, Mar 26, 2011.

  1. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
  2. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    In the Scene View this happens because the Near Clip plane of the Scene View Camera varies depending on what object was last focussed on by hitting "f". I'm able to reproduce this only in the Scene View because of that. In the Game View if you use "sane" clipping planes for near and far then this issue also goes away.

    For example, when you first open Demostenes example ( http://www.uloz.to/10055809/test-rar ) you might see artifacts on the Terrain. But if you simply readjust the Scene View Camera's Near Clip plane by focussing on the large cube (hit "f") in the scene then the artifacts disappear.

    If you want the artifacts to reappear then you simply create a default cube, focus on it by pressing "f", and voila, they reappear because the Near Clip plane has been made too small and the Far Clip plane is very large in the Scne View (I believe it's set to 10000).

    Again, this is not a bug. This is a mathematical limitation of the depth buffer in deferred rendering and is avoidable if your clipping planes are set up properly.
     
  3. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    I was toying with clipping planes for an hour. I am able to get artefacts away from one frame, but when I move, it is back. My default settings were 3-1000 (on the video), even values like 3-100, 5-100 or some random tuning with decimals around did not help. It seems to my like very sane vulues. Anyway in forward mode there is no problem like it. I checked exactly this in 2 other engines and it worked OK. So this is really not BUG? Common, be serious and at least admit it.

    This is bug and pretty serious. And if it is caused by depth buffer in deferred mode, then your implementation is bad, because other engines does not have this problem.
     
    Last edited: Dec 18, 2011
  4. andorov

    andorov

    Joined:
    Feb 10, 2011
    Posts:
    1,061
    Is it possible for you to strip your project down to the bare minimum and upload it. I'd like to tinker with it, as I've never seen those artifacts while working w/ terrain.
     
  5. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    Unfortunatelly no, we have lots of licenced concent there and licence forbids us to send it unencrypted (as all these licences do). But it is quite easy to simulate this. You just need scene with more objects, maybe some trees. When you reach some level, turn on deferred mode, turn on directional light with shadows and done, you will see terrible disco like on my video ( http://www.youtube.com/watch?v=H5vobcqscuk ). Artefacts are both on meshes and terrain. Objects on my video were sufficient to cause this. Maybe I am wrong, but I was not able to simulate this in empty scene, or few objects. There are no custom shaders, no scripts, no postprocessing effects, everything out of box. We tried on 4 different computers (ati, nvidia) without any change.
     
    Last edited: Dec 18, 2011
  6. andorov

    andorov

    Joined:
    Feb 10, 2011
    Posts:
    1,061
    Yea... no.

    I've hit some pretty ridiculous poly (multi million) and object (thousands) counts and have never seen this.
     
  7. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    It seems, that 3.5 made big progress. Shadows artefacts in deferred mode are almost gone, using bias strength finally makes some difference. Shadows are still shaking little bit, but it is far better.

    I would made more testing, but 3.5 is crashing like crazy on our of memory leaks, so I am staying with 3.4.
     
  8. Helkus

    Helkus

    Joined:
    Dec 20, 2012
    Posts:
    7
    Hey guys, I just caught up on this thread, I filed a bug report about this months ago and to date have had zero response (case # 474710)

    I've sent bug reports, emails, and tried on IRC, no responses though.

    So from reading various articles and responses I understand the near plane being too small is the supposed fix.

    There is one problem though...

    Unity3d has no support for first person weapon models in that case.. So if you're making a first person shooter, you are completely out of luck. Your view model will be Clipped by the near plane if you increase it too much

    The documentation regarding using a seperate camera to render the view model (so it does not clip the world etc) is out of date and that system is completely broken in deferred rendering mode (case # 448498 )


    We're using a near plane of 0.21 and it's still not good enough, we've had to increase the scale of our viewmodels so they aren't clipped by the camera (which results in inaccurate lighting, but we can deal with it)

    Point of the matter is, you need to keep on increasing it and increasing it based on the size of your level, and unfortuantely reducing far plane doesn't seem to have any effect on this, I've lowered it down to as little as 200 units (and been positioned at -3000,0,0) and I still get major shadow wobble.



    A secondary problem seems to be actual model transform wobble at large ranges, my view models were rendering incorrectly and child objects positions would jump by what seemed like floating point errors as I moved around (so the slide of a pistol would wobble left and right and not stay solid) We fixed this by using a custom view model shader that adjusts the rendering matricies to 'pretend' its at 0 0 0, while retaining the lighting information.



    Is there any way to avoid this if, lets say internally to unity when it rendered the scene, it got the offsets of all objects from the camera, and then treated the camera as if it were at 0 0 0, and rendered each object at the correct offsets?

    That seems to sound like a familiar method for solving these large unit floating point/depth precision issues but I'm not sure.

    Any ideas?
     
  9. zelmund

    zelmund

    Joined:
    Mar 2, 2012
    Posts:
    437
    idea is next. if you have large scene ( more then 300x300 metrs) then use forward (if you have only dir light ofc). in other cases use deffered.
    seems UT just close their eyes on that f***n problem and ppl still waiting answer on their questions.

    you can resolve that problem by writting your own shadows or light method with shadows but you cant resolve that problem with a standart options in engine.

    another way to resolve shaking is.... use Unigine =) 64bits and using doubles instead floats its kinda cool maby =)
     
  10. Zarkow

    Zarkow

    Joined:
    Jul 27, 2015
    Posts:
    92
    Necro, but just want to say that I see the same issue using Deferred rendering, 0.1-250 and then aiming a flashlight (spotlight) straight at a 90 degree wall - it flickers like there is no tomorrow. If I aim 0.1 degree away, the issue goes gradually away...
     
  11. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
  12. Knugke

    Knugke

    Joined:
    Jan 10, 2016
    Posts:
    3
    This thread is *really* old, but I had he same problem and it turned out to be a very close near clipping pane of the camera. changed it from 0.01 to 0.5 and the shadows were fine.
     
  13. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
  14. hertz-rat

    hertz-rat

    Joined:
    Nov 3, 2019
    Posts:
    71
    Can confirm, still a bug in may 2020.
     
    LaireonGames likes this.
  15. Zarkow

    Zarkow

    Joined:
    Jul 27, 2015
    Posts:
    92
    Upgraded from 2018.3.0f2 to 2018.4.23f, and now even the Directional default light suffer from it when aiming 90 deg down - luckily I turn it off and only use other lights.
     
    LaireonGames likes this.