// Copyright (c) Wojciech Figat. All rights reserved.
#pragma once
#include "MaterialBase.h"
///
/// Instance of the with custom set of material parameter values.
///
API_CLASS(NoSpawn) class FLAXENGINE_API MaterialInstance : public MaterialBase
{
DECLARE_BINARY_ASSET_HEADER(MaterialInstance, 4);
private:
MaterialBase* _baseMaterial = nullptr;
public:
///
/// Gets the base material. If value gets changed parameters collection is restored to the default values of the new material.
///
API_PROPERTY() FORCE_INLINE MaterialBase* GetBaseMaterial() const
{
return _baseMaterial;
}
///
/// Sets the base material. If value gets changed parameters collection is restored to the default values of the new material.
///
/// The base material.
API_PROPERTY() void SetBaseMaterial(MaterialBase* baseMaterial);
///
/// Resets all parameters back to the base material (including disabling parameter overrides).
///
API_FUNCTION() void ResetParameters();
private:
void OnBaseSet();
void OnBaseUnset();
void OnBaseUnloaded(Asset* p);
void OnBaseParamsChanged();
public:
// [MaterialBase]
bool IsMaterialInstance() const override;
#if USE_EDITOR
void GetReferences(Array& assets, Array& files) const override;
bool Save(const StringView& path = StringView::Empty) override;
#endif
// [IMaterial]
const MaterialInfo& GetInfo() const override;
GPUShader* GetShader() const override;
bool IsReady() const override;
DrawPass GetDrawModes() const override;
bool CanUseLightmap() const override;
bool CanUseInstancing(InstancingHandler& handler) const override;
void Bind(BindParameters& params) override;
protected:
// [MaterialBase]
LoadResult load() override;
void unload(bool isReloading) override;
AssetChunksFlag getChunksToPreload() const override;
};