1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice
  3. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  4. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  5. Unity 5.5 is now released.
    Dismiss Notice
  6. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  7. Unity 5.6 beta is now available for download.
    Dismiss Notice

Unity 5 - How to light large scenes.

Discussion in 'General Graphics' started by Hjeldnes, Mar 5, 2015.

  1. Hjeldnes

    Hjeldnes

    Joined:
    Jul 22, 2012
    Posts:
    107
    I was wondering what kind of techniques the unity guys suggest that the use for large complex scenes when using Unity5.
    With unity 4.x we could bake dual lightmaps, and we could get lightmaps in the distance and real time shadows closeup. That worked quite ok.
    It's not possible to only use realtime lights & shadows (no baked lights). The shadows create far too many drawcalls (at least they did in unity 4.x). I've seen people from Unity mentioning that you shouldn't have shadows in the distance, but that does not really work in practice. Even if something is far away, it doesn't necessarily mean it will use little screenspace (Large building, a mountain, ground, trees, etc..).

    Lights with baketype mixed seems interesting, where (I assume) you will get baked lights on static geo, and realtime lights/shadows on dynamic assets and the static geo gets shadows from dynamic assets that blend with the existing lightmap.
    However, this does not work. Using deferred rendering I get no shadow at all from the dynamic object. Using forward rendering I get a shadow on static geo, but it is black and does not blend with the lightmapped shadow.
    I can reduce transparency of the shadow but that's not really correct. It still doesn't blend with the lightmapped surface (grey vs a colored lightmapped shadow), and other dynamic objects does not get this shadow.

    A bit frustrating this because unity in it's current state isn't really usable for large scenes.
    I just wonder how Unity people have envisioned the engine to be used in such scenarios.

    Kjetil
     
  2. Tinovdk

    Tinovdk

    Joined:
    Nov 28, 2013
    Posts:
    65
    Thanks for bringing this up Hjeldnes. I came specifically to this forum today to find an answer to the mixed lighting problem. This worked wonderfully for us in Unity 4.x but seems to not work in Unity 5. Hopefully a Unity dev can shed some light on this issue.
     
  3. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    857
    Hi! We are aware of the current issues with mixed mode lighting and will be working on fixing it soon. It is not a trivial thing to get working across the full deferred, the (Legacy) light pre-pass deferred and the forward renderer, but we will fix it for sure. It was deemed to risky to include in the newly released final 5.0 version because touching a lot of code late in the beta is not a good thing for stability.
    Several bugs have been logged on it already, so you don't have to file more.
    Mixed mode lighting is intended to be used exactly as you wrote, with the limitation that it is used for sunlight only. Right now the UI allow all light types that were Auto in 4.x to become mixed and that doesn't work well so that will likely be changed.
     
  4. Hjeldnes

    Hjeldnes

    Joined:
    Jul 22, 2012
    Posts:
    107
    Okay, its good to hear you are on it.
    Having mixed lights work on only directional lights sounds like a pretty big limitation though. One of the main performance issues in our previous game came from local shadows. It made the drawcall count go sky high.
    We managed to sort of fix it by removing shadows on some lights + reducing shadow distance. That worked ok because we had a "backup" shadow from the lightmap.

    As I understand it, it wont work like that at all anymore since lights will have to be realtime to cast shadows. Has shadow performance been drastically improved in unity 5, or will we get issues here as well?
    How do you envision that we setup lighting for such large complex scenes where there would be a lot of local lights. Lets say a moonlit fantasy city with a lot of torches and lamps.
    From your info I assume we'd have to go for mixed light on the moon, and have short shadow-range. And then probably bake all the lights that have a less chance of casting a shadow onto the characters.
     
    moco2k likes this.
  5. Kubold

    Kubold

    Joined:
    May 10, 2012
    Posts:
    317
    I'm starting to think that old-style Dual Lightmaps was a very, very good solution. If I had Dual Lightmaps, but with:

    - "close" map with bump+specular+realtime shadows and just 10-20m range
    - "far" map being bump+specular+baked shadows

    that would be just perfect. Wouldn't it?
     
    bartm4n likes this.
  6. Hjeldnes

    Hjeldnes

    Joined:
    Jul 22, 2012
    Posts:
    107
    Yep, I think dual lightmaps worked quite well. The only thing I didnt like with it was that ambient occlusion was added only to the far lightmap. I know you can use SSAO but it's quite an expensive and local effect, so it wasn't completly the same as a baked ao map. And then it uses a bit more memory I suppose, since you have to store two lightmaps.
    And you can't have a dynamic time of day so easily with dual lightmaps, but many games don't need that.
    It could be that shadows will be a lot cheaper in unity 5(I haven't had time to test perfomance much yet), they were crazy expensive on unity 4.x, especially related to drawcalls.
     
  7. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    857
    In some cases, yes... shadows should be a faster:

    From the release notes:
    In Forward rendering, directional light shadows are computed from camera's depth texture instead of a separate "shadow collector" rendering pass. Saves a bunch of draw calls, especially when depth texture is needed for image effects anyway. This means that ShadowCollector shader passes aren't used for anything; you can just remove them if you had any.
    Most platforms now internally use floating point (RFloat) format for point light shadows, instead of custom encoded ARGB32 format. Saves shader instructions and has better precision.
    Shadow caster culling is multithreaded now.


    In your case, it sounds like you need dynamic shadows from all of your torches but only the most important ones for the current camera should have a shadow map allocated, hence a low shadow distance is needed.

    Remember you also have the option of using dynamic emission from materials to fake area lights and get bounce lighting (in low resolution). Perhaps this will be useful for torches, but this is unrelated to the mixed shadows.
     
  8. seattlebluesky

    seattlebluesky

    Joined:
    Sep 2, 2014
    Posts:
    170
    @KEngelstoft thanks for taking the time to continue this discussion from the 5 Beta forums. Very much appreciated.
     
  9. Hjeldnes

    Hjeldnes

    Joined:
    Jul 22, 2012
    Posts:
    107
    Yep, I really appreciate the comments as well!
    Ok, so you think forward rendering could be better to use in a scene like that? I have been thinking "forward = old and dated" (on non-mobile), but that's maybe wrong :)
    I guess you can reduce the amount of per pixel-pointlights rendered, so the cost can be controlled to some degree. But I assume tens of dynamic lights close to eachother is not possible.

    Dynamic emission seems like a good idea and could be used instead of baked lighting in places. No shadow from those then, but I will have a closer look at this.

    I wondered by the way, is it not possible to batch all the shadowcasters from one light (at least from static geo)? In 4.x we would get 1 drawcall per object, per shadow. And when pointlights has 6 shadowmaps-in-one (right?), then this very quickly adds up to a lot of drawcalls.
    Are there any changes unity5, or are point light shadow still very costly? And why not pcf hardware filtering on local lights?

    Edit: I had a quick look at emission, and you get a lowres lighting/shadowing from it. However, it only works on static geometry. Dynamic geometry is not lit by an emissive surface. Is this a known bug?
     
    Last edited: Mar 12, 2015
  10. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,028
    @KEngelstoft , seeing as you mentioned a lighting bug, in Unity 4 I used a custom projection matrix for my camera and shadows still worked, but since upgrading to Unity 5, shadows no longer show up with a custom projection matrix for cameras. Do you know if this is a bug, or as intended and I have to do something specific to get the shadows back?
     
  11. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    857
    Please post unrelated questions in separate threads, instead of hijacking existing ones.
     
  12. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    857
    The goal is to make mixed mode lighting work the same way in forward and the two different deferred renderers. With tens of dynamic lights, you should probably go with the full deferred renderer.

    The batching code and behavior changed between 4.x and 5.0. Now, you should be less concerned about draw call count and focus on the number of SetPass calls, as draw calls without state changes in between are actually really fast. Shadow map drawing doesn't change a lot of state...

    PCF hardware filtering on local lights? Good question, I would ask @Aras or one of the other devs who worked on shadows.

    You should light dynamic objects using light probes and reflection probes.
     
  13. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,028
    @KEngelstoft I did here, but nobody at Unity responded to me, and there are others with the same issue here, but no official response from anyone at Unity to why custom matrix projections cause shadows to no longer show up in Unity 5, so I thought posting at a Unity 5 lighting thread might help. My bad.
     
    Last edited: Mar 13, 2015
  14. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    18,524
    One issue we have with having a full time of day solution is that shadows will look wrong in the far distance, so some form of approximation in shadows are required for the maximum draw distance parts. Other engines solve this with a semi raycast solution, and I'm wondering if Unity has any plans in this respect for open world dynamic games?
     
  15. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    857
    @hippocoder yes, we would like to introduce a solution for that at some point during 5.x (it is on our trello board), but right now we are focusing on fixing bugs rather than introducing more major features. First we have to fix the mixed mode shadows, then we can look into more fancy solutions.
     
    hopeful and hippocoder like this.
  16. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    18,524
    Thanks, sorry for interrupting :)
     
  17. Hjeldnes

    Hjeldnes

    Joined:
    Jul 22, 2012
    Posts:
    107
    Okay, thanks! Yep, I guess with dx12, mantle and metal, then draw calls won't be as problematic as they used to be..
    Some more questions:
    What's the difference between drawcall and setpass, and how many setpass calls is considered ok on todays hardware?
    And what decides the amount of setpass calls, and how can we control the amount of state changes. By using few shaders and so on?
    And when do we get a state change, and what exactly is the cost?

    On the emissive test I did, I had reflection probes and light probes, but the emissive light did not affect the dynamic object. It was a very basic test with a few boxes and a sphere. I believe it was all correctly setup. I'll have another look when I get to work tomorrow morning.

    And yep, proper soft shadows on local lights would be great, a must really :) Tell the shadow guys to fix it ;)
     
  18. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    857
    The documentation you are looking for is available here, although a bit out of date (it will be automatically updated once the next patch ships) http://docs.unity3d.com/Manual/RenderingStatistics.html
    SetPass is the number of rendering passes. Each pass requires Unity runtime to bind a new shader which may introduce CPU overhead. This is way higher than the overhead for a drawcall and it is SetPass you have to optimize for even on current rendering APIs.
     
  19. montyfi

    montyfi

    Joined:
    Aug 3, 2012
    Posts:
    515
    Am I understand correctly that in the current version of Unity 5 it is not possible to use baked GI if you want shadows from non-static objects? Will it be available in 5.0.2? 5.0.3?
     
  20. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    337
    Still waiting for solutions..
    Gonna watch this thread!
     
  21. RimFra

    RimFra

    Joined:
    Mar 27, 2015
    Posts:
    85
    Any news about this?I really need this fix..
     
  22. FreakForFreedom

    FreakForFreedom

    Joined:
    Jan 22, 2013
    Posts:
    148
    Second that. :(
     
  23. thehosse

    thehosse

    Joined:
    Nov 29, 2013
    Posts:
    32
    Any updates on the mixed mode lightmaps?

    Also I'm having issues creating lightmaps with AO enabled. "
    'Bake AO' job failed with error code: 4294967295 ('Unknown error.')."

    Anybody had this?
     
  24. thehosse

    thehosse

    Joined:
    Nov 29, 2013
    Posts:
    32
    Ok so I managed to produce this just now, I seem to have a mixed lightmap mode working...? Realtime shadows in the forground and baked shadows in the distance. Only issue is the baked shadows in the foreground are being rendered with the realtime shadows...

    [​IMG]

    Using Unity 5.0.1f1

    Linear colour space
    Differed rendering

    I've tried this setup in one of our game scenes and it only bakes the shadows, no realtime forground shadows or AO pass on the lightmaps, this makes the lightmapper hang..

    Would be very helpful if anyone from the Unity staff could chime in with their input as I seem to be chasing my own tail now.! :)
     
  25. amiel_ace

    amiel_ace

    Joined:
    Oct 25, 2014
    Posts:
    5
    any news about this? hahaha :cool:
     
  26. Findus

    Findus

    Joined:
    Jun 23, 2012
    Posts:
    103
    @thehosse : To me it looks like you have double shadows. So a character walking between those shadows would clearly overlay his shadow over an already existing set of shadows/ the shadow would seem to have different transparancy/density.

    @KEngelstoft : "Mixed mode lighting is intended to be used exactly as you wrote, with the limitation that it is used for sunlight only. " this seems really limiting. It's almost like Unity telling us what kind of scenarios and games we can and can't create. Don't get me wrong, problem solving is of course a part of development, but right now there are far too many problems with lightmapping for my taste.
     
  27. phasiclabs

    phasiclabs

    Joined:
    Nov 13, 2013
    Posts:
    120
    *bump*

    Seriously though, mixed mode lightmaps would be extremely useful. Is there a roadmap/schedule for fixing them?
     
    Gekigengar likes this.
  28. Tinovdk

    Tinovdk

    Joined:
    Nov 28, 2013
    Posts:
    65
    I'm seconding this. How is this issue coming along Unity? Ever since Unity 5 released you guys have done a great effort tackling bugs, but I have yet to see a mention on mixed shadows in the patch list. An update on the issue that many are looking forward to would be really appreciated.
     
  29. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    387
    Any news ?
     
  30. Matthew-Schell

    Matthew-Schell

    Unity Technologies

    Joined:
    Oct 1, 2014
    Posts:
    215
    The news from the devs is that while it's not fixed it remains a top priority. I was just looking into this myself and that's the latest as of today, sorry I don't have more detail.
     
    Bruce_GMC and jimmikaelkael like this.
  31. Tinovdk

    Tinovdk

    Joined:
    Nov 28, 2013
    Posts:
    65
    Hi Matthew (or other Unity representative),

    Looking at Unity's roadmap for 5.2, I'm not seeing anything about shadows in the mixed mode lighting. http://unity3d.com/unity/roadmap/

    Has it been scrapped?
     
    Bruce_GMC and Gekigengar like this.
  32. karolled

    karolled

    Joined:
    Apr 8, 2013
    Posts:
    11
    UNITY TEAM FIX LIGHTMAPPPING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
     
    Swagmiral likes this.
  33. Tinovdk

    Tinovdk

    Joined:
    Nov 28, 2013
    Posts:
    65
    Lightmapping itself actually works most of the time as I've described in this recent blog: http://sassybot.com/blog/lightmapping-in-unity-5/. It's just that lights set to mixed mode does not create dynamic shadows inside the shadow radius as it did in Unity 4.x. I'm currently using a rather unoptimised solution that clutters the scene much more than it should and I would love for the mixed shadows to work like it did before. Not seeing it on the roadmap while I was under the impression that it was came as a surprise to me.
     
    radiantboy, Bruce_GMC and chrismarch like this.
  34. Bruce_GMC

    Bruce_GMC

    Joined:
    Oct 23, 2014
    Posts:
    65
    I was also surprised by the lack of lightmapping appearances in the roadmap. I was also confused why they call it an internal roadmap when really its an internal feature checklist. The bugs that plague the current release, the bugs that are found through premium support, being worked on and referenced in issue tracker; these topics are the main point of interest to people who use unity to its potential.

    After seeing unity emps say that it's a top priority, witnessing the status of light map bugs in issue tracker mostly all getting set to fixed(ie the bug my dev submitted http://issuetracker.unity3d.com/issues/radiosity-core-is-corrupted-when-backing-lightmap, etc.. I have decided that they have fixed it now and are preparing it for a future 5.1 patch. Since 5.0.1, the word on the nets has been 5.1 will fix lightmapping but it looks like they are dragging it out until september. So I'm crossing my fingers. /speculation /hopes /dreams :(

    Upside: This looks cool. https://drive.google.com/file/d/0B11iL4IgOgWLUTJWU1ZXOXFheTA/view
     
    Last edited: Jun 26, 2015
  35. Tinovdk

    Tinovdk

    Joined:
    Nov 28, 2013
    Posts:
    65


    So does this. There are cool things on the horizon but that's besides the point. We are working on a commercial project where we relied on the ability to use mixed shadows as was possible with the Beast lightmapper.

    This feature is not working as intended according to the comment above and there is no update on when we can expect to see this addressed
     
  36. Tinovdk

    Tinovdk

    Joined:
    Nov 28, 2013
    Posts:
    65
  37. Bruce_GMC

    Bruce_GMC

    Joined:
    Oct 23, 2014
    Posts:
    65
    I understand where you're coming from. We started our project on version 4.6, using shaderforge to build our shaders. It wasn't until I talked with Sony and MS that I realized 4.6 would be totally unsupported by consoles. We were forced to upgrade and keep our stunning visuals and mechanics built on new 4.6+ systems or downgrade to 4.3, losing our shaders and mechanics which would force our devs to start building these systems by hand. Superspline comes to mind..

    Anyways, I added a vote for you. Curious though, does this only happen in directional specular mode?
     
  38. Tinovdk

    Tinovdk

    Joined:
    Nov 28, 2013
    Posts:
    65
    Thanks. Maybe it sways Unity's efforts more in favor of fixing this but I'm sure they are already very much aware of the severity of the issue.

    In our case we got really excited about the UI features of 4.6 and created our interface with it. Then we realised exactly the same as you did. It's either upgrade to 5.x and keep the UI, or dump the UI and downgrade a couple of versions.

    I've just tested it for just Directional Mode and shadows are not shown for dynamic objects with a directional light set to Mixed. However, if you set your lighting mode to Forward then the dynamic objects will cast a shadow from mixed lights. Depending on how many lights you have in your scene, this could be worth the consideration.

    lightmap_directional.PNG

    I hope that the solution to the problem in the issuetracker also solves it for all directional modes in deferred rendering. This instance of the issue was the closest entry I could find to our problem.
     
  39. montyfi

    montyfi

    Joined:
    Aug 3, 2012
    Posts:
    515
    In my case that stops working as soon as I baked lightmap in Forward.
     
  40. Mad-Monkey-Art

    Mad-Monkey-Art

    Joined:
    Oct 22, 2014
    Posts:
    7
    It seems like only non-static assets will receive shadows from each other. So shadows are cast but you will only see them on the object itself and all other non-static objects.
     
    Last edited: Jul 2, 2015
  41. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,025
    This is a gamebreaker for my title that has been in development for a very long time, and looking to get builds out to publishers in the next few weeks, but I won't be able to if Mixed mode lighting is broken, as it makes a huge difference in the visual aspect of my game.

    Not to mention the submissions for the Unity Awards close on 31 July, which I very much intend to enter.

    Is there any update or ETA, or any temporary workaround?? Shadow performance on Android is absolutely horrible, so lightmapping with mixed mode is my only option really.
     
    Last edited: Jul 6, 2015
    Shkarface-Noori likes this.
  42. Kuba

    Kuba

    Unity Technologies

    Joined:
    Jan 13, 2009
    Posts:
    372
    The roadmap (http://unity3d.com/unity/roadmap/) shows only new features. The bug database (http://issuetracker.unity3d.com) contains only bugs. Feedback (http://feedback.unity3d.com/) contains only feature requests.

    Not sure why you think we should mix the features and the bugs in one list. They are quite different in nature.

    You can be sure we prioritize the bugs as well as we can. We do use the vote count, among other things, to decide which bugs to tackle next.

    In the Global Illumination team we almost exclusively work on fixing bugs for some months now. We do have two features in development, but the reason they are being worked on is that they will allow us to tackle a big group of bugs related to lightmapping speed.
     
  43. Kuba

    Kuba

    Unity Technologies

    Joined:
    Jan 13, 2009
    Posts:
    372
    Could you elaborate on what exactly do you want to achieve? Some setups do already work, some were just fixed recently, but will reach a beta only in a small few weeks. We're discussing how to fix it across the board (for the different rendering paths, how it should interact with light probes, etc.).
     
  44. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,025
    My game involves trucks racing offroad around in a stadium. I want the stadium itself and props etc all to have shadows casted onto the track and the environment, as it adds a nice effect.

    If I use mixed mode, shadows still cast in realtime, which brings performance down from 30FPS on my Android device to 1-2FPS.

    If I set the lighting to Baked only, then my trucks look all dull and unlit, and not very appealing to the eye.

    So the case here is having static objects baked, and dynamic objects still being lit in realtime.

    I've currently figured a workaround for this, I have two lights, one for baking, and one for realtime. And I just set the culling mask on the realtime light to my trucks layer, and set the culling mask on the baked light layer to everything else.

    Although this means my trucks don't cast any realtime shadows on the track surface (which is baked only lighting). So I've had to resort to shadow projectors.
     
  45. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,504
    Have you tried using light probes for your trucks? And maintaining the baked only solution?
     
  46. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,025
    Putting light probes around every single piece of track in the game sounds like a very time consuming solution, the trucks will always be lit, so sounds like a bit overkill?
     
  47. Tinovdk

    Tinovdk

    Joined:
    Nov 28, 2013
    Posts:
    65
    Even though light probes would help make the truck look more grounded in the environment, there is still the problem of dynamic shadows that need to be cast from the truck.

    Placing light probes around your environment may sound time consuming but I generally find the result to be worth the effort.
     
  48. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,025
    Worth the effort if they still don't cast dynamic shadows?

    What effort are they worth, if having a second light that is realtime only can just provide lighting for them?
     
  49. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,504
    You'll get light and shadow from the existing baked lights. The real time directional light won't have this.
     
  50. Tinovdk

    Tinovdk

    Joined:
    Nov 28, 2013
    Posts:
    65
    You get light sampled from that point in space onto the light probe and it will be applied to dynamic objects close to that light probe. The light that is sampled includes bounce light. So even though you will not have dynamic shadows with light probes, you will have the illusion of bounce light when you distribute light probes and bake a lightmap.
     
    jimmikaelkael likes this.