Game.Prefabs.Effects.LightEffect
Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Effects
Type: class
Base: ComponentBase
Summary:
LightEffect is a component/prefab class used to configure and serialize runtime light effect parameters for the game (spot/point/area lights). It contains editor UI helper code (a nested ColorTemperatureSliderFieldFactory) and runtime data used to initialize ECS components (LightEffectData and EffectColorData). The class handles multiple light units (lumen, candela, lux, ev100), shape/area/spot conversions, color temperature, volumetrics and LOD-related distance factors.
Fields
-
public Game.Rendering.LightType m_Type
Used to select the logical light type (Spot, Point, Area). -
public Game.Rendering.SpotLightShape m_SpotShape
Spot-specific shape selection (Cone, Box, Pyramid). -
public Game.Rendering.AreaLightShape m_AreaShape
Area light shape selection (Rectangle, Tube). -
public float m_Range = 25f
Logical range used for LOD/distance calculations. -
public float m_Intensity = 10f
Serialized intensity value (previously named m_LuxIntensity). Represents the numeric intensity before unit conversion. -
public LightIntensity m_LightIntensity
Container that holds intensity and unit (m_Intensity + m_LightUnit). Used for unit-aware conversions. -
public float m_LuxAtDistance = 5f
Distance used when interpreting lux values (lux -> candela conversion uses this). -
public Game.Rendering.LightUnit m_LightUnit = Game.Rendering.LightUnit.Lux
Unit enum for the stored intensity (Lumen, Candela, Lux, Ev100, etc). -
public bool m_EnableSpotReflector = true
If true, spot lights consider reflector behavior for lumen→candela conversions. -
public float m_SpotAngle = 150f
Spot cone/spectrum angle (degrees). -
public float m_InnerSpotPercentage = 50f
Inner spot falloff percentage for spot lights. -
public float m_ShapeRadius = 0.025f
Radius for shape-based lights (area/tube). -
public float m_AspectRatio = 1f
Aspect ratio used for pyramid spot conversions. -
public float m_ShapeWidth = 0.5f
Area light width. -
public float m_ShapeHeight = 0.5f
Area light height. -
public bool m_UseColorTemperature = true
If true, color temperature multiplies the base color. -
public Color m_Color = new Color(1f, 0.86f, 0.65f, 1f)
Base light color (linear conversion applied in computations). -
public float m_ColorTemperature = 6570f
Color temperature in Kelvin. Decorated with a custom editor field (ColorTemperatureSliderFieldFactory). -
public Texture m_Cookie
Cookie texture for projection / gobo effects. -
public bool m_AffectDiffuse = true
Whether the light affects diffuse lighting. -
public bool m_AffectSpecular = true
Whether the light affects specular lighting. -
public bool m_ApplyRangeAttenuation = true
Whether range attenuation is applied. -
public float m_LightDimmer = 1f
Global dimmer multiplier applied to light output. -
public float m_LodBias
Bias used when calculating LOD limit from range. -
public float m_BarnDoorAngle
Barn door cropping angle (hidden in inspector). -
public float m_BarnDoorLength
Barn door cropping length (hidden in inspector). -
public bool m_UseVolumetric = true
If volumetric scattering is used. -
public float m_VolumetricDimmer = 1f
Dimmer for volumetric contribution. -
public float m_VolumetricFadeDistance = 10000f
Fade distance for volumetrics. -
(nested)
private class ColorTemperatureSliderFieldFactory
Provides an editor FieldBuilder for a color-temperature slider with icons. Internally holds an IconValuePairs instance and provides TryCreate and GetIconSource to supply icons based on temperature.
Properties
- None declared public on this class.
(The class exposes behavior via methods and public fields; unit/intensity are wrapped in the LightIntensity object.)
Constructors
public LightEffect()
No explicit constructor defined in source; default parameterless constructor is used. Initialization of serialized field defaults occurs inline in the field declarations.
Methods
-
public void RecalculateIntensity(Game.Rendering.LightUnit oldUnit, Game.Rendering.LightUnit newUnit)
Converts stored m_Intensity between units using LightUtils and writes the converted value into m_Intensity and to m_LightIntensity.m_Intensity. Use when the project/editor unit setting changes. -
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds required ECS component types for the prefab: LightEffectData and EffectColorData. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
No archetype components added by this prefab (method present but empty). -
public override void Initialize(EntityManager entityManager, Entity entity)
Initializes runtime ECS component data: - Computes LOD limit from m_Range and m_LodBias,
- Calculates distance factors and writes LightEffectData (m_Range, m_DistanceFactor, m_InvDistanceFactor, m_MinLod),
- Ensures m_LightIntensity is set and unit-consistent,
-
Computes final emission color via ComputeLightFinalColor and writes it into EffectColorData on the entity.
-
public HDLightTypeAndShape GetLightTypeAndShape()
Maps this component's m_Type + shape enums to HDLightTypeAndShape values used by HDRP. Throws NotImplementedException for unsupported enum values. -
public Color GetEmissionColor()
Returns the emission color computed from m_Color (linear), m_LightIntensity.m_Intensity, optional correlated color temperature multiplication, and m_LightDimmer. This is similar to ComputeLightFinalColor but uses m_LightIntensity.m_Intensity directly (no unit conversions performed here). -
private float CalculateLightIntensityPunctual(float intensity)
Helper used for point/spot lights when m_LightUnit is lumen or lux conversions are required. Handles reflector/shape special cases and uses LightUtils helper conversions. -
private float ComputeLightIntensity()
Converts stored intensity (m_LightIntensity.m_Intensity with m_LightUnit) to the rendering intensity the renderer expects (candela/luminance depending on type). Handles lumen->candela, area lumen->luminance, ev100, lux->candela (with special-case for box spot), and returns the computed intensity value. -
public Color ComputeLightFinalColor()
Combines base linear color with ComputeLightIntensity(), optional correlated color temperature conversion and m_LightDimmer, returning the final color/intensity to write to EffectColorData.
(nested ColorTemperatureSliderFieldFactory methods)
-
private string GetIconSource(float value)
Returns an icon path string appropriate for the given temperature value using the internal IconValuePairs mapping. -
public FieldBuilder TryCreate(Type memberType, object[] attributes)
Implementation of IFieldBuilderFactory; returns a FieldBuilder (GradientSliderField configured for color temperature) which the editor UI can use to render a temperature slider with icons and gradient.
Usage Example
// Example: compute final color and write it somewhere or inspect it.
var lightEffect = new LightEffect();
lightEffect.m_Color = Color.white;
lightEffect.m_ColorTemperature = 3000f;
lightEffect.m_LightIntensity = new LightIntensity { m_Intensity = 1200f, m_LightUnit = Game.Rendering.LightUnit.Lumen };
Color finalColor = lightEffect.ComputeLightFinalColor();
// Example: convert intensity when unit setting changes
lightEffect.RecalculateIntensity(Game.Rendering.LightUnit.Lumen, Game.Rendering.LightUnit.Candela);
// Example: initialize ECS components for a prefab (called by prefab system)
lightEffect.Initialize(entityManager, entity);
Notes / Modding tips: - Use RecalculateIntensity when a global/light-unit setting changes to keep serialized m_Intensity consistent. - GetLightTypeAndShape maps the logical shapes to HDRP HDLightTypeAndShape — add support for extra shapes cautiously and match HDLightTypeAndShape expectations. - ComputeLightFinalColor applies both unit conversions and color-temperature multiplication; when inspecting emission color directly from m_LightIntensity be aware of unit differences.