// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #pragma once #if COMPILE_WITH_MATERIAL_GRAPH #include "Types.h" #include "Engine/Graphics/Materials/MaterialInfo.h" /// /// We use them to map layer's params ID. /// Used in layered materials to change param ID for each layer (two or more layers may have the same params ID from the same base material) /// struct LayerParamMapping { Guid SrcId; Guid DstId; }; /// /// Single material layer /// class MaterialLayer { public: struct LayerUsage { String VarName; void* Hint; LayerUsage() { Hint = nullptr; } }; public: /// /// Layer ID /// Guid ID; /// /// Graph data /// MaterialGraph Graph; /// /// Root node /// MaterialGraph::Node* Root; /// /// Material structure variable name (different for every layer sampling with different UVs, default UVs are a first index) /// LayerUsage Usage[4]; /// /// Layer features flags /// MaterialFeaturesFlags FeaturesFlags; /// /// Layer usage flags /// MaterialUsageFlags UsageFlags; /// /// Domain /// MaterialDomain Domain; /// /// Blending mode /// MaterialBlendMode BlendMode; /// /// The shading model. /// MaterialShadingModel ShadingModel; /// /// The opacity threshold value (masked materials pixels clipping). /// float MaskThreshold; /// /// The opacity threshold value (transparent materials shadow pass though clipping). /// float OpacityThreshold; /// /// Helper array with original layer parameters Ids mappings into new Ids /// Note: during sampling different materials layers we have to change their parameters Ids due to possible Ids collisions /// Collisions may occur in duplicated materials so we want to resolve them. /// Array ParamIdsMappings; public: /// /// Initializes a new instance of the class. /// /// The layer asset identifier. MaterialLayer(const Guid& id); public: /// /// Clear all cached values /// void ClearCache(); /// /// Prepare layer for the material compilation process /// void Prepare(); Guid GetMappedParamId(const Guid& id); String& GetVariableName(void* hint); bool HasAnyVariableName(); void UpdateFeaturesFlags(); public: /// /// Create default empty layer /// /// Layer id /// Layer static MaterialLayer* CreateDefault(const Guid& id); /// /// Load layer data /// /// Layer id /// Stream with saved graph object /// Material info structure /// Calling object name /// Layer static MaterialLayer* Load(const Guid& id, ReadStream* graphData, const MaterialInfo& info, const String& caller); private: void createRootNode(); }; #endif