Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to make realtime shadows look "good" in Unity?

Discussion in 'Editor & General Support' started by WarpZone, Aug 25, 2012.

  1. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    Change Color Space to Linear. Use HDR for the camera. Use deferred rendering. Use Tonemapping effect on camera.
    Use realistic colors/setup for situation (not pitch black shadow, on 100% white floor).

    I understand you don't like the grain, but you aren't doing anything usable here.

    In this type of situation the shadow would be sharper, lighter etc. Combined with the correct settings so that you see what Unity is actually rendering you would get usable results.

    If you actually do something that goes towards the realistic spectrum your results will improve.

    You see when the unity team got beat down to provide realistic rendering, the idea was that you have to do things correctly to achieve this (you can't just avoid linear color space for instance). It's also essential to work on realistic lighting conditions.

    The difference between this method (grainy) and simply blurring is visible mainly on lower resolution shadows. Change the resolution to something like Medium or Low and then fiddle with the Softness values, you will see that lower res shadows don't have the "blurred pixel" effect you would otherwise see.

    This is especially obvious with far away thin objects which with blur look like disconnected blur pixel shadows. ust check out GTA 4 screenshots and you will see what I mean, you will still recognize the pixels, but they will be a lot less obvious.
     

    Attached Files:

  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    I'm perfectly happy having only the high end ;-)
     
  3. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    Then just increase the shadow distance
     
  4. Deleted User

    Deleted User

    Guest

    No. I don't want to do all that. It introduces other problems. Deferred rendering forces me to use post effect AA, which is expensive and doesn't look as good as forward rendering's AA.

    I appreciate your workaround ideas, but that is not a satisfactory answer. What if I don't want realism? Just shadows that aren't speckly and changing speckle position every frame. My point is that Unity needs to add some blur to soft shadows. The OP linked to a blog post with a way to do this and Unity needs to add similar functionality to their soft shadows.
     
  5. macdude2

    macdude2

    Joined:
    Sep 22, 2010
    Posts:
    686
    On a slightly different note, if anyone has the unity 4.0 ios beta, I would love to see a screenshot or video of the realtime lighting as well as lightmapped normals on an iPhone if this is at all possible.
     
  6. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Unity's main problem with shadows is the best shadow algorithms are patented software.
    So, we won't see this kind of improvement unless UT invest tons of money on it.
     
  7. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326
    Thanks for the suggestions, koyima. They greatly improved the visual appeal of this particular Unity3 project. I had indeed neglected to manually set Color Depth to Linear in the Player settings and I wasn't using very much more than the default amount of ambient lighting, when more is called for in a daytime scene.

    That said, it would look even better than THIS if I could blur those shadows out a little bit.
     
  8. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326
    S***. They patented "any method of blurring just the shadows?"

    That sucks. You should have just said so.

    How come that blogger got away with doing it? His blog is basically evidence of patent violation, right?
     
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    unity's mobile shadows (and shadow technique in general) is a bit slow. It's still tonnes faster just to stencil buffer shadow and post blur the result. There's problems with that route though, even if it can end up twice as fast, and that is it requires specific geometry when in shadow or the shadows don't calculate correctly. That's my understanding of the matter. And if you wanted that you'd want creative lab's patented depth fail.
     
  10. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Rolling out my own depth texture using replacement shaders. Once you got the shadowmap, it's just a matter of composing with your final color (in a post-process).
     
  11. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    It's the other way around. Stencil shadows (even using carmack reverse) still slower than any basic shadowmap technique.
     
  12. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    You mean do that instead of lightmaps? No, then I lose all my bounced light and everything looks totally S***.

    C'mon, this isn't a new idea. I can show you Xbox360 games from 2009 that had the static, lightmapped environment geometry casting shadows on the player character. "Just do it all in realtime" isn't workable unless you've got a realtime GI solution that looks as good as baked lightmaps.
     
  13. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    How is it every game i've seen with stencil shadows runs faster than shadow mapped shadows? Why didn't carmack use them when they existed before doom3? shadow mapping requires the entire scene to be drawn to a texture first (the visible range) then it's projected back. This is faster than using polygons and skipping that step entirely? Probably on a modern gpu. But a mobile gpu? I just don't know. In any case I'm happy if unity is using the faster technique.
     
  14. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Well, it really depends on your scene complexity but in overall, shadowmaping is cheaper to render. For example, indoor scenes with only few low poly models, stencil shadows will surely do better. However, when you start to add more complexity (meshes) to your scenes (as today's modern games), that's where shadowmap shines.
    Stencil/volume shadows are really filtrate hungry, not good for mobile atm.
     
  15. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    You can exclude objects from the shadow casting during the bake and then only cast shadows from them in real-time. You can generate the lightmaps outside Unity so they only have GI too. You can bake the GI into vertex colors. If the shadow has the correct settings (color, intensity etc) the results can be perfect.

    There are multiple ways to do stuff, don't assume that because games in 2009 were doing something that it was done in some sort of straightforward fool-proof or close to elegant way.

    Actually I highly doubt that their solutions match Beast as far as how many scenarios it can handle, flexibility(options) and results. If you want custom results you have to work out custom solutions.
     
  16. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632

    No cutouts (alpha), all meshes have to be watertight.
     
  17. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    I guess that's the point. I'm not entirely convinced they can't blur the shadows some other way (patent talk), I just think they chose one method over the other and some people prefer simple blurring. From my experience once you use anything resembling realistic textures the grain isn't visible and light-mapping is key.
     
  18. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    You mean only bake indirect light into lightmaps? I looked into this but I couldn't find how to do it on any of the major lightmappers. Do you have links to any documentation on how to set it up? There's no way I'm changing techniques at this point in my project but it would be good to know for future reference.

    That's not practical with the amount of geometry we've got.

    My point wasn't "it was done in 2009, it must be easy," my point was that without features like this, Unity's lighting system is less capable than games that are three years old.

    Beast's flexibility is worth nothing to me if things like this are missing, because, as you say, I have to work out a custom solution.
     
  19. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    Just turn off shadow casting for the bake in beast. Increasing Bounces might be required to get a nice gi feeling. Shadows are basically overlayed on top. You can test how this works in photoshop. Get one shot with GI and no shadows and a second shot with only shadows (black n white). Put shadows over GI environment change blending mode to multiply and play with transparency. Then you can also go to Hue/Saturation and Colorize the shadow layer. Then compare it to the one with baked shadows.

    Here is a project using mental ray if I remember correctly
    http://basenjigames.com/
    http://forum.unity3d.com/threads/100533-Parsimonia-1st-Floor-Walkthrough
    http://docs.unity3d.com/Documentation/Manual/LightmappingInDepth.html

    You can do the same in max with vray or mental ray and bake whatever elements you want.
     
    Last edited: Aug 26, 2012
  20. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326
    Koyima, is it an all-or-nothing situation? Is it impossible to add a feature like shadow blurring the way hippococder or tatoforever are describing without completely stripping out Beast in the process? You can't hook into the existant shadow-drawing algorithms and, if an option is ticked in Unity, have it draw that shadow data to a seperate full-screen buffer, make that buffer accessible from Image Effects, and then blend it at runtime? Sure, it'd be slow, but no slower than a typical full-screen blur or bloom effect, as far as I can tell. All of the techniques you use to optimize Image Effects such as having a buffer 1/2 or 1/4 the size of the screen could be used here. You can't do that without losing Beast?
     
    Last edited: Aug 26, 2012
  21. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    I think it's entirely possible to have both, but I haven't done any research into the subject. It doesn't make sense that blurring is out of the question. I haven't even done a search to see if a Unity staff member has explained the rationale behind this. For any environment with photographic textures you won't notice the grain, but that doesn't mean you should take the option away entirely.

    I'm guessing the method used has less artifacts in a variety of scenarios (different shadow situations).

    Here is some reading (haven't gone through it all yet :) ):

    http://developer.download.nvidia.com/presentations/2008/GDC/GDC08_SoftShadowMapping.pdf
    http://msdn.microsoft.com/en-us/library/windows/desktop/ee416307(v=vs.85).aspx

    http://www.opengl.org/discussion_boards/showthread.php/152677-Blurring-shadow-maps

    Also I don't think beast has anything to do with it. Beast renders perfect shadows.
     
    Last edited: Aug 26, 2012
  22. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    First thing that comes to mind is, you have to re-create the shadows yourself with the camera depthtexture, blur them out and compose the final image as a post-effect. However, I've posted a while back a 8tap filter technique (hacking the basic shadows filter provided by Unity) to soft a little bit more the omni shadows (the ugliest one), look for it in the forum (don't remember exactly where the thread is). You can then use that as a basis to create a better filter (full screen blur, etc).
    [EDIT] Once our game will be published (later this year), I'm gonna release the mobile soft-shadowmaping sources to the community for free. :rolleyes:
     
    Last edited: Aug 26, 2012
  23. macdude2

    macdude2

    Joined:
    Sep 22, 2010
    Posts:
    686
  24. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Basic 2pass shadowmapping, no filter, no cascades, nothing fancy. :cool:
    [EDIT] For indoor scenes, if you are casting shadows only on few objects (low poly ones) then yes, shadow volumes will do great.
     
    Last edited: Aug 27, 2012
  25. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326