NcEngine
Material.h
Go to the documentation of this file.
1
5#pragma once
6
8#include "ncmath/Vector.h"
9
10#include <limits>
11#include <utility>
12
13namespace nc
14{
15namespace graphics
16{
17class MaterialRegistry;
18} // namespace graphics
19
21using MaterialInstanceHandle = uint32_t;
22
24constexpr auto NullMaterialInstanceHandle = std::numeric_limits<MaterialInstanceHandle>::max();
25
28{
29 using type = uint64_t;
30
31 static constexpr auto UniShadow = type{1 << 0};
32 static constexpr auto PointShadow = type{1 << 1};
33 static constexpr auto Depth = type{1 << 2};
34 static constexpr auto Toon = type{1 << 3};
35 static constexpr auto Normals = type{1 << 4};
36};
37
39using MaterialPassFlags = MaterialPassFlag::type;
40
42constexpr auto ShadowedToonMaterial = MaterialPassFlag::UniShadow | MaterialPassFlag::PointShadow | MaterialPassFlag::Depth | MaterialPassFlag::Toon | MaterialPassFlag::Normals;
43
46{
47 Vector4 gradientStart = Vector4::One();
48 Vector4 gradientEnd = Vector4::One();
49 Vector4 primaryColor = Vector4::One();
50 Vector4 secondaryColor = Vector4::One();
51 Vector4 tertiaryColor = Vector4::One();
52 float normalIntensity = 1.0f;
53 float hatchTiling = 1.0f;
54 float gradientAmount = 0.1f;
55 float reflectivity = 0.0f;
59 bool useTextureNormals = true;
60 bool useFlatShading = true;
61 bool useColorOverride = false;
62 bool useHatchTexture = false;
63};
64
67{
68 std::string name = "DefaultMaterial";
71};
72
75{
76 public:
77 explicit MaterialInstance(const MaterialDesc& desc = MaterialDesc{});
78 MaterialInstance(MaterialInstance&& other) noexcept;
79 MaterialInstance& operator=(MaterialInstance&& other) noexcept;
80 ~MaterialInstance() noexcept;
81
82 MaterialInstance(const MaterialInstance&) = delete;
83 MaterialInstance& operator=(const MaterialInstance&) = delete;
84
86 auto Clone() const -> MaterialInstance;
87
89 auto GetName() const -> std::string_view;
90 void SetName(std::string_view name);
91
93 auto GetPasses() const -> MaterialPassFlags;
94
96 auto GetProperties() const -> const MaterialProperties&;
97 void SetProperties(const MaterialProperties& properties);
98
101 {
102 return m_handle;
103 }
104
105 private:
107 static inline graphics::MaterialRegistry* s_registry = nullptr;
108
109 MaterialInstanceHandle m_handle;
110
111 void Release() noexcept;
112};
113
114inline MaterialInstance::MaterialInstance(MaterialInstance&& other) noexcept
115 : m_handle{std::exchange(other.m_handle, NullMaterialInstanceHandle)}
116{
117}
118
119inline MaterialInstance& MaterialInstance::operator=(MaterialInstance&& other) noexcept
120{
121 if (this != &other)
122 {
123 Release();
124 m_handle = std::exchange(other.m_handle, NullMaterialInstanceHandle);
125 }
126
127 return *this;
128}
129
130inline MaterialInstance::~MaterialInstance() noexcept
131{
132 Release();
133}
134} // namespace nc
MaterialPassFlag::type MaterialPassFlags
Set of flags indicating a MaterialInstance's enabled passes.
Definition: Material.h:39
constexpr auto NullMaterialInstanceHandle
Null identifier for a MaterialInstance.
Definition: Material.h:24
uint32_t MaterialInstanceHandle
Identifier for a MaterialInstance.
Definition: Material.h:21
constexpr auto ShadowedToonMaterial
Default passes for a toon material.
Definition: Material.h:42
Owning wrapper around a material in GPU memory.
Definition: Material.h:75
auto GetHandle() const -> MaterialInstanceHandle
Get the instance's handle.
Definition: Material.h:100
auto GetProperties() const -> const MaterialProperties &
Get the instance's handle.
void SetProperties(const MaterialProperties &properties)
Get the instance's handle.
auto Clone() const -> MaterialInstance
Create a new MaterialInstance from this instance's properties.
friend class graphics::MaterialRegistry
Get the instance's handle.
Definition: Material.h:106
Properties for constructing a MaterialInstance.
Definition: Material.h:67
Material pass flags.
Definition: Material.h:28
Properties of a MaterialInstance passed to shaders.
Definition: Material.h:46
A four component vector.
Definition: Vector.h:48
Definition: AssetViews.h:66