Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/*
Copyright (c) 2017 DIVIDE-Studio
Copyright (c) 2009 Ionut Cava

This file is part of DIVIDE Framework.

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.

*/

#ifndef _MATERIAL_INL_
#define _MATERIAL_INL_

namespace Divide {

inline void Material::setColourData(const ColourData& other) {
    _dirty = true;
    _colourData = other;
    _translucencyCheck = true;
}

inline void Material::setDiffuse(const vec4<F32>& value) {
    _dirty = true;
    _colourData._diffuse = value;
    if (value.a < 0.95f) {
        _translucencyCheck = true;
    }
}

inline void Material::setSpecular(const vec4<F32>& value) {
    _dirty = true;
    _colourData._specular = value;
}

inline void Material::setEmissive(const vec3<F32>& value) {
    _dirty = true;
    _colourData._emissive = value;
}

inline void Material::setHardwareSkinning(const bool state) {
    _dirty = true;
    _hardwareSkinning = state;
}

inline void Material::setOpacity(F32 value) {
    _dirty = true;
    _colourData._diffuse.a = value;
    _translucencyCheck = true;
}

inline void Material::setShininess(F32 value) {
    _dirty = true;
    _colourData._shininess = value;
}

// Should the shaders be computed on add? Should reflections be always parsed? Etc
inline void Material::setHighPriority(const bool state) {
    _highPriority = state;
}

inline void Material::addShaderModifier(const RenderStagePass& renderStagePass, const stringImpl& shaderModifier) {
    _shaderModifier[renderStagePass.index()] = shaderModifier;
}

inline void Material::addShaderModifier(const stringImpl& shaderModifier) {
    for (RenderStagePass::PassIndex i = 0; i < RenderStagePass::count(); ++i) {
        addShaderModifier(RenderStagePass::stagePass(i), shaderModifier);
    }
}

inline void Material::setShaderDefines(RenderPassType passType, const stringImpl& shaderDefines) {
    for (U8 i = 0; i < to_U8(RenderStage::COUNT); ++i) {
        setShaderDefines(RenderStagePass(static_cast<RenderStage>(i), passType), shaderDefines);
    }
}

inline void Material::setShaderDefines(RenderStage renderStage, const stringImpl& shaderDefines) {
    for (U8 i = 0; i < to_U8(RenderPassType::COUNT); ++i) {
        setShaderDefines(RenderStagePass(renderStage, static_cast<RenderPassType>(i)), shaderDefines);
    }
}

inline void Material::setShaderDefines(const RenderStagePass& renderStagePass, const stringImpl& shaderDefines) {
    vectorImpl<stringImpl>& defines = shaderInfo(renderStagePass)._shaderDefines;
    if (std::find(std::cbegin(defines), std::cend(defines), shaderDefines) == std::cend(defines)) {
        defines.push_back(shaderDefines);
    }
}

inline void Material::setShaderDefines(const stringImpl& shaderDefines) {
    for (RenderStagePass::PassIndex i = 0; i < RenderStagePass::count(); ++i) {
        setShaderDefines(RenderStagePass::stagePass(i), shaderDefines);
    }
}

/// toggle multi-threaded shader loading on or off for this material
inline void Material::setShaderLoadThreaded(const bool state) {
    _shaderThreadedLoad = state;
}

inline void Material::setShaderProgram(const stringImpl& shader,
                                       const bool computeOnAdd) {
    for (RenderStagePass::PassIndex i = 0; i < RenderStagePass::count(); ++i) {
        setShaderProgram(shader, RenderStagePass::stagePass(i), computeOnAdd);
    }
}

inline void Material::setShaderProgram(const ShaderProgram_ptr& shader) {
    for (RenderStagePass::PassIndex i = 0; i < RenderStagePass::count(); ++i) {
        setShaderProgram(shader, RenderStagePass::stagePass(i));
    }
}

inline void Material::setRenderStateBlock(size_t renderStateBlockHash,
                                          I32 variant) {
    for (RenderStagePass::PassIndex i = 0; i < RenderStagePass::count(); ++i) {
        setRenderStateBlock(renderStateBlockHash, RenderStagePass::stagePass(i), variant);
    }
}

inline void Material::setRenderStateBlock(size_t renderStateBlockHash,
                                          RenderStage renderStage,
                                          I32 variant) {
    for (U8 pass = 0; pass < to_base(RenderPassType::COUNT); ++pass) {
        RenderStagePass renderStagePass(renderStage, static_cast<RenderPassType>(pass));

        if (variant < 0 || variant >= defaultRenderStates(renderStagePass).size()) {
            for (size_t& state : defaultRenderStates(renderStagePass)) {
                state = renderStateBlockHash;
            }
        } else {
            defaultRenderStates(renderStagePass)[variant] = renderStateBlockHash;
        }
    }
}

inline void Material::setRenderStateBlock(size_t renderStateBlockHash,
                                          RenderPassType renderPassType,
                                          I32 variant) {
    for (U8 stage = 0; stage < to_base(RenderStage::COUNT); ++stage) {
        RenderStagePass renderStagePass(static_cast<RenderStage>(stage), renderPassType);

        if (variant < 0 || variant >= defaultRenderStates(renderStagePass).size()) {
            for (size_t& state : defaultRenderStates(renderStagePass)) {
                state = renderStateBlockHash;
            }
        } else {
            defaultRenderStates(renderStagePass)[variant] = renderStateBlockHash;
        }
    }
}

inline void Material::setRenderStateBlock(size_t renderStateBlockHash,
                                          const RenderStagePass& renderStagePass,
                                          I32 variant) {
    if (variant < 0 || variant >= defaultRenderStates(renderStagePass).size()) {
        for (size_t& state : defaultRenderStates(renderStagePass)) {
            state = renderStateBlockHash;
        }
    } else {
        defaultRenderStates(renderStagePass)[variant] = renderStateBlockHash;
    }
}

inline size_t Material::getRenderStateBlock(const RenderStagePass& renderStagePass, I32 variant) {
    const std::array<size_t, 3>& states = defaultRenderStates(renderStagePass);

    assert(variant >= 0 && variant < 3);
    return states[variant];
}

inline void Material::setParallaxFactor(F32 factor) {
    _parallaxFactor = std::min(0.01f, factor);
}

inline F32 Material::getParallaxFactor() const {
    return _parallaxFactor;
}

/// Add a texture <-> bind slot pair to be bound with the default textures
/// on each "bindTexture" call
inline void Material::addExternalTexture(const Texture_ptr& texture, U8 slot, bool activeForDepth) {
    // custom textures are not material dependencies!
    _externalTextures.push_back(ExternalTexture { texture, slot, activeForDepth });
}

inline std::weak_ptr<Texture> Material::getTexture(ShaderProgram::TextureUsage textureUsage) const {
    return _textures[to_U32(textureUsage)];
}

inline const Material::TextureOperation& Material::getTextureOperation() const {
    return _operation;
}

inline const Material::ColourData&  Material::getColourData()  const {
    return _colourData;
}

inline const Material::ShadingMode& Material::getShadingMode() const {
    return _shadingMode;
}

inline const Material::BumpMethod&  Material::getBumpMethod()  const {
    return _bumpMethod;
}

inline bool Material::hasTranslucency() const {
    return _translucencyType != TranslucencyType::FULL_TRANSPARENT;
}

inline bool Material::hasTransparency() const {
    return _translucencySource != TranslucencySource::COUNT;
}

inline void Material::dumpToFile(bool state) {
    _dumpToFile = state;
}

inline bool Material::isDirty() const {
    return _dirty;
}

inline bool Material::isDoubleSided() const {
    return _doubleSided;
}

inline U32 Material::defaultReflectionTextureIndex() const {
    return _reflectionIndex > -1 ? to_U32(_reflectionIndex)
                                 : _defaultReflection.second;
}

inline U32 Material::defaultRefractionTextureIndex() const {
    return _refractionIndex > -1 ? to_U32(_refractionIndex)
                                 : _defaultRefraction.second;
}

inline bool Material::isExternalTexture(ShaderProgram::TextureUsage slot) const {
    return _textureExtenalFlag[to_U32(slot)];
}

inline void Material::setBumpMethod(const BumpMethod& newBumpMethod) {
    _bumpMethod = newBumpMethod;
    recomputeShaders();
}

inline void Material::setShadingMode(const ShadingMode& mode) {
    _shadingMode = mode;
    recomputeShaders();
}

inline ShaderProgramInfo& Material::getShaderInfo(const RenderStagePass& renderStagePass) {
    return shaderInfo(renderStagePass);
}

inline ShaderProgramInfo& Material::shaderInfo(const RenderStagePass& renderStagePass) {
    return _shaderInfo[renderStagePass.index()];
}

inline const ShaderProgramInfo& Material::shaderInfo(const RenderStagePass& renderStagePass) const {
    return _shaderInfo[renderStagePass.index()];
}

// Here we set the shader's name
inline void Material::setShaderProgram(const stringImpl& shader,
                                       const RenderStagePass& renderStagePass,
                                       const bool computeOnAdd) {
    shaderInfo(renderStagePass)._customShader = true;
    setShaderProgramInternal(shader, renderStagePass, computeOnAdd);
}

inline void Material::setShaderProgram(const ShaderProgram_ptr& shader,
                                       const RenderStagePass& renderStagePass) {
    shaderInfo(renderStagePass)._customShader = true;
    setShaderProgramInternal(shader, renderStagePass);
}

inline void Material::setShaderProgram(const stringImpl& shader,
                                       RenderStage stage,
                                       const bool computeOnAdd) {
    for (U8 pass = 0; pass < to_base(RenderPassType::COUNT); ++pass) {
        setShaderProgram(shader, RenderStagePass(stage, static_cast<RenderPassType>(pass)), computeOnAdd);
    }
}

inline void Material::setShaderProgram(const ShaderProgram_ptr& shader,
                                       RenderStage stage) {
    for (U8 pass = 0; pass < to_base(RenderPassType::COUNT); ++pass) {
        setShaderProgram(shader, RenderStagePass(stage, static_cast<RenderPassType>(pass)));
    }
}

inline void Material::setShaderProgram(const stringImpl& shader,
                                       RenderPassType passType,
                                       const bool computeOnAdd) {
    for (U8 stage = 0; stage < to_base(RenderStage::COUNT); ++stage) {
        setShaderProgram(shader, RenderStagePass(static_cast<RenderStage>(stage), passType), computeOnAdd);
    }
}

inline void Material::setShaderProgram(const ShaderProgram_ptr& shader,
                                       RenderPassType passType) {
    for (U8 stage = 0; stage < to_base(RenderStage::COUNT); ++stage) {
        setShaderProgram(shader, RenderStagePass(static_cast<RenderStage>(stage), passType));
    }
}

inline std::array<size_t, 3>& Material::defaultRenderStates(const RenderStagePass& renderStagePass) {
    return _defaultRenderStates[renderStagePass.index()];
}

}; //namespace Divide

#endif //_MATERIAL_INL_

Commits for Divide-Framework/trunk/Source Code/Geometry/Material/Headers/Material.inl

Diff revisions: vs.
Revision Author Commited Message
926 Diff Diff IonutCava picture IonutCava Fri 04 Aug, 2017 14:06:17 +0000

[Ionut]
- Rename material custom textures to external textures and make sure we properly provide all needed textures for depth stages

913 Diff Diff IonutCava picture IonutCava Thu 06 Jul, 2017 15:57:35 +0000

[Ionut]
- All shaders that are assigned to a material should have SHADOW_PASS defined for shadow shaders and DEPTH_PASS for all depth pass shaders.
- Add a helper function to map a value from one range to another

905 Diff Diff IonutCava picture IonutCava Mon 26 Jun, 2017 15:56:21 +0000

[Ionut]
Untested code

- Rework RenderBin/RenderPass/RenderQueue system to allow per-bin type rendering decision
— Added to allow implementation of Weighted, Blended Order-Independent Transparency later on
- Better detection of transparency and translucency in textures and materials. Used to separate Alpha-Discard based geometry from OIT translucent geometry

895 Diff Diff IonutCava picture IonutCava Wed 21 Jun, 2017 21:10:26 +0000

[IonutCava]
- Reorder and cleanup OpenGL backend a bit.
- Small code cleanup
- Some small profile-guided optimizations

890 Diff Diff IonutCava picture IonutCava Sun 14 May, 2017 20:54:59 +0000

[Ionut]
- Add pre-compiled header support
- Initial code for per-stage tessellation computation

875 IonutCava picture IonutCava Tue 14 Mar, 2017 16:59:38 +0000

[IonutCava]
- Cleanup and optimizations