Finality Engine
Loading...
Searching...
No Matches
MaterialAsset.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <Assets/Asset.h>
9#include <Core/Core.h>
10#include <Core/Pipeline.h>
11#include <Renderer/Material.h>
12
13#include <array>
14#include <cstdint>
15#include <memory>
16#include <string>
17#include <vector>
18#include <filesystem>
19
20namespace FINALITY
21{
22 class RenderDevice;
23
31
34 {
35 std::string Name;
37 uint32_t Offset = 64;
38 // Float uses 1 element; Vec4 uses 4; Mat4 uses 16, column-major.
39 std::array<float, 16> Default{};
40 };
41
44 {
45 std::string Name = "Untitled Material";
46 std::string Type = "Custom"; // Standard, Unlit, Custom or project-defined type
47 std::string VertexShader;
48 std::string FragmentShader;
49 bool EnableBlending = false;
51 std::vector<MaterialParameterDefinition> Properties;
52 // Current Vulkan implementation binds one combined image sampler at set=1, binding=0.
53 std::string TextureBinding;
54 std::string TexturePath;
55 };
56
57 // Cached shared asset loaded from a .fmat file. Do not animate this definition.
59 class FAPI MaterialAsset : public Asset
60 {
61 public:
62 static std::shared_ptr<MaterialAsset> Create(const std::string& filePath, RenderDevice* device);
63
64 AssetType GetType() const override { return AssetType::Material; }
65 const MaterialDefinition& GetDefinition() const { return m_Definition; }
66 MaterialDefinition& GetDefinition() { return m_Definition; }
67
68 std::shared_ptr<Material> CreateInstance() const;
69 void UpdateDefaultsFromInstance(const Material& instance);
70 bool ReloadShadersIfChanged(bool force = false);
71 void ReplaceTexture(const std::shared_ptr<Texture>& previous, const std::shared_ptr<Texture>& replacement);
72
73 private:
74 MaterialDefinition m_Definition;
75 std::shared_ptr<Pipeline> m_Pipeline;
76 std::shared_ptr<Texture> m_Texture;
77 std::string m_FilePath;
78 std::string m_VertexShaderPath;
79 std::string m_FragmentShaderPath;
80 std::filesystem::file_time_type m_VertexTimestamp{};
81 std::filesystem::file_time_type m_FragmentTimestamp{};
82 mutable std::vector<std::weak_ptr<Material>> m_Instances;
83 };
84}
#define FAPI
Definition Core.h:22
void ReplaceTexture(const std::shared_ptr< Texture > &previous, const std::shared_ptr< Texture > &replacement)
AssetType GetType() const override
MaterialDefinition & GetDefinition()
static std::shared_ptr< MaterialAsset > Create(const std::string &filePath, RenderDevice *device)
bool ReloadShadersIfChanged(bool force=false)
const MaterialDefinition & GetDefinition() const
std::shared_ptr< Material > CreateInstance() const
void UpdateDefaultsFromInstance(const Material &instance)
Defines the graphics backend boundary and render submission contract.
AssetType
Definition Asset.h:15
std::vector< MaterialParameterDefinition > Properties