Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
material.h
1#ifndef OE_SCENE_MATERIAL_H
2#define OE_SCENE_MATERIAL_H
3
4#include <vector>
5#include <string>
6#include <map>
7#include <glm/mat4x4.hpp>
8
9namespace oe::render
10{
11 class Texture;
12 class ShaderBase;
13}
14
15namespace oe::scene
16{
21 {
25 std::string name;
26
33 };
34
41 {
48 glm::vec2 tiling = glm::vec2(1.f);
49
54 glm::vec2 offset = glm::vec2(0.f);
55 };
56
63 {
71 float transmission = 0.0f;
72
78 float thickness = 0.0f;
79
80 float attenuation_distance = 0.0f;
81 glm::vec3 attenuation_color = glm::vec3(1.0f);
82 };
83
90 {
91 public:
92 std::vector<TextureProperty> textures;
93
98
103
109 uint32_t flags = 0;
110
115
119 bool double_sided = false;
120
124 bool invert_faces = false;
125
131 bool is_blend = false;
132
137
141 float alpha_threshold = 0.5f;
142
146 Material* parent = nullptr;
147
151 bool inherit_properties = false;
152
156 bool inherit_textures = false;
157
158 /*
159 * @brief Set Texture at specified layer
160 *
161 * @param name Texture uniform name
162 * @param texture texture pointer
163 * @param layer layer (set to -1 to use the next available)
164 */
165 void setTexture(const std::string& name, render::Texture* texture/*, const int32_t layer = -1*/)
166 {
167 textures.push_back(
168 {
169 .name = name,
170 .texture = texture
171 });
172 }
173
174 /*
175 * @brief Get Texture stored at specified layer
176 */
177 //std::shared_ptr<oe::render::Texture> getTexture(const uint32_t& layer) const noexcept;
178
187 uint32_t getNextAvailableTextureLayer(const uint32_t start = 0) const;
188
193 /*const auto& getTextures() const
194 {
195 return _textures;
196 }*/
197
203 template <typename T>
204 Material* setProperty(const std::string& name, const T& value) = delete;
205
211 template <typename T>
212 Material* setArray(const std::string& name, const std::vector<T>& value) = delete;
213
214 private:
215 // todo for _textures : std::map<std::pair<TextureSettings, share<Texture>>
216 // TextureSettings would contain (among others?): scale, offset and rot
217 // todo² : see how to populate
218 //std::map<std::string, std::pair<uint32_t, std::shared_ptr<oe::render::Texture>>> _textures;
219 //std::map<uint32_t, std::shared_ptr<oe::render::Texture>> _textures_layers;
220
221 friend class oe::render::ShaderBase;
222
223 // Generate all material's properties containers
224 #define OE_ENGINE_SCENE_MATERIAL_GENERATE_PROPERTY(TYPE, PROPERTY) \
225 std::map<const std::string, TYPE> _prop_ ## PROPERTY; \
226 std::map<const std::string, std::vector<TYPE>> _prop_ ## PROPERTY ## _arrays; \
227
228 OE_ENGINE_SCENE_MATERIAL_GENERATE_PROPERTY(bool, bool)
229 OE_ENGINE_SCENE_MATERIAL_GENERATE_PROPERTY(int32_t, int32_t)
230 OE_ENGINE_SCENE_MATERIAL_GENERATE_PROPERTY(uint32_t, uint32_t)
231 OE_ENGINE_SCENE_MATERIAL_GENERATE_PROPERTY(float, float)
232 OE_ENGINE_SCENE_MATERIAL_GENERATE_PROPERTY(double, double)
233 OE_ENGINE_SCENE_MATERIAL_GENERATE_PROPERTY(glm::ivec2, ivec2)
234 OE_ENGINE_SCENE_MATERIAL_GENERATE_PROPERTY(glm::vec2, vec2)
235 OE_ENGINE_SCENE_MATERIAL_GENERATE_PROPERTY(glm::vec3, vec3)
236 OE_ENGINE_SCENE_MATERIAL_GENERATE_PROPERTY(glm::vec4, vec4)
237 OE_ENGINE_SCENE_MATERIAL_GENERATE_PROPERTY(glm::mat4, mat4)
238
239 #undef OE_ENGINE_SCENE_MATERIAL_GENERATE_PROPERTY
240 };
241
242 #define OE_ENGINE_SCENE_MATERIAL_GENERATE_SETTER(TYPE, PROPERTY) \
243 template <> inline Material* Material::setProperty(const std::string& name, const TYPE& value) \
244 { \
245 _prop_ ## PROPERTY[name] = value; \
246 return this; \
247 } \
248 template <> inline Material* Material::setArray(const std::string& name, const std::vector<TYPE>& value) \
249 { \
250 _prop_ ## PROPERTY ## _arrays[name] = value; \
251 return this; \
252 }
253
254 OE_ENGINE_SCENE_MATERIAL_GENERATE_SETTER(int32_t, int32_t)
255 OE_ENGINE_SCENE_MATERIAL_GENERATE_SETTER(uint32_t, uint32_t)
256 OE_ENGINE_SCENE_MATERIAL_GENERATE_SETTER(float, float)
257 OE_ENGINE_SCENE_MATERIAL_GENERATE_SETTER(double, double)
258 OE_ENGINE_SCENE_MATERIAL_GENERATE_SETTER(glm::ivec2, ivec2)
259 OE_ENGINE_SCENE_MATERIAL_GENERATE_SETTER(glm::vec2, vec2)
260 OE_ENGINE_SCENE_MATERIAL_GENERATE_SETTER(glm::vec3, vec3)
261 OE_ENGINE_SCENE_MATERIAL_GENERATE_SETTER(glm::vec4, vec4)
262 OE_ENGINE_SCENE_MATERIAL_GENERATE_SETTER(glm::mat4, mat4)
263
264 template <> inline Material* Material::setProperty(const std::string& name, const size_t& value)
265 {
266 return setProperty<int32_t>(name, value);
267 }
268
269 // Bool specialization, should be treated as an int
270 template <> inline Material* Material::setProperty(const std::string& name, const bool& value)
271 {
272 return setProperty<uint32_t>(name, value);
273 }
274
275 template <> inline Material* Material::setArray(const std::string& name, const std::vector<bool>& values)
276 {
277 std::vector<uint32_t> result(values.begin(), values.end());
278 return setArray<uint32_t>(name, result);
279 }
280
281 #undef OE_ENGINE_SCENE_MATERIAL_GENERATE_SETTER
282}
283
284#endif
Shader class.
Definition shader_base.h:32
Definition texture.h:31
Render agnostic material.
Definition material.h:90
TextureCoordinatesTransform texture_coordinates_1
Second texture coordinates transformation set.
Definition material.h:102
bool double_sided
Draws two sides of faces.
Definition material.h:119
Material * parent
Material source where properties/textures should be inherited from.
Definition material.h:146
uint32_t getNextAvailableTextureLayer(const uint32_t start=0) const
Get an available texture layer for this material.
bool inherit_properties
Check if Material properties should be inherited from parent Material.
Definition material.h:151
float alpha_threshold
Texture with alpha below this value will be considered completely transparent.
Definition material.h:141
TextureCoordinatesTransform texture_coordinates_0
First texture coordinates transformation set.
Definition material.h:97
Material * setProperty(const std::string &name, const T &value)=delete
Get all material textures.
uint32_t flags
General purpose user flags, may be used for collisions / sounds / etc...
Definition material.h:109
Material * setArray(const std::string &name, const std::vector< T > &value)=delete
Set a array of properties on a material.
oe::render::ShaderBase * shader
Shader to use to render this material.
Definition material.h:114
TransmissiveProperties transmissive_properties
Physically-based transmission properties.
Definition material.h:136
bool is_blend
This material need blending (transparency, effects, ...)
Definition material.h:131
bool invert_faces
If not double sided, draws back faces instead of front ones.
Definition material.h:124
bool inherit_textures
Check if Material textures should be inherited from parent Material.
Definition material.h:156
Render related abstractions (Shader, Framebuffer, Cubemaps, Textures)
Definition opengl.h:10
Scene related management (Render-agnostic Geometry, Manger, etc...)
Definition debug.h:19
Material property defining texture coordinates set transformation.
Definition material.h:41
glm::vec2 offset
Apply an offset to the texture UV.
Definition material.h:54
glm::vec2 tiling
Apply a tiling to the texture UV.
Definition material.h:48
Material property defining texture settings.
Definition material.h:21
std::string name
Texture uniform name.
Definition material.h:25
render::Texture * texture
Texture pointer.
Definition material.h:32
Material properties related to physically-based transparency related effects.
Definition material.h:63
float thickness
Thickness of the volume of the material between 0.0f (thin) and +Infinite (thick)
Definition material.h:78
float transmission
Percentage of light transmitted through the surface between 0.0f (opaque) and 1.0f (transparent)
Definition material.h:71