vsg 1.1.3
VulkanSceneGraph library
Loading...
Searching...
No Matches
material.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2018 Robert Osfield
6
7Permission 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:
8
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE 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.
12
13</editor-fold> */
14
15#include <vsg/core/Array.h>
16#include <vsg/core/Value.h>
17
18namespace vsg
19{
20
22 struct material
23 {
24 vec4 ambientColor;
25 vec4 diffuseColor;
26 vec4 specularColor;
27 float shininess{100.0f};
28
29 void read(vsg::Input& input)
30 {
31 input.read("ambientColor", ambientColor);
32 input.read("diffuseColor", diffuseColor);
33 input.read("specularColor", specularColor);
34 input.read("shininess", shininess);
35 }
36
37 void write(vsg::Output& output) const
38 {
39 output.write("ambientColor", ambientColor);
40 output.write("diffuseColor", diffuseColor);
41 output.write("specularColor", specularColor);
42 output.write("shininess", shininess);
43 }
44 };
45
46 template<>
47 constexpr bool has_read_write<material>() { return true; }
48
49 VSG_value(materialValue, material);
50 VSG_array(materialArray, material);
51
55 {
56 vec4 ambient{1.0f, 1.0f, 1.0f, 1.0f};
57 vec4 diffuse{0.9f, 0.9f, 0.9f, 1.0f};
58 vec4 specular{0.2f, 0.2f, 0.2f, 1.0f};
59 vec4 emissive{0.0f, 0.0f, 0.0f, 0.0f};
60 float shininess{100.0f};
61 float alphaMask{1.0f};
62 float alphaMaskCutoff{0.5f};
63
64 void read(vsg::Input& input)
65 {
66 input.read("ambient", ambient);
67 input.read("diffuse", diffuse);
68 input.read("specular", specular);
69 input.read("emissive", emissive);
70 input.read("shininess", shininess);
71 input.read("alphaMask", alphaMask);
72 input.read("alphaMaskCutoff", alphaMaskCutoff);
73 }
74
75 void write(vsg::Output& output) const
76 {
77 output.write("ambient", ambient);
78 output.write("diffuse", diffuse);
79 output.write("specular", specular);
80 output.write("emissive", emissive);
81 output.write("shininess", shininess);
82 output.write("alphaMask", alphaMask);
83 output.write("alphaMaskCutoff", alphaMaskCutoff);
84 }
85 };
86
87 template<>
88 constexpr bool has_read_write<PhongMaterial>() { return true; }
89
90 VSG_value(PhongMaterialValue, PhongMaterial);
91 VSG_array(PhongMaterialArray, PhongMaterial);
92
96 {
97 vec4 baseColorFactor{1.0f, 1.0f, 1.0f, 1.0f};
98 vec4 emissiveFactor{0.0f, 0.0f, 0.0f, 1.0f};
99 vec4 diffuseFactor{0.9f, 0.9f, 0.9f, 1.0f};
100 vec4 specularFactor{0.2f, 0.2f, 0.2f, 1.0f};
101 float metallicFactor{1.0f};
102 float roughnessFactor{1.0f};
103 float alphaMask{1.0f};
104 float alphaMaskCutoff{0.5f};
105
106 void read(vsg::Input& input)
107 {
108 input.read("baseColorFactor", baseColorFactor);
109 input.read("emissiveFactor", emissiveFactor);
110 input.read("diffuseFactor", diffuseFactor);
111 input.read("specularFactor", specularFactor);
112 input.read("metallicFactor", metallicFactor);
113 input.read("roughnessFactor", roughnessFactor);
114 input.read("alphaMask", alphaMask);
115 input.read("alphaMaskCutoff", alphaMaskCutoff);
116 }
117
118 void write(vsg::Output& output) const
119 {
120 output.write("baseColorFactor", baseColorFactor);
121 output.write("emissiveFactor", emissiveFactor);
122 output.write("diffuseFactor", diffuseFactor);
123 output.write("specularFactor", specularFactor);
124 output.write("metallicFactor", metallicFactor);
125 output.write("roughnessFactor", roughnessFactor);
126 output.write("alphaMask", alphaMask);
127 output.write("alphaMaskCutoff", alphaMaskCutoff);
128 }
129 };
130
131 template<>
132 constexpr bool has_read_write<PbrMaterial>() { return true; }
133
134 VSG_value(PbrMaterialValue, PbrMaterial);
135 VSG_array(PbrMaterialArray, PbrMaterial);
136
137} // namespace vsg
Definition Input.h:44
Definition Output.h:41
virtual void write(size_t num, const int8_t *value)=0
write contiguous array of value(s)
Definition material.h:96
Definition material.h:55
simple material struct for passing material settings as uniform value to fragment shader
Definition material.h:23