CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Material.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Forward.hpp"
11
12#include "MaterialModel.hpp"
13
15
17
18namespace CeresEngine {
19
21 class Material : public TResource<Material> {
24
25 public:
26 using super::super;
27 };
28
30 class PBRMaterial : public TResource<PBRMaterial, Material> {
33
34 private:
37
38 public:
42
43 public:
44 using super::super;
45
46 explicit PBRMaterial(const PBRMaterialModel& model) { setModel(model); }
47 explicit PBRMaterial(ResourceData& resourceData, const PBRMaterialModel& model) : super(resourceData) { setModel(model); }
48
49 public:
50#define CE_MATERIAL_MODEL_PROPERTY_ACCESSOR(NAME, FIELD, TYPE) \
51 [[nodiscard]] inline const TYPE##MaterialProperty& get##NAME() const { return mModel.FIELD; } \
52 [[nodiscard]] inline TYPE get##NAME##Value() { return mModel.FIELD.value; } \
53 [[nodiscard]] inline const HTexture& get##NAME##Texture() { return mModel.FIELD.texture; } \
54 [[nodiscard]] inline const GPUSamplerDescriptor& get##NAME##Sampler() { return mModel.FIELD.sampler; } \
55 [[nodiscard]] inline const MaterialPropertySwizzle<TYPE>& get##NAME##Swizzle() { return mModel.FIELD.swizzle; } \
56 \
57 inline void set##NAME(const TYPE##MaterialProperty& value) { \
58 mModel.FIELD = value; \
59 markAsDirty(); \
60 didChangeModel(mModel); \
61 } \
62 \
63 inline void set##NAME(const TYPE& value) { \
64 mModel.FIELD = TYPE##MaterialProperty(value); \
65 markAsDirty(); \
66 didChangeModel(mModel); \
67 } \
68 \
69 inline void set##NAME##Value(const TYPE& value) { \
70 mModel.FIELD.value = value; \
71 markAsDirty(); \
72 didChangeModel(mModel); \
73 } \
74 \
75 inline void set##NAME##Texture(const HTexture& texture) { \
76 mModel.FIELD.texture = texture; \
77 markAsDirty(); \
78 didChangeModel(mModel); \
79 } \
80 \
81 inline void set##NAME##Sampler(const GPUSamplerDescriptor& sampler) { \
82 mModel.FIELD.sampler = sampler; \
83 markAsDirty(); \
84 didChangeModel(mModel); \
85 } \
86 \
87 inline void set##NAME##Swizzle(const MaterialPropertySwizzle<TYPE>& swizzle) { \
88 mModel.FIELD.swizzle = swizzle; \
89 markAsDirty(); \
90 didChangeModel(mModel); \
91 } \
92 \
93 inline void set##NAME(const HTexture& texture, const TYPE& value = TYPE(1)) { \
94 mModel.FIELD.texture = texture; \
95 mModel.FIELD.value = value; \
96 markAsDirty(); \
97 didChangeModel(mModel); \
98 }
99
107
110
112 void setNormalMapSpace(const MaterialNormalMapSpace normalMapSpace) {
113 mModel.normalMapSpace = normalMapSpace;
114 markAsDirty();
115 }
116
117 public:
118 template<typename Func> decltype(auto) changeModel(Func&& func) {
119 func(mModel);
120 markAsDirty();
122 }
123
125 [[nodiscard]] const PBRMaterialModel& getModel() const { return mModel; }
126
128 void setModel(const PBRMaterialModel& model) {
129 mModel = model;
130 markAsDirty();
132 }
133 };
134
136 class ShaderMaterial : public TResource<ShaderMaterial, Material> {
139
140 private:
143
144 public:
145 explicit ShaderMaterial(const HShader& shader);
146
147 public:
149 [[nodiscard]] const HShader& getShader() const { return mShader; }
150
152 void setShader(const HShader& shader);
153 };
154
155} // namespace CeresEngine
156
157
158
159
#define CE_MATERIAL_MODEL_PROPERTY_ACCESSOR(NAME, FIELD, TYPE)
Definition Material.hpp:50
#define CE_META_CLASS_FRIEND(T)
Definition Forward.hpp:48
A graphics material to be used when rendering objects in a scene.
Definition Material.hpp:21
A material type that uses a PBR model.
Definition Material.hpp:30
PBRMaterial(ResourceData &resourceData, const PBRMaterialModel &model)
Definition Material.hpp:47
void setModel(const PBRMaterialModel &model)
Definition Material.hpp:128
const PBRMaterialModel & getModel() const
Definition Material.hpp:125
void setNormalMapSpace(const MaterialNormalMapSpace normalMapSpace)
Determines if the normals are stored in tangent space, object-space or world-space.
Definition Material.hpp:112
MaterialNormalMapSpace getNormalMapType() const
Determines if the normals are stored in tangent space, object-space or world-space.
Definition Material.hpp:109
PBRMaterialModel mModel
The PBR material model. Can be used to quickly return.
Definition Material.hpp:36
Event< void(const PBRMaterialModel &)> didChangeModel
An event called whenever the associated PBRMaterialModel has a property changed.
Definition Material.hpp:41
decltype(auto) changeModel(Func &&func)
Definition Material.hpp:118
PBRMaterial(const PBRMaterialModel &model)
Definition Material.hpp:46
An object, provided by the resource manager, to view and alter data from the resource itself.
Definition Resource.hpp:89
void markAsDirty()
Marks the resource as dirty.
A material that renders using a custom shader.
Definition Material.hpp:136
void setShader(const HShader &shader)
The shader to be used when rendering the material.
ShaderMaterial(const HShader &shader)
const HShader & getShader() const
The shader to be used when rendering the material.
Definition Material.hpp:149
HShader mShader
The shader to be used when rendering the material.
Definition Material.hpp:142
Base template for the event class.
Definition Event.hpp:27
Utility template class that can be extended by Resources to automatically implement methods that are ...
Definition Resource.hpp:272
Definition Application.hpp:19
@ Color
Attachment is used for color output.
MaterialNormalMapSpace
Specifies the kind of normal map used by a material.
Definition MaterialModel.hpp:244
@ Normal
Displays the cursor normally as per the user operating system preferences.
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
double Double
Definition DataTypes.hpp:33
A material model that represents a PBR surface.
Definition MaterialModel.hpp:256
MaterialNormalMapSpace normalMapSpace
Determines if the normals are stored in tangent space, object-space or world-space.
Definition MaterialModel.hpp:280