Search Unity

Terrain flickering, really annoying please help

Discussion in 'Editor & General Support' started by WillModelForFood, Jan 5, 2013.

Thread Status:
Not open for further replies.
  1. WillModelForFood

    WillModelForFood

    Joined:
    Dec 5, 2011
    Posts:
    143
    Using unity4 pro. This only happens in deferred rendering, not forward. And when the terrain option: cast shadows enabled. Really bad flickering happening. I'm using a directional light, tried messing with every single setting in the light properties, shadows, rendering quality, terrain properties, nothing seems to fix it.

    This happens even with no trees and just a terrain with a directional light, even more so the bigger terrain you use. For example it gets really bad using 10k x 10k terrain.

    Vid -
     
    Last edited: Jan 5, 2013
  2. WillModelForFood

    WillModelForFood

    Joined:
    Dec 5, 2011
    Posts:
    143
    Well it seems like this is a known bug since last year. Only setting the near clip plane to a very high amount helps, but then you can see through walls.

    Even with no trees, just a 10kx10k terrain these shadow artifacts happen. Only turning off the terrain: cast shadows option will get rid of it, which is not really an option, because this issue occurs on meshes too
    http://forum.unity3d.com/threads/81499-Shadow-Artifact-Problem-(bug-)-on-Terrain-(Solution)

    Unfortunately I will not be able to use unity because of this now.

    Why is such a huge issue not fixed in so long?

    Another video from another user who abandoned unity a year ago and never came back because of this. Thought it was fixed but actually wasn't (wait till he changes to deferred)-

     
  3. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    Hey. Im fairly new to unity but have quite a bit of experience with opengl and maybe able to help.

    I dont think this a bug with unity but simply the limitations wilth todays graphic cards. What I think is happening is the depth buffer does not have enough precision to shadow the terrain over such a large distance.

    This is worst on the terrain because of self shadowing. Where the shadowed area is closer to the part thats is causing the shadow than there is enough precision to distinguish them apart you will get shadow acne. You can help this by increasing the bias setting but it will only help to a certain degree.

    This is why it improves when you change the near plane of the camera as this has the greatest effect on the depth buffer precision.

    You have a few options -

    1 - The easiest is to use light maps. They will look and perform the best but the lighting will be static.

    2- Only shadow close to the player and fade out with distance.

    3 - Only shadow objects onto the terrain like trees, buildings, etc and resort to shading will normals for the terrain.

    4 - Use multiple light maps for different times of the day and fade between them for dynamic lights

    5 - Move the near plane forward render distant objects, clear the depth buffer, move the near and far plane back and render near object.

    You will most likely need to use a combination of tricks to render very large scenes.

    good luck
     
    RaoulWB, Chris_Payne_QS and Mr-Logan like this.
  4. WillModelForFood

    WillModelForFood

    Joined:
    Dec 5, 2011
    Posts:
    143
    Thanks for the response, I clicked bake scene for all then changed light to baked only and I'm still getting the problem when using deferred rendering and directional light.

    I didn't want to have to bake light though I was trying to use unity for a realtime renderer, ever since using cryengine baking light is like a nightmare
     
    Last edited: Jan 6, 2013
  5. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    For the scene in the video can you try making the terrain a shadow receiver but not a shadow caster and for the trees a shadow caster but no receiver.
    If it goes away its a self shadowing problem. If not it may be your settings.

    Can you post you shadow distance, quality, number of cascades, bias, near plane and far plane values.
     
  6. WillModelForFood

    WillModelForFood

    Joined:
    Dec 5, 2011
    Posts:
    143
    The only setting that can help causes other problems and is not a solution.

    This thread goes into it in detail even more: http://forum.unity3d.com/threads/83286-Shadows-shaking

    In that thread ^ he pretty much tried everything, and half way through a unity dev responded about a bug report and the fact that they never even got to looking at it. Finally at his last post he thought it was fixed, but it was only briefly and actually not, thus why he has disappeared from the unity forums since 10 months ago.

    He tried different graphics cards, nvidia, ati, nothing helped. The only real solution is to set the near clipping plane of the camera to 1.0. This is not really possible though because then you can see through walls. The default is at 0.3 which has the flickering problem, but it's necessary and doesnt get fixed until you go to 1.0, which is not a solution. I cannot make the far clipping plane smaller either (not that it helps) because I have a big environment.

    For just a terrain with no meshs, turning off cast shadows in the terrain options will help, but thats not really a solution either because as seen in his video it happens with meshs as well.

    The fact that thread I linked has a dev acknowledging it as a bug with only using absurd clipping plane values that are not acceptable as a fix shows that this is a big problem.

    Changing the shadow distance, quality, cascade, or bias doesn't really fix it, only the near clip plane which is not really acceptable.
     
    Last edited: Jan 6, 2013
  7. WillModelForFood

    WillModelForFood

    Joined:
    Dec 5, 2011
    Posts:
    143
    So now I'm trying to figure out how to bake the shadows onto the terrain and avoid using realtime shadows at all, but I'm not sure how. It doesn't seem to want to bake the shadows from a directional light.
    After the bake if I turn off realtime shadows there are no shadows.

    How can I bake the tree and mesh's shadows onto the terrain like a real bake would in udk? I have everything tagged as static and tried many different settings.Or can you only bake light and not shadows?

    Also my terrain is 10,000 x 10,000 I have read somewhere terrain over 2kx2k with the highest lightmap settings will bake very bad quality compared to how realtime looks.

    What should I do? Is there a way to bake crisp shadows on such large terrain (even in maya)?
     
    Last edited: Jan 6, 2013
  8. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    1. Use a bunch of small terrains stitched together instead of one giant terrain. Your lightmap will be garbage on a giant terrain, way too stretched to even notice.
    2. Are you using the standard of 1unit = 1 meter? That's how unity is designed.
    3. If you never want realtime shadows, go into quality settings and turn them off.
     
  9. WillModelForFood

    WillModelForFood

    Joined:
    Dec 5, 2011
    Posts:
    143
    K thanks-

    How small should each terrain be for crisp shadows that are high quality as realtime hard ones?
    Also, I wanted to bring in huge terrains that I made with world machine, either from heightmaps or mesh's.
    Is there a way I could bake shadows onto such huge terrains externally in maya? Or will the texture size be limited no matter what
     
  10. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    Creating crisp shadows like that on terrain is probably not going to be a good idea. You would need to create your terrains really small, and the amount of texture data would consume enormous amounts of memory. For example, if you used the default 50 texels per unit, a 10,000 x 10,000 terrain would consume 236 Gigabytes of texture memory. Baking shadowmaps into textures would result in similar outrageous amounts of RAM usage. You may want to revisit your thoughts on getting rid of realtime shadows. All game program is an exercise in trying to use limited resources. You usually can't just brute-force things.

    My recommendation is as follows:

    1. Lower your terrain resolution as much as possible. Do you really, really need 10,000x10,000 terrains?
    2. Use WorldMachine to create tiled terrains instead. Try to have as few terrains as you can, and try to limit them to 2,000x2,000 or less.
    Use a 1024x1024 light map (or 2048x2048) on your terrains.
    3. Turn Realtime lighting back on. Set shadows to "Hard and Soft Shadows". Set your cascades to at least 2 (maybe 4), and set the shadow distance to 100. Set the Shadow Resolution to "High Resolution", and the shadow projection to "Stable Fit"
    4. Set the near clipping plane to at least 0.3 meters. if you can, push it out further, like 0.4 or 0.5. Remember this is all in meters, so if you're in first person, your collider will need to be at least double the width of your near clipping plane to avoid looking through walls.
    5. Start with just one directional light. Make sure it's not pointing straight down ( I usually maneuver the scene camera to the location/direction I want, and then align the light with the view). Set the shadows on it it to "Soft Shadows", and the shadow strength to something like 0.6 or 0.7 (you'll need to tweek this once you have your scene light mapped). Set the bias to 0.05, the softness to 4 and the softness fade to 1.
     
    transat and Beloudest like this.
  11. WillModelForFood

    WillModelForFood

    Joined:
    Dec 5, 2011
    Posts:
    143
    Thanks I really appreciate the tips,

    however I already tried all of this. The horrible shadow flashing and flickering artifacts will always happen in deferred rendering with realtime shadows from a directional light unless the near clipping plane is set to 1. I'm not sure how so many people have not noticed this, maybe not many use deferred. The whole purpose of baking was the only option to avoid the problem- Using smaller terrains will not really help as the second video I posted shows it happens on mesh's too.

    I'm pretty sure I have tried experimenting with every single setting, just as others have in the other thread I linked. I appreciate the help and will try everything you said exact, but It's been tried already, nothing will help except an absurd near clipping plane, or switching to forward rendering.
     
    Last edited: Jan 6, 2013
  12. R-Type

    R-Type

    Joined:
    Oct 31, 2012
    Posts:
    44
    Just an idea that came up when reading this thread. Why not doing it in 2 passes, first set near to 1, render your scene, then set near to as close as you need it and far to 1, render again on top of the first result.

    I am no Unity Expert, but that seems to be a simple and fast solution, surely a dirty one... but maybee it will do its job...
     
    sj631 likes this.
  13. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    @WillModelForFood: Just trying to help out. This does not happen to me, in any of my scenes, so I gave you the settings I was using. If your scene is small enough, I would be happy to look at it, see if there is some difference in settings somewhere. Or if you can make a small scene (or give instructions on how to recreate it...)

    Of course, I get this error all the time in the scene view during editing (because the scene camera is so wonky). But I don't ever see it in any the normal game view.
     
  14. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    This has been an issue in 3.5.6 and before. Not sure if it has been fixed in any version of 4, but I wouldn't count on it as the terrain system hasn't gotten much love (about to change in near future?) in the past. But we encountered this bug, too (deferred rendering, 2000x2000 default terrain patches).
    One of two solutions: either deactivate "Cast shadow" on each terrain patch or move the near clipping plane farther away from the camera's position resulting in higher depth buffer precision.
    Solution 'A' may be the better alternative as the shadow casting doesn't have that big of an impact on the overall visual quality imho. 'B' may lead to undesired clipping of close range objects.

    I don't know why this hasn't been addressed properly, yet - it seems the design decisions made for the terrain engine favor a use case that is some sort of fps or third person game very close to the ground with very low view distances (no more than 1000 meters).
     
  15. WillModelForFood

    WillModelForFood

    Joined:
    Dec 5, 2011
    Posts:
    143
    For a quick test you can make a 10,000 x 10,000 terrain add a texture, switch to deferred, add a directional light, turn on realtime hard shadows, add an fps controller, set near clip to default 0.3 and set the jump height really high to like 300. Jump and start looking around in game..the effect is more noticable the further you go from the terrain.


    Wow glad I found someone also experienced with this, thanks very much!
    But wouldnt the other crowded mesh's have this problem? In the second video here you can see it on the meshs too, and in the thread I linked
    http://forum.unity3d.com/threads/81499-Shadow-Artifact-Problem-(bug-)-on-Terrain-(Solution)
    He said he tried turning off cast shadow for the terrain but the problem was still there for mesh's. You have to have enough meshs though, not just a couple.
    Can you confirm this?
     
    Last edited: Jan 6, 2013
  16. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    We have only few objects in our scenes - mostly trees. So I haven't noticed the flickering on objects, yet.
    But that thread you linked to displays the bug perfectly (Moiré patterns and flickering/z-fighting shadows).
     
Thread Status:
Not open for further replies.