Unravel Engine C++ Reference
Loading...
Searching...
No Matches
material.h
Go to the documentation of this file.
1#pragma once
2#include <engine/engine_export.h>
3
4#include "gpu_program.h"
6
7#include <graphics/graphics.h>
8#include <math/math.h>
11
12
13namespace unravel
14{
15
20enum class cull_type : std::uint32_t
21{
22 none,
23 clockwise,
25};
26
31class material : public crtp_meta_type<material>
32{
33public:
35
36 using sptr = std::shared_ptr<material>;
37 using wptr = std::weak_ptr<material>;
38 using uptr = std::unique_ptr<material>;
39
40 material() = default;
41 virtual ~material() = default;
42
43
48 virtual auto submit(gpu_program* program) const -> bool;
49
54 auto get_cull_type() const -> cull_type;
55
60 void set_cull_type(cull_type val);
61
69 virtual auto get_render_states(bool apply_cull = true, bool depth_write = true, bool depth_test = true) const
70 -> uint64_t;
71
76 static auto default_color_map() -> asset_handle<gfx::texture>&;
77
82 static auto default_normal_map() -> asset_handle<gfx::texture>&;
83
88 virtual auto clone() const -> material::sptr;
89
90protected:
93};
94
100{
101public:
103
104 auto clone() const -> std::shared_ptr<material> override;
105
110 auto get_base_color() const -> const math::color&
111 {
112 return base_color_;
113 }
114
120 {
121 base_color_ = val;
122 }
123
128 auto get_subsurface_color() const -> const math::color&
129 {
130 return subsurface_color_;
131 }
132
138 {
139 subsurface_color_ = val;
140 }
141
146 auto get_emissive_color() const -> const math::color&
147 {
148 return emissive_color_;
149 }
150
156 {
157 emissive_color_ = val;
158 }
159
164 auto get_roughness() const -> float
165 {
166 return surface_data_.x;
167 }
168
173 void set_roughness(float roughness)
174 {
175 surface_data_.x = roughness;
176 }
177
182 auto get_metalness() const -> float
183 {
184 return surface_data_.y;
185 }
186
191 void set_metalness(float metalness)
192 {
193 surface_data_.y = metalness;
194 }
195
200 auto get_bumpiness() const -> float
201 {
202 return surface_data_.z;
203 }
204
209 void set_bumpiness(float bumpiness)
210 {
211 surface_data_.z = bumpiness;
212 }
213
218 auto get_alpha_test_value() const -> float
219 {
220 return surface_data_.w;
221 }
222
227 void set_alpha_test_value(float alpha_test_value)
228 {
229 surface_data_.w = alpha_test_value;
230 }
231
236 auto get_surface_data() const -> const math::vec4&
237 {
238 return surface_data_;
239 }
240
245 auto get_surface_data2() const -> math::vec4
246 {
247 math::vec4 surface_data2{};
248
249 surface_data2[0] = metalness_roughness_combined() ? 1.0f : 0.0f;
250
251 return surface_data2;
252 }
253
254 auto metalness_roughness_combined() const -> bool
255 {
256 return metalness_map_ == roughness_map_;
257 }
258
263 auto get_tiling() const -> const math::vec2&
264 {
265 return tiling_;
266 }
267
272 void set_tiling(const math::vec2& tiling)
273 {
274 tiling_ = tiling;
275 }
276
281 auto get_dither_threshold() const -> const math::vec2&
282 {
283 return dither_threshold_;
284 }
285
290 void set_dither_threshold(const math::vec2& threshold)
291 {
292 dither_threshold_ = threshold;
293 }
294
299 auto get_color_map() const -> const asset_handle<gfx::texture>&
300 {
301 return color_map_;
302 }
303
309 {
310 color_map_ = val;
311 }
312
317 auto get_normal_map() const -> const asset_handle<gfx::texture>&
318 {
319 return normal_map_;
320 }
321
327 {
328 normal_map_ = val;
329 }
330
335 auto get_roughness_map() const -> const asset_handle<gfx::texture>&
336 {
337 return roughness_map_;
338 }
339
345 {
346 roughness_map_ = val;
347 }
348
353 auto get_metalness_map() const -> const asset_handle<gfx::texture>&
354 {
355 return metalness_map_;
356 }
357
363 {
364 metalness_map_ = val;
365 }
366
371 auto get_ao_map() const -> const asset_handle<gfx::texture>&
372 {
373 return ao_map_;
374 }
375
381 {
382 ao_map_ = val;
383 }
384
389 auto get_emissive_map() const -> const asset_handle<gfx::texture>&
390 {
391 return emissive_map_;
392 }
393
399 {
400 emissive_map_ = val;
401 }
402
403private:
405 math::color base_color_{
406 1.0f,
407 1.0f,
408 1.0f,
409 1.0f
410 };
412 math::color subsurface_color_{
413 0.0f,
414 0.0f,
415 0.0f,
416 0.8f
417 };
419 math::color emissive_color_{
420 0.0f,
421 0.0f,
422 0.0f,
423 0.0f
424 };
426 math::vec4 surface_data_{
427 0.3f,
428 0.0f,
429 1.0f,
430 0.25f
431 };
433 math::vec2 tiling_{
434 1.0f,
435 1.0f
436 };
438 math::vec2 dither_threshold_{
439 0.5f,
440 0.0f
441 };
442
445 asset_handle<gfx::texture> normal_map_;
446 asset_handle<gfx::texture> roughness_map_;
447 asset_handle<gfx::texture> metalness_map_;
448 asset_handle<gfx::texture> emissive_map_;
450};
451
452} // namespace unravel
Class representing a GPU program.
Definition gpu_program.h:17
Base class for materials used in rendering.
Definition material.h:32
static auto default_normal_map() -> asset_handle< gfx::texture > &
Gets the default normal map.
Definition material.cpp:21
static auto default_color_map() -> asset_handle< gfx::texture > &
Gets the default color map.
Definition material.cpp:15
std::weak_ptr< material > wptr
Definition material.h:37
std::shared_ptr< material > sptr
Definition material.h:36
void set_cull_type(cull_type val)
Sets the culling type of the material.
Definition material.cpp:37
virtual auto submit(gpu_program *program) const -> bool
Submits the material properties to the GPU program.
Definition material.cpp:27
virtual auto get_render_states(bool apply_cull=true, bool depth_write=true, bool depth_test=true) const -> uint64_t
Gets the render states for the material.
Definition material.cpp:42
cull_type cull_type_
< The culling type for this material.
Definition material.h:92
std::unique_ptr< material > uptr
Definition material.h:38
auto get_cull_type() const -> cull_type
Gets the culling type of the material.
Definition material.cpp:32
virtual auto clone() const -> material::sptr
Clones a materiial.
Definition material.cpp:9
Class for physically-based rendering (PBR) materials.
Definition material.h:100
auto get_surface_data2() const -> math::vec4
Gets additional surface data for the material.
Definition material.h:245
auto get_dither_threshold() const -> const math::vec2 &
Gets the dither threshold of the material.
Definition material.h:281
auto get_emissive_map() const -> const asset_handle< gfx::texture > &
Gets the emissive map of the material.
Definition material.h:389
void set_subsurface_color(const math::color &val)
Sets the subsurface color of the material.
Definition material.h:137
void set_roughness_map(const asset_handle< gfx::texture > &val)
Sets the roughness map of the material.
Definition material.h:344
void set_base_color(const math::color &val)
Sets the base color of the material.
Definition material.h:119
auto metalness_roughness_combined() const -> bool
Definition material.h:254
auto get_subsurface_color() const -> const math::color &
Gets the subsurface color of the material.
Definition material.h:128
void set_color_map(const asset_handle< gfx::texture > &val)
Sets the color map of the material.
Definition material.h:308
void set_ao_map(const asset_handle< gfx::texture > &val)
Sets the ambient occlusion map of the material.
Definition material.h:380
auto get_color_map() const -> const asset_handle< gfx::texture > &
Gets the color map of the material.
Definition material.h:299
auto get_alpha_test_value() const -> float
Gets the alpha test value of the material.
Definition material.h:218
auto get_bumpiness() const -> float
Gets the bumpiness of the material.
Definition material.h:200
auto get_roughness() const -> float
Gets the roughness of the material.
Definition material.h:164
auto get_metalness() const -> float
Gets the metalness of the material.
Definition material.h:182
void set_dither_threshold(const math::vec2 &threshold)
Sets the dither threshold of the material.
Definition material.h:290
auto get_surface_data() const -> const math::vec4 &
Gets the surface data of the material.
Definition material.h:236
void set_bumpiness(float bumpiness)
Sets the bumpiness of the material.
Definition material.h:209
void set_emissive_map(const asset_handle< gfx::texture > &val)
Sets the emissive map of the material.
Definition material.h:398
void set_normal_map(const asset_handle< gfx::texture > &val)
Sets the normal map of the material.
Definition material.h:326
auto get_roughness_map() const -> const asset_handle< gfx::texture > &
Gets the roughness map of the material.
Definition material.h:335
void set_emissive_color(const math::color &val)
Sets the emissive color of the material.
Definition material.h:155
auto get_metalness_map() const -> const asset_handle< gfx::texture > &
Gets the metalness map of the material.
Definition material.h:353
auto get_tiling() const -> const math::vec2 &
Gets the tiling factor of the material.
Definition material.h:263
void set_alpha_test_value(float alpha_test_value)
Sets the alpha test value of the material.
Definition material.h:227
auto get_normal_map() const -> const asset_handle< gfx::texture > &
Gets the normal map of the material.
Definition material.h:317
void set_metalness_map(const asset_handle< gfx::texture > &val)
Sets the metalness map of the material.
Definition material.h:362
void set_tiling(const math::vec2 &tiling)
Sets the tiling factor of the material.
Definition material.h:272
void set_roughness(float roughness)
Sets the roughness of the material.
Definition material.h:173
void set_metalness(float metalness)
Sets the metalness of the material.
Definition material.h:191
auto get_base_color() const -> const math::color &
Gets the base color of the material.
Definition material.h:110
auto get_emissive_color() const -> const math::color &
Gets the emissive color of the material.
Definition material.h:146
auto get_ao_map() const -> const asset_handle< gfx::texture > &
Gets the ambient occlusion map of the material.
Definition material.h:371
Definition bbox.cpp:5
cull_type
Enum representing the type of culling to be used.
Definition material.h:21
@ counter_clockwise
Cull counter-clockwise faces.
@ clockwise
Cull clockwise faces.
#define SERIALIZABLE(T)
Represents a handle to an asset, providing access and management functions.