Point lights with source length building static lighting in incorrect direction

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

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.

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

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.

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.