# Lighting channels and real-time lighting

**URL:** <https://forums.unrealengine.com/t/lighting-channels-and-real-time-lighting/299547>\
**Category:** Rendering\
**Tags:** static-light, realtime, dynamic-lighting, unreal-engine, Rendering, Lighting, question\
**Created:** [November 21, 2014, 3:40pm UTC](https://forums.unrealengine.com/t/lighting-channels-and-real-time-lighting/299547 "2014-11-21T15:40:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leszek\_Godlewski\_Astronauts\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Leszek\_Godlewski\_Astronauts\_1](https://forums.unrealengine.com/u/Leszek_Godlewski_Astronauts_1)\
**Post date:** [November 21, 2014, 3:40pm UTC](https://forums.unrealengine.com/t/lighting-channels-and-real-time-lighting/299547/1 "2014-11-21T15:40:04Z")

</div>

Hi everyone,

I’ve implemented lighting channels much like in UE3 by putting an `FLightingChannelContainer` in `ULightComponentBase`, `UPrimitiveComponent`, all their `SceneInfo`s etc. and doing the AND operation in `ULightComponent::AffectsPrimitive()` and `ULightSceneInfoCompact::AffectsPrimitve()`.

And it works, but only for static lights ― and only after rebuilding the level lighting. Real-time lights seem to ignore the channels, even though I made sure `FLightPrimitiveInteraction`s are not instantiated for components with non-overlapping channels.

Where should I look to fix that?

---

<div class="post-metadata">

**Author:** ![Leszek\_Godlewski\_Astronauts\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Leszek\_Godlewski\_Astronauts\_1](https://forums.unrealengine.com/u/Leszek_Godlewski_Astronauts_1)\
**Post date:** [November 27, 2014, 12:59pm UTC](https://forums.unrealengine.com/t/lighting-channels-and-real-time-lighting/299547/2 "2014-11-27T12:59:54Z")

</div>

Okay, I’ve managed to implement it myself.

G-buffer B’s alpha channel normally contains only the shading model ID, of which there are 6. So they only occupy 3 bits, leaving 5 bits free. I’m populating them with 5 lighting channels by properly adjusting the G-buffer encoding and decoding functions. Light channel bitmasks are injected via new uniform buffer fields in `FPrimitiveUniformShaderParameters` and `FDeferredLightUniformStruct`. The masks are ANDed in `GetDynamicLighting()` in `DeferredLightingCommon.usf`.

Auxiliary code is trivial.

---

<div class="post-metadata">

**Author:** ![Waffle\_SS](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Waffle\_SS](https://forums.unrealengine.com/u/Waffle_SS)\
**Post date:** [May 21, 2016, 2:52pm UTC](https://forums.unrealengine.com/t/lighting-channels-and-real-time-lighting/299547/3 "2016-05-21T14:52:47Z")

</div>

Could you share your code/the files you changed to achieve this?
