-
Notifications
You must be signed in to change notification settings - Fork 193
/
material.h
137 lines (113 loc) · 5.4 KB
/
material.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#pragma once
/* <editor-fold desc="MIT License">
Copyright(c) 2018 Robert Osfield
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
</editor-fold> */
#include <vsg/core/Array.h>
#include <vsg/core/Value.h>
namespace vsg
{
/// simple material struct for passing material settings as uniform value to fragment shader
struct material
{
vec4 ambientColor;
vec4 diffuseColor;
vec4 specularColor;
float shininess{100.0f};
void read(vsg::Input& input)
{
input.read("ambientColor", ambientColor);
input.read("diffuseColor", diffuseColor);
input.read("specularColor", specularColor);
input.read("shininess", shininess);
}
void write(vsg::Output& output) const
{
output.write("ambientColor", ambientColor);
output.write("diffuseColor", diffuseColor);
output.write("specularColor", specularColor);
output.write("shininess", shininess);
}
};
template<>
constexpr bool has_read_write<material>() { return true; }
VSG_value(materialValue, material);
VSG_array(materialArray, material);
/// PhongMaterial struct for passing material settings, suitable for phong lighting model, as uniform value to fragment shader
/// Used in conjunction with vsg::createPhongShaderSet().
struct PhongMaterial
{
vec4 ambient{1.0f, 1.0f, 1.0f, 1.0f};
vec4 diffuse{0.9f, 0.9f, 0.9f, 1.0f};
vec4 specular{0.2f, 0.2f, 0.2f, 1.0f};
vec4 emissive{0.0f, 0.0f, 0.0f, 0.0f};
float shininess{100.0f};
float alphaMask{1.0f};
float alphaMaskCutoff{0.5f};
void read(vsg::Input& input)
{
input.read("ambient", ambient);
input.read("diffuse", diffuse);
input.read("specular", specular);
input.read("emissive", emissive);
input.read("shininess", shininess);
input.read("alphaMask", alphaMask);
input.read("alphaMaskCutoff", alphaMaskCutoff);
}
void write(vsg::Output& output) const
{
output.write("ambient", ambient);
output.write("diffuse", diffuse);
output.write("specular", specular);
output.write("emissive", emissive);
output.write("shininess", shininess);
output.write("alphaMask", alphaMask);
output.write("alphaMaskCutoff", alphaMaskCutoff);
}
};
template<>
constexpr bool has_read_write<PhongMaterial>() { return true; }
VSG_value(PhongMaterialValue, PhongMaterial);
VSG_array(PhongMaterialArray, PhongMaterial);
/// PbrMaterial struct for passing material settings, suitable for PBR lighting model, as uniform value to fragment shader
/// Used in conjunction with vsg::createPhysicsBasedRenderingShaderSet().
struct PbrMaterial
{
vec4 baseColorFactor{1.0f, 1.0f, 1.0f, 1.0f};
vec4 emissiveFactor{0.0f, 0.0f, 0.0f, 1.0f};
vec4 diffuseFactor{0.9f, 0.9f, 0.9f, 1.0f};
vec4 specularFactor{0.2f, 0.2f, 0.2f, 1.0f};
float metallicFactor{1.0f};
float roughnessFactor{1.0f};
float alphaMask{1.0f};
float alphaMaskCutoff{0.5f};
void read(vsg::Input& input)
{
input.read("baseColorFactor", baseColorFactor);
input.read("emissiveFactor", emissiveFactor);
input.read("diffuseFactor", diffuseFactor);
input.read("specularFactor", specularFactor);
input.read("metallicFactor", metallicFactor);
input.read("roughnessFactor", roughnessFactor);
input.read("alphaMask", alphaMask);
input.read("alphaMaskCutoff", alphaMaskCutoff);
}
void write(vsg::Output& output) const
{
output.write("baseColorFactor", baseColorFactor);
output.write("emissiveFactor", emissiveFactor);
output.write("diffuseFactor", diffuseFactor);
output.write("specularFactor", specularFactor);
output.write("metallicFactor", metallicFactor);
output.write("roughnessFactor", roughnessFactor);
output.write("alphaMask", alphaMask);
output.write("alphaMaskCutoff", alphaMaskCutoff);
}
};
template<>
constexpr bool has_read_write<PbrMaterial>() { return true; }
VSG_value(PbrMaterialValue, PbrMaterial);
VSG_array(PbrMaterialArray, PbrMaterial);
} // namespace vsg