Search Unity

Resolved Hybrid Renderer V2: Light probes not working on entities

Discussion in 'Graphics for ECS' started by Samsle, Jan 13, 2022.

  1. Samsle

    Samsle

    Joined:
    Mar 31, 2020
    Posts:
    110
    Hello,
    I use Hybrid Renderer 0.11.0 + URP 11.0.0 in my project.
    It says here that for this combination light probes are supported.

    But my light probes are only working on GameObjects, not entities. Do I have to add maybe a component to my entity to get it to work?
     
  2. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    If you convert from GameObjects or use RenderMeshUtility.AddComponents, the required components should get added automatically. If not, you should add one of AmbientProbeTag, BlendProbeTag or CustomProbeTag.
     
    Samsle likes this.
  3. Samsle

    Samsle

    Joined:
    Mar 31, 2020
    Posts:
    110
    Thanks for your reply @JussiKnuuttila!
    Unfortunately this still does not work. I tried it with a very simple cube (lit material).

    As Gameobject (in GameWindow):
    gameobject.PNG

    When I move the cube into the subscene, it gets the BlendProbeTag like you said automatically, but still does not work :confused: (in GameWindow):
    entity.PNG

    And thats my light probe group (within subscene):
    upload_2022-1-13_19-37-36.png

    The object which is throwing the shadow is also in the subscene and static (via lightmap).
    And the directional light (just 1) is outside the subscene and not an entity.
     
    Last edited: Jan 13, 2022
  4. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    Do you see the SH coefficient components (BuiltinMaterialPropertyUnity_SHAr) on the entity at run time? Those should get added automatically by the light probe system. If those are missing, that would cause light probes to not work.
     
    Samsle likes this.
  5. Samsle

    Samsle

    Joined:
    Mar 31, 2020
    Posts:
    110
    Yap I see them at run time on my entity:
    upload_2022-1-14_12-27-13.png

    Btw I also use SRP and Unity 2021.1.15f1. But I guess there are still so many variables.. so many potential things I may do wrong. Is there maybe an example project for light probes & ecs?
     
  6. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    Reading through your message again, it's possible that the issue is related to the shadow caster also being inside the subscene.

    There is a known limitation in the current version, where light baking (both light maps and light probes) is unable to take entities into account during baking. To work around this, light baking should be performed with all subscenes opened so the source GameObjects are visible to the light baking. The resulting light maps and probes should then be usable by the entities when the subscenes are closed again.
     
    Samsle likes this.
  7. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    The sample scenes in HybridURPSamples in https://github.com/Unity-Technologies/EntityComponentSystemSamples should contain a simple example of light probe usage.

    It's also worth noting that 2021.1 is not an officially supported Unity version with Hybrid Renderer or DOTS, so it is possible that using it will cause extra problems.
     
    Samsle likes this.
  8. Samsle

    Samsle

    Joined:
    Mar 31, 2020
    Posts:
    110
    Thanks @JussiKnuuttila!
    I tested the Unity example for Light Probes, this time with the correct Unity Version.
    But for me, I needed light probes mainly for shadows, and these lightmaps in the example did not include any shadows thrown by these spheres.
    I could only bake them, if I changed the light-mode to "baked". In my own project with Unity 2021.1 it worked also with "mixed". But at least, with this mode (baked) the light probes for shadows finally worked -also for my own project! :)

    But now the drawback is, that dynamic entities are pretty dark in the scene (obviously) :confused:


    And something not related to the topic: In the example project I encountered the problem that the objects from the subscene are still visible in the scene view (the spheres), even when the subscene was closed o_O
    spheres.PNG
     

    Attached Files:

    Last edited: Jan 14, 2022
  9. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    If the subscene is closed, then any objects in it are converted to entities and are rendered in the scene view as entities, using Hybrid Renderer. Opened subscenes are rendered either as GameObjects (authoring state) or entities (runtime state) depending on LiveLink settings.
     
  10. Samsle

    Samsle

    Joined:
    Mar 31, 2020
    Posts:
    110
    Oh, then my experience was always the wrong/buggy one :D
    But yep, this behaviour sounds way more reasonable actual
     
  11. Arnold_2013

    Arnold_2013

    Joined:
    Nov 24, 2013
    Posts:
    285
    Thx for the post, I ran into the same issue. Using "baked" lightsource the light probes work, but now my dynamic objects don't cast shadows anymore.

    Have you by any chance found a way to get mixed light to work with light probes?

    (I'm on Entities 0.17.0; URP 10.3.2; HR V2 0.11.0-preview44. Unity 2020.3.11f1)
     
  12. Samsle

    Samsle

    Joined:
    Mar 31, 2020
    Posts:
    110
    @Arnold_2013 Nope, I gave up.
    But maybe it works with the new versions 0.50? I didn't give it a try yet
     
    Arnold_2013 likes this.
  13. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    This is weird. I have tried all kinds of settings, but for the life of me, I cannot get lighting to apply to entities that are in subscenes.

    Below is a lamp prefab in subscene that has a point light source attached to it. The terrain is a game object (because DOTS has no solution for terrain yet :mad:). The satellite dish is a game object. Everything looks fine - the point light on the lamp affects the dish and it casts a shadow.
    upload_2022-11-1_18-33-58.png

    Here it is after I attach convert-to-entity to the satellite dish and press play:

    upload_2022-11-1_18-37-40.png

    Yuck. The light clearly doesn't work on the satellite dish entity, but it works fine on the terrain game-object. Strangely, the shadow is being cast by the lamp though.

    Now here's the scene with the satellite dish in a subscene (with the subscene closed or in play-mode)

    upload_2022-11-1_18-39-7.png
    Same result as with convert-to-entity.

    Here's the scene without the lamp

    upload_2022-11-1_18-47-24.png
    You can see that the shadow is being cast by the sun instead of the lamp. So why do shadows cast by point lights work on entities, but the entities don't reflect the point light?

    I'm using entities 0.51 and I've tried for hours tweaking settings trying to find something that works. Tried with and without light probes, real-time and baked light maps, and so many other things.
     
    heu3becteh likes this.
  14. Arnold_2013

    Arnold_2013

    Joined:
    Nov 24, 2013
    Posts:
    285
    For URP you are only allowed 1 realtime directional light. All other lights don't work. (they work on terrain, because its a game object). I don't use HDRP, but there multiple lights are allowed I think.
     
  15. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    I am using a point light for the lamp - not a directional one. Are you sure about that limit? I thought the URP limitation was something like a max of 4 (some people say 8?) light contributions per mesh and 256 per camera. So whenever an object is rendered it use the 4 closest light sources and ignore any other lights that are in range. In my example above, I have one directional light (the sun) and one point light. So it seems to me that satellite dish should be lit by the lamp's point light.

    But something is preventing the lamp from contributing to the light of meshes on entities.... and allowing it for meshes on game objects. It's strange.
     
  16. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    If you using 2021LTS or later and using Deferred Rendering (as opposed to Forward Rendering) you aren't limited to 1 realtime directional light and can use point lights with URP
     
  17. Arnold_2013

    Arnold_2013

    Joined:
    Nov 24, 2013
    Posts:
    285
    lclemens likes this.
  18. Samsle

    Samsle

    Joined:
    Mar 31, 2020
    Posts:
    110
    lclemens likes this.
  19. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    DOTS 0.51 does not officially support local lights with URP.

    Entities 1.0 will officially support local lights in URP, but only when the URP Forward+ rendering mode is used. The rendering mode can be selected in the URP Renderer Asset.

    With both versions, URP Deferred might partially work. What is likely to happen is that basic lighting and shadows will work, but reflection probes do not. Also, it is important to note that this combination is not officially supported.

    The reason behind all of this is that URP relies on the same built-in light lists and reflection probe setup as the built-in render pipeline does. This special built-in setup is built around GameObjects, and is incompatible with the BatchRendererGroup rendering path that is used by Entities Graphics. One reason for this is that such setup requires position information for each rendered instance, which is not always available with BatchRendererGroup.

    Both HDRP and URP Forward+ implement lighting completely in screen space, without requiring special per-object setup, which is why they are the fully supported modes. URP Deferred uses screen space lighting, but still uses the built-in reflection probes, so those will not be correctly applied.
     
    heu3becteh, Arnold_2013 and lclemens like this.
  20. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    Thanks JussiKnuutila. Switching to URP deferred got the basic lighting and shadows working for my entities, and for now I'm not too concerned about reflection probes. I didn't know about the deferred mode until now, and I like the idea that it uses hardware acceleration to improve speed - so I hope that sometime soon after 1.0, deferred mode will be supported as well.
     
  21. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    One gotcha which really frustrates me - deferred rendering does not work with textured vertex animation techniques. So now I have to choose between broken point lights and broken animation. :(
     
  22. Arnold_2013

    Arnold_2013

    Joined:
    Nov 24, 2013
    Posts:
    285
    I don't use vertex animation from textures, but I implemented some basic extra lights for explosions. (I guess I can scrap this and move to the forward+ when I upgrade to ECS 1.0). Ned has a detailed rundown of implementing your own lights (there is also a Youtube video) https://nedmakesgames.medium.com/cr...h-with-universal-render-pipeline-5ad442c27276

    For me it worked good enough to get some shine on my entities. I do an extra render pass where I add 'this custom light calculation' multiplying it with the scene color buffer. (So the direction of the explosion light is not correct, but for me this was good enough visually and performance wise)

    The terrain is a GameObject, but the rock next to the blue tower is an entity. (The towers don't process the extra light in this image, they could if their layer was included in the render pass.)
     
    lclemens likes this.
  23. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    Wow, that's pretty cool. I don't I have the time to dive off into implementing my own lights. It seems like I've already written half of a game engine as it is since DOTS is missing so many common things that game engines have (animation, audio, terrain, pathfinding, AI, UI, particle effects, etc). I'll just cross my fingers and hope that 1.0 supports point lights, because if I have to keep implementing game engine features my game won't release until I'm 90 years old in a wheelchair.
     
    Arnold_2013 likes this.
  24. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    I haven't tested it yet, but supposedly point and spot lights are supported in 1.0.0-pre.15 !!!
    upload_2022-12-2_12-38-21.png
     
    ThatDan123 and Arnold_2013 like this.