Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Lighting in DOTS rendering

Discussion in 'Graphics for ECS' started by SamOld, Mar 7, 2020.

  1. SamOld

    SamOld

    Joined:
    Aug 17, 2018
    Posts:
    325
    As far as I'm aware, lights must currently be legacy
    GameObject
    components and hybrid rendering has no direct support for them. I'm not aware of any way to dynamically render lights into the scene through the
    Graphics
    API or anything, so I think that this is impossible to add at the moment. I guess that a new API in
    Graphics
    may be coming to support DOTS lighting.

    Does anyone know more about what the plan is here? A rough timeline would be helpful. This is one of the things holding me back from going full steam ahead with DOTS, because it's the main legacy component that's still fairly unavoidable.

    If anyone has any good tips or resources for working with lights in DOTS under the current setup, I'd be keen to hear them. In particular, small dynamic lights attached to entities. I had a quick play with using lights with
    HybridComponent
    a couple of weeks ago but ran into inconsistent, seemingly buggy, behaviour. Is this something that anybody has got working? I'll take another run at it if it's possible.
     
  2. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    Hey,

    I was just looking into this now, since the new Hybrid renderer 0.4 supports conversion of Lights (and Camera and more).

    The Light is added automatically as a HybridComponent, and you can then access it almost like any other component on the entity. Behind the scene this create a hidden GameObject with the managed component, and links it up to the entity.

    See this article for some info on the Hybrid components:
    https://gametorrahod.com/game-object-conversion-and-subscene/

    I just tried the following and it works just fine :)

    Code (CSharp):
    1. Entities.WithName("LightAnimationSystem_ForEach")
    2.         .WithoutBurst()
    3.         .ForEach((Light light) =>
    4.         {
    5.             Debug.LogWarning($"Found light: {light.intensity}");
    6.         })
    7.         .Run();
    FYI - Setting light intensity through the hybrid component does not calculate the correct value according to the chosen measurement (it usually ends up too bright). For now you can hack it by using the conversion formulas found in HDAdditionalLightData.cs.
     
    Last edited: Mar 14, 2020
  3. racer161

    racer161

    Joined:
    Mar 2, 2011
    Posts:
    6
    @siggigg Thank you. Your post saved me. I swear the ECS documentation gets worse with each release. Seems like they really don't want beginners messing around with this stuff but how hard would it be to post the literal 7 line example you have there on the github. GG Unity. Anyway, just wanted to say cheers for what would've been a forgone light feature in my game.
     
  4. SebastianAaltonen

    SebastianAaltonen

    Unity Technologies

    Joined:
    Feb 21, 2020
    Posts:
    112
    Thanks for the example.

    Hybrid entities is a new feature in development. In 0.4.0 package hybrid entities support was just added and there were still showstopper bugs. This feature wasn't properly working yet in 0.4.0. Documentation will be added when we have validated that the feature is working as intended. I make sure that we will be adding an example like this to the documentation.

    To get HDRP light working properly, you should do query over HDLightAdditionalData instead of Light. This way intensity also works properly.

    Code (CSharp):
    1. Entities.WithName("HDLightAnimationSystem_ForEach")
    2.         .WithoutBurst()
    3.         .ForEach((HDLightAdditionalData hdLight) =>
    4.         {
    5.             Debug.LogWarning($"Found HD light: {hdLight.intensity}");
    6.         })
    7.         .Run();
     
    Last edited: Apr 16, 2020
    Orimay, thelebaron and SamOld like this.
  5. SamOld

    SamOld

    Joined:
    Aug 17, 2018
    Posts:
    325
    Yeah, thanks for the example @siggigg, sorry for not replying before, it slipped my mind.

    @SebastianAaltonen, could you confirm that hybrid components and legacy
    Light
    components are the long term plan rather than some API that allows unmanaged light data to be directly injected into the renderer?

    I've been working on a custom volumetric lighting engine with the goal that the core of my engine should be compatible with both GameObject/MB and DOTS, and it's proving a bit hard to make design decisions without knowing what being compatible with DOTS actually means. Will
    CommandBuffer
    s be supported?

    Overall I've actually found Unity's APIs for this quite lacking. I would have liked to inject my own logic for handling every light in the scene, but I've not found a reasonable way of getting each light every frame, and I've had to resort to requiring a custom MB on each light to make it compatible with my system. This is something that the ECS is well suited to, but I don't know what that's going to look like yet, and it's helpful to support non-ECS lights too. It's a little bit of a mess.