// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
#pragma once
#include "../Actor.h"
#include "Engine/Content/Assets/CubeTexture.h"
#include "Engine/Content/AssetReference.h"
///
/// Environment Probe can capture space around the objects to provide reflections.
///
API_CLASS() class FLAXENGINE_API EnvironmentProbe : public Actor
{
DECLARE_SCENE_OBJECT(EnvironmentProbe);
private:
float _radius;
bool _isUsingCustomProbe;
int32 _sceneRenderingKey = -1;
AssetReference _probe;
public:
///
/// The reflections brightness.
///
API_FIELD(Attributes="EditorOrder(10), DefaultValue(1.0f), Limit(0, 1000, 0.01f), EditorDisplay(\"Probe\")")
float Brightness = 1.0f;
///
/// Value indicating if probe should be updated automatically on change.
///
API_FIELD(Attributes="EditorOrder(30), DefaultValue(false), EditorDisplay(\"Probe\")")
bool AutoUpdate = false;
///
/// The probe capture camera near plane distance.
///
API_FIELD(Attributes="EditorOrder(30), DefaultValue(10.0f), Limit(0, float.MaxValue, 0.01f), EditorDisplay(\"Probe\")")
float CaptureNearPlane = 10.0f;
public:
///
/// Gets the probe radius.
///
API_PROPERTY(Attributes="EditorOrder(20), DefaultValue(3000.0f), Limit(0), EditorDisplay(\"Probe\")")
float GetRadius() const;
///
/// Sets the probe radius.
///
API_PROPERTY() void SetRadius(float value);
///
/// Gets probe scaled radius.
///
API_PROPERTY() float GetScaledRadius() const;
///
/// Returns true if env probe has cube texture assigned.
///
API_PROPERTY() bool HasProbe() const
{
return _probe != nullptr;
}
///
/// Returns true if env probe has cube texture assigned.
///
API_PROPERTY() bool HasProbeLoaded() const
{
return _probe != nullptr && _probe->IsLoaded();
}
///
/// Gets the probe texture used during rendering (baked or custom one).
///
API_PROPERTY() CubeTexture* GetProbe() const
{
return _probe;
}
///
/// True if probe is using custom cube texture (not baked).
///
API_PROPERTY() bool IsUsingCustomProbe() const
{
return _isUsingCustomProbe;
}
///
/// Setup probe data structure
///
/// Packed probe data to set
void SetupProbeData(struct ProbeData* data) const;
///
/// Gets the custom probe (null if using baked one or none).
///
API_PROPERTY(Attributes="EditorOrder(40), DefaultValue(null), EditorDisplay(\"Probe\")")
CubeTexture* GetCustomProbe() const;
///
/// Sets the custom probe (null to disable that feature).
///
/// Probe cube texture asset to use
API_PROPERTY() void SetCustomProbe(CubeTexture* probe);
public:
///
/// Bakes that probe. It won't be performed now but on async graphics rendering task.
///
/// 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:
// [Actor]
#if USE_EDITOR
BoundingBox GetEditorBox() const override
{
const Vector3 size(50);
return BoundingBox(_transform.Translation - size, _transform.Translation + size);
}
#endif
void Draw(RenderContext& renderContext) override;
#if USE_EDITOR
void OnDebugDrawSelected() override;
#endif
void OnLayerChanged() override;
void Serialize(SerializeStream& stream, const void* otherObj) override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
bool HasContentLoaded() const override;
bool IntersectsItself(const Ray& ray, float& distance, Vector3& normal) override;
protected:
// [Actor]
void OnEnable() override;
void OnDisable() override;
void OnTransformChanged() override;
};