# Point lights with source length building static lighting in incorrect direction

**URL:** <https://forums.unrealengine.com/t/point-lights-with-source-length-building-static-lighting-in-incorrect-direction/427343>\
**Category:** Rendering\
**Tags:** Lightmass, unreal-engine, Rendering, Lighting, question\
**Created:** [June 14, 2018, 2:30am UTC](https://forums.unrealengine.com/t/point-lights-with-source-length-building-static-lighting-in-incorrect-direction/427343 "2018-06-14T02:30:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_Kitten](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nick\_Kitten](https://forums.unrealengine.com/u/Nick_Kitten)\
**Post date:** [June 14, 2018, 2:30am UTC](https://forums.unrealengine.com/t/point-lights-with-source-length-building-static-lighting-in-incorrect-direction/427343/1 "2018-06-14T02:30:37Z")

</div>

In 4.19.2, if you give a static point light a large Source Length, rotate it about the X-Axis 90 degrees, and bake lighting, you will see the light’s effect is 90 degrees rotated from the source. This was noted in [UE-56344](https://issues.unrealengine.com/issue/UE-56344). I’m posting this for anyone else who ran into the error, but was disappointed to find that the unreal issue doesn’t list the changelist that fixes it.

---

<div class="post-metadata">

**Author:** ![Nick\_Kitten](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nick\_Kitten](https://forums.unrealengine.com/u/Nick_Kitten)\
**Post date:** [June 14, 2018, 2:36am UTC](https://forums.unrealengine.com/t/point-lights-with-source-length-building-static-lighting-in-incorrect-direction/427343/2 "2018-06-14T02:36:38Z")

</div>

The fix was submitted as part of Epic’s P4 changelist 4053911; in LightmassScene.cpp, find all 3 instances of this line:

```
FVector4 L01 = Direction * LightSourceLength;

```

and replace it with this:

```
FVector4 L01 = GetLightTangent() * LightSourceLength;

```

Edit: to fix reflection captures, too, you need to make these additional changes in SceneVisibility.cpp:  
Around line 3037, replace

```
Color /= PI * FMath::Square( LightParameters.LightSourceRadius ) + 0.5f * PI * LightParameters.LightSourceRadius * LightParameters.LightSourceLength;

```

with this:

```
const float SphereArea = (4.0f * PI) * FMath::Square(LightParameters.LightSourceRadius);
const float CylinderArea = (2.0f * PI) * LightParameters.LightSourceRadius * LightParameters.LightSourceLength;
const float SurfaceArea = SphereArea + CylinderArea;
Color *= 4.0f / SurfaceArea;

```

and farther down around 3060, replace

```
FViewElementPDI LightPDI( &View, NULL );
// Scaled sphere to handle SourceLength
const float ZScale = FMath::Max(LightParameters.LightSourceRadius, LightParameters.LightSourceLength);
DrawSphere(&LightPDI, Origin, FRotationMatrix::MakeFromZ(LightParameters.NormalizedLightDirection).Rotator(), FVector(LightParameters.LightSourceRadius, LightParameters.LightSourceRadius, ZScale), 36, 24, ColoredMeshInstance, SDPG_World);

```

with this:

```
// fix reflection capture point light direction, should be fixed in 4.20
FMatrix LightToWorld = Proxy->GetLightToWorld();
LightToWorld.RemoveScaling();

FViewElementPDI LightPDI(&View, NULL);

if (LightParameters.LightSourceLength > 0.0f)
{
	DrawSphere(&LightPDI, Origin + 0.5f * LightParameters.LightSourceLength * LightToWorld.GetUnitAxis(EAxis::Z), FRotator::ZeroRotator, LightParameters.LightSourceRadius * FVector::OneVector, 36, 24, ColoredMeshInstance, SDPG_World);
	DrawSphere(&LightPDI, Origin - 0.5f * LightParameters.LightSourceLength * LightToWorld.GetUnitAxis(EAxis::Z), FRotator::ZeroRotator, LightParameters.LightSourceRadius * FVector::OneVector, 36, 24, ColoredMeshInstance, SDPG_World);
	DrawCylinder(&LightPDI, Origin, LightToWorld.GetUnitAxis(EAxis::X), LightToWorld.GetUnitAxis(EAxis::Y), LightToWorld.GetUnitAxis(EAxis::Z), LightParameters.LightSourceRadius, 0.5f * LightParameters.LightSourceLength, 36, ColoredMeshInstance, SDPG_World);
}
else
{
	DrawSphere(&LightPDI, Origin, FRotator::ZeroRotator, LightParameters.LightSourceRadius * FVector::OneVector, 36, 24, ColoredMeshInstance, SDPG_World);
}

```

Make sure to rebuild the UnrealLightmass project, and you’re good to go.

---

<div class="post-metadata">

**Author:** ![roborama](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@roborama](https://forums.unrealengine.com/u/roborama)\
**Post date:** [September 10, 2018, 9:22pm UTC](https://forums.unrealengine.com/t/point-lights-with-source-length-building-static-lighting-in-incorrect-direction/427343/3 "2018-09-10T21:22:23Z")

</div>

sorry for my ignorance, but how is this fixed if i need to be editing cpp files? I’m an artist. shouldn’t this just work if its fixed? My lighting is completely messed up because of this and stationary light aren’t an option for VR

---

<div class="post-metadata">

**Author:** ![Nick\_Kitten](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nick\_Kitten](https://forums.unrealengine.com/u/Nick_Kitten)\
**Post date:** [September 10, 2018, 10:16pm UTC](https://forums.unrealengine.com/t/point-lights-with-source-length-building-static-lighting-in-incorrect-direction/427343/4 "2018-09-10T22:16:23Z")

</div>

It’s fixed in 4.20. If, like we did, you have to ship with 4.19, this is how you fix it without upgrading to the new engine version.

---

<div class="post-metadata">

**Author:** ![roborama](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@roborama](https://forums.unrealengine.com/u/roborama)\
**Post date:** [September 11, 2018, 4:12am UTC](https://forums.unrealengine.com/t/point-lights-with-source-length-building-static-lighting-in-incorrect-direction/427343/5 "2018-09-11T04:12:01Z")

</div>

Great!

Sorry I thought you meant it was fixed in 4.19. I get it now.

We may have to ship in 4.19 so thanks for this Nick.
