Search Unity

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

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

  1. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326
    Okay, every time I google this question I see a bunch of angry complaining on the users' side and doublespeak and feigned confusion on the PR/developers' side, so before I open this Pandora's Box of a conversation again, let me first define some terms:

    "Good" means I don't see blocky, angular, jagged black pixels in the realtime shadows. Ever.
    "Setting Shadow Type to Soft Shadows in Unity 3" is not "Good."
    "Fallout 3" is an edge case.
    "Unreal Engine 3" is not an edge case, that's why everyone's USING it.
    "Lying" means posting a 256x192 screenshot where a standard jagged Unity 3 shadow is being cast on an extremely busy brick textured floor. If it wouldn't look smooth on a plain white surface at 1040p, that's not really smooth, and you know it.
    "Modern" means this problem has been solved. That is, solving this problem is necessary, but not sufficient, for making your game look good to modern gamers.
    "Easy" means other developers have already solved it, all over the industry, so don't say it can't be done. Don't say it's only necessary for First-Person games. This guy did it on an iPhone, for crying out loud. In a third-person game. With large outdoor areas. And it looks objectively better. So why can't I have it in my Unity Pro PC game?





    This is not a question of "is this a real feature," "does this feature matter," or "is this feature relevant to the types of games people would want to make with Unity." The answers are all "Yes," and that's why people keep asking for this feature over and over again.

    There is only one question that needs to be answered in this thread:
    Can we achieve this feature with Unity 3, or do we have to wait for Unity 4?

    Thank you for your time.
     
    Last edited: Aug 25, 2012
    Gryflir likes this.
  2. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    Turn your shadow resolution up. Bake light maps. Set the distance for shadows lower, like around 50 units. Shadows are no longer blocky. They look great.
     
    Last edited: Aug 25, 2012
  3. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Good question, there has only been mention on mobile shadows, nothing on improved shadows for other platforms which is a MUST.
     
  4. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326
    That's similar to the Fallout 3/Lying solution of just using really busy textures for everything so the player doesn't notice or think about the shadows so much.

    I'm not asking how to make Unity 3 shadows look as good as possible. I'm asking if we'll get this specific feature (realtime shadow blurring) now, or later.

    Unity cannot do without this feature forever. It's just not reasonable to pretend it can.
     
    Last edited: Aug 25, 2012
  5. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    Yes you can, especially since a quick read of that guys blog strongly suggests he is using exactly the same shadow mapping that Unity offers - cascading shadow maps with blur. The thing is, unless there has been a major breakthrough in the last few years that i've missed, shadow mapping is not a 'solved' problem. There are many solutions but they all suffer various problems, such as perspective aliasing or dueling frusta. The best you can hope for is to learn how the algorithm works, understand the issues and tweak the settings to get the best out of it. This includes choosing correct distances, number of cascades, size of shadow map etc.

    This is why 'Simons tech blog' looks good, he understands the algorithm as he had to implement it.

    Mind your don't think his shadows are that good, he's using rather low resolution shadow maps, with extreme blur, so they lose pretty much any detail.


    Edit:
    LOL - check out that guys blog references and you'll find one from Aras

    [8] Deferred Cascaded Shadow Maps:*http://aras-p.info/blog/2009/11/04/deferred-cascaded-shadow-maps/

    So the guy you are using as an example of producing great and easy shadowmapping actually used a reference to Aras tutorial about how shadow mapping was implemented in Unity.
     
    Last edited: Aug 25, 2012
  6. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    Surely you're not asking for the entirety of a fallout 3 style world to be drawn with realtime blurred shadows? Or are you asking for deferred shadow blurring to be actually blurred instead of dithered? All I've really seen is that you've posted a screenshot that was created with the worst shadow settings possible, and asked if they were going to get better. The answer to that is "they're better now if you change your settings".

    ALL 3d graphics are "lying". I'd like deferred rendering shadows to be blurred instead of dithered also. But that's just better lying.
     
  7. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326
    Yes, he uses Cascaded Shadow Maps, just like Unity 3. Then, after he did that, he blurred the shadows, (I'm guessing in screen-space,) which I don't see a way to do right out of the box. If you look at the screenshots I posted in the OP in their original context on his blog, you'll see that they are clearly labeled. The images on the left basically emulate Unity 3's cascaded shadows in both "Hard" and "Soft" modes. (I'm pretty sure THIS is what he's referring to in the references. Not the feature I'm talking about, which is also the feature the TEXT of his blog post is talking about, E.G. soft realtime shadows.) The images on the right START where Unity 3 ends, and then adds blur to JUST the shadows.

    All I want is for this feature, that last blur effect, to be do-able in Unity.

    If it's doable in Unity 3 right now, I want to know how to do it. So I can go back to all those forum posts from like 2008-onwards and tell people, "Yeah, you can make the shadows look good in Unity. Here's how you do it."

    If it's doable in Unity3 with an Image Effect, that's awesome! Where's that script? How do I do it? If there's caveats on how to use it properly, like z-fighting or whatever, that's fine. Just ship the script with Unity 3 and mention the caveats. Wouldn't that be better than straight up LOSING all the noob customers who ask about this feature because they think they saw it in Call of Duty, only to be told that it doesn't exist, it shouldn't exist, it's not a feature, it's not necessary, Unity's lighting already looks great?

    If it's not doable in Unity3, because the shadows aren't exposed in the API after being drawn or whatever, that's fine. But Unity 4 needs to expose them.

    This feature, while not perfectly realistic, is a pretty standard feature in games these days. It's unrealistic in a forgiving way. Players expect it. Therefore developers need it in their toolbox.

    That's all I'm saying.
     
    Last edited: Aug 25, 2012
  8. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    I have seen how the shadows look even NOW... I sent my lights to soft and they don't look like soft shadows, and changing the resolution just masks the stepping look on the shadows...we need to fix this...
     
  9. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326
    No, of course not. Even the laziest developer realizes that would slow any game to a crawl.

    I'm asking for the option of using both. Dither first, then blur. Like in the blog post I linked to in the OP.

    No, I showed you screenshots of someone else's game engine demonstrating first Unity-style shadows, then their same engine demontrating Unity-style shadows but with a custom blur feature enabled.

    I know that. And as the screenshots in the blog show, they're even better than THAT if you blur them after the lighting pass. Right now. Using someone else's custom iphone engine, that is, not using Unity Pro for PCs.

    Agreed. But I want this specific lie in my... what do you store collections of lies in? ...in my Tom Sawyer.

    But for the purposes of this thread, I defined lying as scaling down a screenshot and using busy textures to make the jagged edges and stepping less visible, then pointing to the screenshot and saying "See? No jaggies! This is totally fixed in Unity 3." This actually happened in a thread from 2011, and it made me angry when I saw it today. This was by one of the "I don't understand what shadow issue you're referring to" apologists, too, IIRC.
     
    Last edited: Aug 25, 2012
  10. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    You can actually have soft-shadows on iPad2/3 with good performance (we are doing it on our game, full screen and it runs really fast). But you know, this sort of decision in an engine isn't the same as it really change from one game to an other. At least you will have directional shadows (hard shadows btw). Better than nothing. XD
    Now speaking of build-in desktop shadows, no, they won't be any better. Perhaps Unity 4.x or 5.0 will bring better shadows techniques/filters, but for now is a nono.
     
  11. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    You don't know how to set them up.
     
  12. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326
    How did you manage this? What would need to be changed/exposed in Unity 3 to make your technique possible? Please contact Unity Team and recommend these features for Unity4.
     
  13. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326

    Show me your best.
     
  14. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Its not about how you set them up, its about bugs and visual errors they produce in deferrend mode. And yes its also about softness, Epic shadows just look way better, dont know why though.
     
  15. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    Why don't you post your scene and I can tell you what you are doing wrong?
     
  16. Deleted User

    Deleted User

    Guest

    IMO, Unity's realtime soft shadows are unusable. They look almost okay in a still frame, but the dithering creeps and pops all over the place with motion. I've read, and tried, all the techniques suggested on the forums and nothing produces satisfactory results. In the end I decided not to use soft shadows. So I am with the OP, Unity's realtime shadows need some love!
     
  17. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    Can I see an example?
     
  18. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326
    How about we do both?

    The point is, I already know the simplest way to fix this issue. It's called switch to Unreal Engine. And that's a real problem for Unity Team. If they'd listened to the first person who complained about this issue, or started implementing the feature when Unreal Engine did it, they coulda got out in front of this thing. Now it's too late. It's reaching critical mass. All the people who've been complaining about this feature since day one, and all the people quietly making a single post agreeing with the OP in this thread are part of that critical mass that has been slowly building. It's becoming a majority.

    And now Unity Team is marketing Unity 4 as a AAA engine? Forget about it. This feature is coming.

    What are you going to do, tell me to turn my settings up? Settings are all the way up already. Draw distance is 10 meters. Very High Resolution, Softness 8. If there's a way to improve this any further, I'd love to hear it, but somehow I still doubt it'll get rid of the obvious banding whenever the light source hits it at a 90 degree angle.

    And this could easily be fixed if we just had access to the shadow data at runtime. One more Image Effect, called Blur Shadows, and suddenly Unity's graphics are as easy/good as Epic's and Unity's more generous licensing terms make it the belle of the ball in AAA, too, not just Indie iphone games.

    I know I sound angry. That's because I'm passionate about this. I love Unity and I want it to succeed. I BOUGHT Unity and I want it to be USEFUL to me. It's superior to all the other engines in a lot of ways. So why does it have to keep falling down on the strength of its realtime shadows?

    I can't just throw jagged shadows and busy floor textures at my players and then tell them, "the game looks great, you're looking at it wrong."
     

    Attached Files:

  19. returnString

    returnString

    Joined:
    Jul 10, 2010
    Posts:
    248
    Welcome to realtime rendering. No-one can do clean surfaces and perfect shadows. Seriously. Not even UE or CE.
     
  20. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Do you have the shadow casades set to close fit? I do get the jagged shadow edges on a flat plane, set to soft with a low softness fade... it is still there, but the results are not too noticeable... and I also use GI and Beast so it doesn't really bother me...
     
    Last edited: Aug 25, 2012
  21. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326
    Don't need it to be perfect, just need it to be comparable to the rest of the industry.
     
  22. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    OK, so what you're asking for is better blurring of shadow edges, as opposed to just dithering. I think we can all agree with that. As for improving the shadows, I'd recommend turning softness down. I have mine set at 4, and the softness fade set at 1, otherwise I think it gets too noisy. And in Quality Settings, make sure your shadow projection is set to "Close fit".
     
    razamgar likes this.
  23. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326
    Okay that's better... still doesn't quite mesh with the baked textures but maybe if I rebake with these settings on the light, it'll blend better.

    I'd still love to just slap a layer of blur over what I have. Part of it is the umbra effect. These are skyscrapers. I'd expect the shadow to have about six inches of blurry transition by the time it reaches street level.
     
  24. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Are you also using Beast?
     
  25. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326

    Yes. I don't have a problem with the dithering per sey, I just think it's insufficient for making your game look good and modern. Blurring it after the dithering produces better results. That's what the linked blog explains how to do. That's (I suspect) why Epic shadows look so good. And that's what (again, I suspect,) all the complainers have been complaining about all this time.

    Unity's shadows look bad. Unity Team, please make them look good. So I can use Unity to make a modern game. (Using terms defined in the OP.)
     
  26. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326
    Yeah it's in the background, not really visible in this shot. Realtime lighting only extends out 10 meters, which in the first screenshot is sunlit.
     
  27. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    I think the mistake you are doing is leaving the ambient 100 black. Thus when using realtime shadows you aren't faking GI in any way.

    Also make sure to use linear space.
     

    Attached Files:

  28. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    I'm baking some lightmaps too.
     
  29. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    I usually leave my scene ambience at full black <(blame my CG background)... I like the last two pics... the shadows are soft but the shape is recognisable... maybe I should do this now on my levels...

    EDIT: This doesn't work on point lights however
     
    Last edited: Aug 25, 2012
  30. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    Leaving the ambient black only makes sense when using GI in a non-realtime solution.People faked GI using the ambient for years. Just because we can now use GI and the sky to actually do the real thing, doesn't mean we abandon the practice altogether.
     
  31. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Well, shoot me... LOL. I like the results you have too... what is your ambient set to?
     
  32. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    You change it depending on the mood. I give an orange tint for mid-day, light blue for earlier in the morning and afternoon. Dark blue desaturated for night and of course you can experiment with this. You can also fiddle with shadow density (intensity), he screens use 0.858 .

    Anyway I was playing CS:GO for the past couple of hours. They have nice lighting, it's in Source, I figure I can replicate the look easily.
     
    Last edited: Aug 25, 2012
  33. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    True... I will probably go back to using 4% black...
     
  34. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    I usually set the ambient lighting to the colour of the sky, though I use HDR lighting with GI... point lights have some strange bias issues...
     
  35. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    Make sure you are using linear space. It just reset after I made the lightmaps.
     
  36. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Deferred and Linear right here...but it is strange that my shadows are not accurately placed.. :) my character models look WAY better in Deferred and Linear Color space... :)... are you using IBL?
     
  37. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    Can you show me a screenshot?

    If you aren't using linear color space you aren't actually seeing what Unity is doing internally. HDR should also be used so the calcs are of higher precision and again input-output match. Color correction (contrast, leveles etc) go on top of that. This is the correct workflow in offline cg rendering too.

    No IBL in the screen, I guess you could do this using the light probes, right?
     
  38. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    For what it's worth, you *do* have access to all of Unity's shadow information, you just have to drop down to the fully-custom shader level to work with it. The ShadowCaster pass is used to render into the shadow buffer (so you could probably mess with the value output there, e.g. for implementing VSM) and then it's read in the ForwardBase/ForwardAdd passes and integrated into the light attenuation term (i.e. atten = 0 means the light is either far away or blocked by shadowcaster). I suspect you might be able to do PCF or something there.

    I've used this to great effect for making some custom shadowcaster geometry - by writing a shader with only a ShadowCaster pass in, objects are completely invisible but still cast shadows.

    Personally, though, what I want is the ability to have lightmapped/static geometry that casts shadows onto dynamic objects. The dual lightmap "switch to realtime lighting for nearby things" approach is no good if you want to run on modest hardware, especially if you're trying to do directional lightmaps with full color support...
     
    Last edited: Aug 26, 2012
  39. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    Well this is where light probes can come in handy. If they are far away enough to not be reached by your real-time light, the approximation should be enough.

    Note:
    Actually I can get pretty good real-time shadows up to 100 (units-meters), they also work better if you want more softness, since the resolution is spread over a larger area the resulting shadow has less stepping. So making the shadow distance small will be better if you want sharper shadows and increasing the shadow distance can help if you want more blur.
     
    Last edited: Aug 26, 2012
  40. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    I use IBL when lighting with Beast... Daytime levels are cool to light up, nighttime scenes are a bit harder... here is a screenshot of my settings... and the shadow issue may be my model... If you are interested in learning how to light with IBL, I have some tutorials I made just for that.

    $Linear%20Colour.jpg
     
  41. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    Are you sure you haven't baked something in another position and haven't cleared the lightmaps? Also check out the Tonemapping camera effect. There is a pdf floating around on Uncharted 3 and how they combined two tonemapper looks to achieve what they called the filmic look (http://filmicgames.com/archives/75)
     
  42. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    There is no lightmapping...and I have tonemapping on...

    It looks better on my computer screen... print screen doesn't capture everything
     
    Last edited: Aug 26, 2012
  43. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    I don't know what would cause this second shadow. I haven't had anything similar happen to me.
     
  44. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    It's only a test scene... for reflections and character shading. I have been using IBL alot and my scenes look excellent
     
  45. Deleted User

    Deleted User

    Guest

    Here is a webplayer that shows the problem:

    http://moosemouse.com/SoftShadowProblem.html

    Please "Go Fullscreen" to see the problem better.

    Scene details:

    - 1 directional light, forward rendering:



    - Quality = fantastic:


    The one interesting thing I noticed is that soft shadows look significantly different between my laptop and my desktop computer. Both are fairly modern computers and the desktop has a nice Radeon HD 5700 series. The desktop is my primary work computer and the soft shadows are much more speckle-y on it.

    Screenshot from laptop:



    Screenshot from destop computer:



    So, I challenge anybody to recreate this simple scene, make it look better, and post a webplayer :p
     
    Last edited by a moderator: Aug 26, 2012
  46. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    You don't really notice the stepping if you turn the softness fade all the way down...
     
  47. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    You mean for static-geometry-casting-onto-characters? That'll give you a rough brightness for the character, but you still lose any kind of high-frequency shadow stuff - no sharp edges and no fine detail. If my character's crawled halfway into a shadow such that he's lying across a nice sharp shadow line on the floor, then I want to see a nice sharp shadow line on him as well.
     
  48. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    You can't have everything. High end is for high end.
     
  49. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    I can only dream of that... but for now, we will work with what we have... Can't wait to work with Unity 4, very good to hear that I can have beast work with normal maps...
     
  50. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Some new notes... the point light bias doesn't move the shadow at all... and the shadow is not in the right place in relation to the object... look at the box and where the shadow is... $Shadow%20bias%20weirdness.jpg ;