Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
MaterialProperties.cpp
Go to the documentation of this file.
1
2#include "Headers/Material.h"
3
4namespace Divide {
5
6void Material::Properties::doubleSided(const bool state) noexcept {
7 if (_doubleSided != state) {
8 _doubleSided = state;
9 _cullUpdated = true;
10 }
11}
12
13void Material::Properties::isRefractive(const bool state) noexcept {
14 if (_isRefractive != state) {
15 _isRefractive = state;
16 _needsNewShader = true;
17 }
18}
19
20void Material::Properties::receivesShadows(const bool state) noexcept {
21 if (_receivesShadows != state) {
22 _receivesShadows = state;
23 _needsNewShader = true;
24 }
25}
26
27void Material::Properties::isStatic(const bool state) noexcept {
28 if (_isStatic != state) {
29 _isStatic = state;
30 _needsNewShader = true;
31 }
32}
33
34void Material::Properties::isInstanced(const bool state) noexcept {
35 if (_isInstanced != state) {
36 _isInstanced = state;
37 _needsNewShader = true;
38 }
39}
40
41void Material::Properties::ignoreTexDiffuseAlpha(const bool state) noexcept {
42 if (overrides()._ignoreTexDiffuseAlpha != state) {
43 overrides()._ignoreTexDiffuseAlpha = state;
44 _needsNewShader = true;
45 }
46}
47
48void Material::Properties::hardwareSkinning(const bool state) noexcept {
49 if (_hardwareSkinning != state) {
50 _hardwareSkinning = state;
51 _needsNewShader = true;
52 }
53}
54
56 if (_texturesInFragmentStageOnly != state) {
57 _texturesInFragmentStageOnly = state;
58 _needsNewShader = true;
59 }
60}
61
62void Material::Properties::toggleTransparency(const bool state) noexcept {
63 if (overrides()._transparencyEnabled != state) {
64 overrides()._transparencyEnabled = state;
65 _transparencyUpdated = true;
66 }
67}
68
69void Material::Properties::useAlphaDiscard(const bool state) noexcept {
70 if (overrides()._useAlphaDiscard != state) {
71 overrides()._useAlphaDiscard = state;
72 _needsNewShader = true;
73 }
74}
75
76void Material::Properties::baseColour(const FColour4& colour) noexcept {
77 _baseColour = colour;
78 _transparencyUpdated = true;
79}
80
81void Material::Properties::bumpMethod(const BumpMethod newBumpMethod) noexcept {
82 if (_bumpMethod != newBumpMethod) {
83 _bumpMethod = newBumpMethod;
84 _needsNewShader = true;
85 }
86}
87
89 if (_shadingMode != mode) {
90 _shadingMode = mode;
91 _needsNewShader = true;
92 }
93}
94
95void Material::Properties::saveToXML(const std::string& entryName, boost::property_tree::ptree& pt) const {
96 pt.put(entryName + ".shadingMode", TypeUtil::ShadingModeToString(shadingMode()));
97
98 pt.put(entryName + ".colour.<xmlattr>.r", baseColour().r);
99 pt.put(entryName + ".colour.<xmlattr>.g", baseColour().g);
100 pt.put(entryName + ".colour.<xmlattr>.b", baseColour().b);
101 pt.put(entryName + ".colour.<xmlattr>.a", baseColour().a);
102
103 pt.put(entryName + ".emissive.<xmlattr>.r", emissive().r);
104 pt.put(entryName + ".emissive.<xmlattr>.g", emissive().g);
105 pt.put(entryName + ".emissive.<xmlattr>.b", emissive().b);
106
107 pt.put(entryName + ".ambient.<xmlattr>.r", ambient().r);
108 pt.put(entryName + ".ambient.<xmlattr>.g", ambient().g);
109 pt.put(entryName + ".ambient.<xmlattr>.b", ambient().b);
110
111 pt.put(entryName + ".specular.<xmlattr>.r", specular().r);
112 pt.put(entryName + ".specular.<xmlattr>.g", specular().g);
113 pt.put(entryName + ".specular.<xmlattr>.b", specular().b);
114 pt.put(entryName + ".specular.<xmlattr>.a", shininess());
115
116 pt.put(entryName + ".specular_factor", specGloss().x);
117 pt.put(entryName + ".glossiness_factor", specGloss().y);
118
119 pt.put(entryName + ".metallic", metallic());
120
121 pt.put(entryName + ".roughness", roughness());
122
123 pt.put(entryName + ".doubleSided", doubleSided());
124
125 pt.put(entryName + ".receivesShadows", receivesShadows());
126
127 pt.put(entryName + ".ignoreTexDiffuseAlpha", overrides().ignoreTexDiffuseAlpha());
128
129 pt.put(entryName + ".bumpMethod", TypeUtil::BumpMethodToString(bumpMethod()));
130
131 pt.put(entryName + ".parallaxFactor", parallaxFactor());
132
133 pt.put(entryName + ".transparencyEnabled", overrides().transparencyEnabled());
134
135 pt.put(entryName + ".useAlphaDiscard", overrides().useAlphaDiscard());
136
137 pt.put(entryName + ".isRefractive", isRefractive());
138}
139
140void Material::Properties::loadFromXML(const std::string& entryName, const boost::property_tree::ptree& pt)
141{
142 const ShadingMode shadingModeCrt = shadingMode();
143 ShadingMode shadingModeFile = TypeUtil::StringToShadingMode(pt.get<std::string>(entryName + ".shadingMode", TypeUtil::ShadingModeToString(shadingModeCrt)));
144 if (shadingModeFile == ShadingMode::COUNT)
145 {
146 shadingModeFile = shadingModeCrt;
147 }
148
149 shadingMode(shadingModeFile);
150
151 baseColour(FColour4(pt.get<F32>(entryName + ".colour.<xmlattr>.r", baseColour().r),
152 pt.get<F32>(entryName + ".colour.<xmlattr>.g", baseColour().g),
153 pt.get<F32>(entryName + ".colour.<xmlattr>.b", baseColour().b),
154 pt.get<F32>(entryName + ".colour.<xmlattr>.a", baseColour().a)));
155
156 emissive(FColour3(pt.get<F32>(entryName + ".emissive.<xmlattr>.r", emissive().r),
157 pt.get<F32>(entryName + ".emissive.<xmlattr>.g", emissive().g),
158 pt.get<F32>(entryName + ".emissive.<xmlattr>.b", emissive().b)));
159
160 ambient(FColour3(pt.get<F32>(entryName + ".ambient.<xmlattr>.r", ambient().r),
161 pt.get<F32>(entryName + ".ambient.<xmlattr>.g", ambient().g),
162 pt.get<F32>(entryName + ".ambient.<xmlattr>.b", ambient().b)));
163
164 specular(FColour3(pt.get<F32>(entryName + ".specular.<xmlattr>.r", specular().r),
165 pt.get<F32>(entryName + ".specular.<xmlattr>.g", specular().g),
166 pt.get<F32>(entryName + ".specular.<xmlattr>.b", specular().b)));
167
168 shininess(pt.get<F32>(entryName + ".specular.<xmlattr>.a", shininess()));
169
170 specGloss(SpecularGlossiness(pt.get<F32>(entryName + ".specular_factor", specGloss().x),
171 pt.get<F32>(entryName + ".glossiness_factor", specGloss().y)));
172
173 metallic(pt.get<F32>(entryName + ".metallic", metallic()));
174
175 roughness(pt.get<F32>(entryName + ".roughness", roughness()));
176
177 parallaxFactor(pt.get<F32>(entryName + ".parallaxFactor", parallaxFactor()));
178
179 receivesShadows(pt.get<bool>(entryName + ".receivesShadows", receivesShadows()));
180
181 ignoreTexDiffuseAlpha(pt.get<bool>(entryName + ".ignoreTexDiffuseAlpha", overrides().ignoreTexDiffuseAlpha()));
182
183 bumpMethod(TypeUtil::StringToBumpMethod(pt.get<std::string>(entryName + ".bumpMethod", TypeUtil::BumpMethodToString(bumpMethod()))));
184
185 toggleTransparency(pt.get<bool>(entryName + ".transparencyEnabled", overrides().transparencyEnabled()));
186
187 useAlphaDiscard(pt.get<bool>(entryName + ".useAlphaDiscard", overrides().useAlphaDiscard()));
188
189 isRefractive(pt.get<bool>(entryName + ".isRefractive", isRefractive()));
190
191 doubleSided(pt.get<bool>(entryName + ".doubleSided", doubleSided()));
192 {
193 //Clear this flag when loading from XML as it will conflict with our custom RenderStateBlock when loading it from XML!!
194 //doubleSided calls set this flag to true thus invalidating our recently loaded render state.
195 cullUpdated(false);
196 }
197}
198
199} //namespace Divide
vec2< F32 > SpecularGlossiness
Definition: Material.h:131
bool isRefractive() const noexcept
Definition: Material.inl:86
BumpMethod StringToBumpMethod(std::string_view name)
Definition: Material.cpp:69
const char * BumpMethodToString(BumpMethod bumpMethod) noexcept
Definition: Material.cpp:64
const char * ShadingModeToString(ShadingMode shadingMode) noexcept
Definition: Material.cpp:82
ShadingMode StringToShadingMode(std::string_view name)
Definition: Material.cpp:87
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
vec4< F32 > FColour4
Definition: MathHelper.h:73
vec3< F32 > FColour3
Definition: MathHelper.h:70
void receivesShadows(bool state) noexcept
void doubleSided(bool state) noexcept
void isRefractive(bool state) noexcept
void texturesInFragmentStageOnly(bool state) noexcept
void isInstanced(bool state) noexcept
void bumpMethod(BumpMethod newBumpMethod) noexcept
void ignoreTexDiffuseAlpha(bool state) noexcept
void hardwareSkinning(bool state) noexcept
void baseColour(const FColour4 &colour) noexcept
void saveToXML(const std::string &entryName, boost::property_tree::ptree &pt) const
void isStatic(bool state) noexcept
void loadFromXML(const std::string &entryName, const boost::property_tree::ptree &pt)
void toggleTransparency(bool state) noexcept
void shadingMode(ShadingMode mode) noexcept
void useAlphaDiscard(bool state) noexcept