MOS
material.hpp
1 #pragma once
2 
3 #include <mos/gfx/material.hpp>
4 #include <mos/gpu/resource.hpp>
5 #include <mos/gpu/texture_2d.hpp>
6 
7 namespace mos::gpu {
8 
9 /* Material living on the GPU */
10 class Material {
11  friend class mos::gfx::Renderer;
12  friend class Model;
13 public:
14  template<class T>
15  struct Pair {
16  explicit Pair(const mos::gfx::Material::Slot<T> slot): value(slot.value) , texture(slot.texture){}
17  explicit Pair(const T &value) : value(value) {}
18  explicit Pair(const Texture_2D &texture) : texture(texture) {}
19  Pair(const T &value, const Texture_2D &texture) : value(value), texture(texture) {}
20  T value = T();
21  Texture_2D texture = Texture_2D();
22  };
23 
24  struct Normal {
25  Normal() = default;
26  Normal(const mos::gfx::Material::Normal &normal) : texture(normal.texture){}
27  Texture_2D texture = Texture_2D();
28  };
29 
30  using Albedo = Pair<glm::vec3>;
31  using Roughness = Pair<float>;
32  using Metallic = Pair<float>;
33  using Emission = Pair<glm::vec3>;
35 
36  Material() = default;
37 
38  auto albedo() const -> const Albedo&;
39  auto metallic() const -> const Metallic&;
40  auto roughness() const -> const Roughness&;
41  auto emission() const -> const Emission&;
42  auto ambient_occlusion() const -> const Ambient_occlusion&;
43  auto normal() const -> const Normal&;
44 
45  auto alpha() const -> const float&;
46  auto index_of_refraction() const -> const float&;
47  auto transmission() const -> const float&;
48 
49 private:
50  Material(const mos::gfx::Material &material);
51 
52  Albedo albedo_{glm::vec3(0.0f)};
53  Metallic metallic_{0.0f};
54  Roughness roughness_{1.0f};
55  Emission emission_{glm::vec3(0.0f)};
56  Ambient_occlusion ambient_occlusion_{1.0f};
57  Normal normal_{};
58 
59  float alpha_{1.0f};
60  float index_of_refraction_{1.5f};
61  float transmission_{0.0f};
62 };
63 }
64 
Definition: material.hpp:24
Physically based material.
Definition: material.hpp:12
Definition: model.hpp:20
Definition: material.hpp:14
Definition: material.hpp:15
Definition: texture_2d.hpp:8
Definition: material.hpp:7
Definition: material.hpp:23
Definition: material.hpp:10