// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#pragma once
#include "Light.h"
#include "Engine/Content/Assets/CubeTexture.h"
#include "Engine/Content/AssetReference.h"
///
/// Sky light captures the distant parts of the scene and applies it as a light. Allows to add ambient light.
///
API_CLASS(Attributes="ActorContextMenu(\"New/Lights/Sky Light\"), ActorToolbox(\"Lights\")")
class FLAXENGINE_API SkyLight : public Light
{
DECLARE_SCENE_OBJECT(SkyLight);
public:
///
/// Sky light source mode.
///
API_ENUM() enum class Modes
{
///
/// The captured scene will be used as a light source.
///
CaptureScene = 0,
///
/// The custom cube texture will be used as a light source.
///
CustomTexture = 1,
};
private:
AssetReference _bakedProbe;
float _radius;
public:
///
/// Additional color to add. Source texture colors are summed with it. Can be used to apply custom ambient color.
///
API_FIELD(Attributes="EditorOrder(21), DefaultValue(typeof(Color), \"0,0,0,1\"), EditorDisplay(\"Light\")")
::Color AdditiveColor = Color::Black;
///
/// Distance from the light at which any geometry should be treated as part of the sky.
///
API_FIELD(Attributes="EditorOrder(45), DefaultValue(150000.0f), Limit(0), EditorDisplay(\"Probe\")")
float SkyDistanceThreshold = 150000.0f;
///
/// The current light source mode.
///
API_FIELD(Attributes="EditorOrder(40), DefaultValue(Modes.CustomTexture), EditorDisplay(\"Probe\")")
Modes Mode = Modes::CustomTexture;
///
/// The custom texture.
///
API_FIELD(Attributes="EditorOrder(50), DefaultValue(null), EditorDisplay(\"Probe\")")
AssetReference CustomTexture;
public:
///
/// Gets the radius.
///
API_PROPERTY(Attributes="EditorOrder(29), DefaultValue(1000000.0f), Limit(0), EditorDisplay(\"Light\")")
FORCE_INLINE float GetRadius() const
{
return _radius;
}
///
/// Sets the radius.
///
API_PROPERTY() void SetRadius(float value);
///
/// Gets the scaled radius of the sky light.
///
float GetScaledRadius() const;
///
/// Gets the light source texture.
///
CubeTexture* GetSource() const;
public:
///
/// Bakes that probe.
///
/// The timeout in seconds left to bake it (aka startup time).
API_FUNCTION() void Bake(float timeout = 0);
///
/// Action fired when probe has been baked.
///
/// The new probe data.
void SetProbeData(TextureData& data);
private:
void UpdateBounds();
public:
// [Light]
void Draw(RenderContext& renderContext) override;
#if USE_EDITOR
void OnDebugDrawSelected() override;
#endif
void Serialize(SerializeStream& stream, const void* otherObj) override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
bool HasContentLoaded() const override;
protected:
// [Light]
void OnTransformChanged() override;
};