LXR the ultimate light detection plugin for Unreal Engine 4.


Contents:

LXR
LXR is highly optimized plugin for detecting if actor is visible to a light source and how much and which color actor receives.

Multithreaded and tick-optimized performant solution even when multiple light sources are present.

Dynamically optimizes check interval based on distance to light source.

Calculates illuminance (lux) actor receives based on physically based lighting using same math that Unreal uses for rendering illuminance. LXR checks lights in two stages:

Relevancy


LXR works by checking all actors with ULXRSourceComponent for relevancy.
Relevancy is passed when LightComponent passes

  1. Distance
  2. Direction
  3. Attenuation
  4. Within cone angle of light (for rect and spots).

If LightComponent passes relevancy check, then ULXRSourceComponent will be marked as Relevant and moved to visibility checks.

Relevant


When ULXRSourceComponent is marked as Relevant LXR proceeds to check if LightComponents which passed Relevancy Check are actually visible to ULXRDetectionComponent by tracing light against RelevantTargetType.
ULXRSourceComponent will be marked as Passed if Visibility Check passes.

Passed lights


ULXRDetectionComponent will calculate combined intensity and light color from all Passed LightComponents.

When ULXRSourceComponent is marked as passed, LXR will do visibility checks for passed Lights.
If passed ULXRSourceComponent fails Visibility Check then it will be checked for Relevancy Check.
If checks fail by amount specified by Max Consecutive Fails in a row, then light will be moved back to Relevancy Check list.

Optimized


LXR is highly optimized.
Nothing gets done every frame.
Even in very absurd scenariod LXR does relevant check blazingly fast with proper Light Batch Count.

Stress test


I have quite high end CPU & GPU so your performance might be completely different.
But what I can say that LXR is blazing fast in real world scenarios.

This stress test is really absurd, we have 2048 pointlights stacked. A situation which you would never have in real game.

Sync


In this example we are processing all 2048 in one check using Sync method.
withoutbatch
Performance is not great.
Over 70 ms to check all lights.

Here is same scenario but Light Batch Count is set to 100.
Massive increase in performance.
withbatch

Multithread


Here is same with Multithread
mtwithoutbatch
And here Light Batch Count is set to 100.
mtwithbatch

This was a stress test, there will never be a real-world situation with 2048 lights overlapped.

Usage


Using LXR is really simple.
Developer needs to just add two components, one for detecting and one for LXR sources.

LXR is meant to be used to detect light from light from sources,
that means ULXRSourceComponent must be added to actor with at least one ULightComponent.

This limitation will be dropped in future versions IF developer only wants to know visibility of ULXRSourceComponent.

Actor with ULXRSourceComponent can have as many ULightComponent as required.

Main classes of LXR are:

ULXRDetectionComponent


ULXRDetectionComponent should be added to actors who should detect LXR.

Relevancy

relevancy

shared

Relevancy Check Rate Type
Relevancy Smart Distance Min
Relevancy Smart Distance Max
Relevancy Check Rate
Relevancy Target Type
Passed Targets Required Percentage


Relevancy Check Rate Type

There is two different algorithms for relevancy detection. Smart and Fixed

Smart

Smart relevancy is enabled by default.
Light sources gets categorized by distance in either Far, Mid or Near categories.
Categorizing uses ULXRDetectionComponent properties RelevancySmartDistanceMin and RelevancySmartDistanceMax.

Far
Mid
Near
Fixed

Check all lights for relevancy every time defined by RelevancyCheckRate property.
Default 0.1f.


Relevant

relevant

shared

Relevant Trace Type
Relevant Target Type
Relevant Light Check Rate
Light Batch Count
Trace Channel
Passed Targets Required
Max Consecutive Fails

Relevant Trace Type

There are two algorithms to choose from for doing line traces Sync or Multithread

Sync

Multithread

ULXRSourceComponent


ULXRSourceComponent for actors which should radiate LXR.

ULXRSourceComponent is meant to be added to any actor that have at least one ULightComponent

Even though LXR uses same math that Unreal uses for calculating illuminance, the final illuminance calculated by LXR is still an approximate.

LXR uses ULightComponent attenuation radius and intensity to calculate final illuminance. That means developers should always try to use attenuation radius which makes sense for light.

source

Excluded Light Names

Attenuation Multiplier to be Relevant

The final distance to check is

if(MinDistanceToForceRelevant != 0)
	DistanceToCheck = MinDistanceToForceRelevant

else if(MaxDistanceToCheckForRelevancy != 0)
	DistanceToCheck = MaxDistanceToCheckForRelevancy

else if(AttenuationMultiplierToBeRelevant != 0)
	DistanceToCheck = LightComponent.Attenuation * AttenuationMultiplierToBeRelevant;	
else
DistanceToCheck = 0;

ILXRLightSource


ILXRLightSource provides various overrides for developer without needing to modify ULXRSourceComponent for project specific needs.

	/* Possibility to override if light actor is enabled.
	Disabled light actor will not be traced against. */ 
	UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
	bool IsOn();

	/* Possibility to override actor's light components.
	By default ULXRSource will return all LightComponents for detection. */
	UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
	TArray<ULightComponent*> GetMyLightComponents();

ULXRSubsystem


Keeps list of all ULXRSourceComponent known to LXR.
Provides methods for removing and adding lights from LXR.

Register and Unregister are called automatically by ULXRSourceComponent

	//Registers new light source for LXR
	UFUNCTION(BlueprintCallable)
	void RegisterLight(AActor* LightSource);
	
	//Removes light source from LXR
	UFUNCTION(BlueprintCallable)
	void UnregisterLight(AActor* LightSource);


LXR Change Log


v 1.0

v 0.9






LXR planned features







LXR Downloads


LXR Example

Example features:

  1. WASD to move.
  2. Introduction of LXR features.
  3. Some gameplay examples. (COMING SOON)

Download Build.
Download Project. (Requires LXR)

LXR Showcase

Showcase features:

  1. WASD to move.
  2. F to toggle flashlight.
  3. A lot of dynamic LXR lights.
  4. AI will detect if player illuminates AI and if player is illuminated by AI light.

Download Build.


LXR Free edition

Free edition limitations:

Feature Free Marketplace
Illuminance x x
Color illuminance   x
Visibility x x
Multithreaded   x
Smart   x

Download Project (Coming Soon)