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.
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.
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.
@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.
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.
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 CommandBuffers 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.