Search Unity

Why static lights create real-time shadows from static object to other static object?

Discussion in 'Global Illumination' started by methusalah999, Aug 22, 2019.

  1. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    I'm wondering. If a mixed light and 2 object are all static, the produced shadow will be calculated in real time, while it could be baked.

    Static means the object transform won't change. In the specific case of light emitters, it should also mean that the light range won't change. So it would be logic to bake such shadows, allowing the author to gain some perfs wherever he can.

    I understand that shadows may be affected by light intensity or color, and "static" only fixes the transform. But the author could simply make such lights dynamic.

    So why these shadows are calculated in real time?
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,791
    If you want to bake the shadows, switch the light from mixed to baked? I'm not seeing the issue here.
     
  3. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    A baked light won't produce any shadow from and to dynamic object. The principle of the mixed light, as far as I understand, is to bake a maximum of thing, and compute what can't be baked in realtime.
     
  4. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,791
    Cool, but to have lights produce shadow from and to dynamic object, you need to calculate shadows in real time. Try Shadowmask see if you like it better?

    It is possible to have unity not update any shadow maps if there aren't any dynamic objects in the light's furstum, some store assets do it, not sure if Unity does it native yet (maybe LWRP/HDRP?).
     
  5. uy3d

    uy3d

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    187
    There are two modes for this: Shadowmask and Distance Shadowmask. Details can be found here. There's also a link to a reference card on that page for an overview of the differences between the mode.

    In short, Shadowmask calculates shadows on statics and uses them for rendering. Statics can only cast shadows on dynamics via occlusion probes, so occlusion will be at the density of your light probes. Distance shadowmask does full realtime shadows within the shadow distance. You'll have to pay the cost of rendering statics into the shadowmaps so they can cast proper shadows on dynamics, and you still have to pay the cost of sampling the shadowmap when rendering statics to get shadows from dynamics on statics.
     
  6. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    My point is that in distance shadowmask mode, Unity could make the economy of calculating shadows in real time for static lights and objects, as static means they won't change. The baked shadow would be enough.

    The only drawback I see is that backed and realtime shadows may be visualy differnet, depending on the quality you set for each. But it's already a problem in distance shadowmask, at shadow distance, the blending is often visible.
     
    vuuk likes this.
  7. uy3d

    uy3d

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    187
    you still have to evaluate the realtime shadowmap to receive lights from dynamic casters. Otherwise you'd need some logic to detect when a dynamic object is within the light, and only use the realtime shadowmap in such cases, falling back to just sampling the shadowmask when there are no dynamics around. Unity doesn't do that, though.
     
  8. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    Yes, such logic would be needed, but I feel like it would be much effective than casting real time shadows that will never move, considering the number of static lights used in the average scene.

    But I understand it's not a trivial thing to implement. I was just wondering why the static status of lights was not used at all in shadowing as it is used in UnrealEngine. I understand that the real time lighting will be changed soon due to the deprecation of Enlighten. Maybe this point could be considered in the future system.

    @uy3d, @AcidArrow, thanks for your answers !
     
    AcidArrow likes this.