Skip to content

Commit 1470856

Browse files
committed
Broken build.
* Incorporating std variant into pbrmaterial to help with alphamask variations.
1 parent d7abada commit 1470856

5 files changed

Lines changed: 52 additions & 8 deletions

File tree

MP-APS/.vs/MP-APS/v15/.suo

0 Bytes
Binary file not shown.

MP-APS/.vs/MP-APS/v15/Browse.VC.db

176 KB
Binary file not shown.

MP-APS/Core/RenderSystem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ void RenderSystem::renderModelsWithTextures(GLShaderProgram& shader, const std::
228228
glBindTexture(GL_TEXTURE_2D, mesh.Material->GetParameterTexture(PBRMaterial::METALLIC));
229229
glActiveTexture(GL_TEXTURE6);
230230
glBindTexture(GL_TEXTURE_2D, mesh.Material->GetParameterTexture(PBRMaterial::ROUGHNESS));
231+
231232
//glActiveTexture(GL_TEXTURE7);
232233
//glBindTexture(GL_TEXTURE_2D, mesh.Material.AOMap);
233234

MP-APS/PBRMaterial.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
#include "ResourceManager.h"
44

5+
/***********************************************************************************/
6+
PBRMaterial::PBRMaterial() {
7+
// Set material defaults
8+
std::fill(m_materialTextures.begin(), m_materialTextures.end(), 0);
9+
std::fill(m_materialColors.begin(), m_materialColors.end(), glm::vec3(0.0f));
10+
}
11+
512
/***********************************************************************************/
613
void PBRMaterial::Init(const std::string_view name,
714
const std::string_view albedoPath,
@@ -18,7 +25,28 @@ void PBRMaterial::Init(const std::string_view name,
1825
m_materialTextures[METALLIC] = ResourceManager::GetInstance().LoadTexture(metallicPath);
1926
m_materialTextures[NORMAL] = ResourceManager::GetInstance().LoadTexture(normalPath);
2027
m_materialTextures[ROUGHNESS] = ResourceManager::GetInstance().LoadTexture(roughnessPath);
21-
m_materialTextures[ALPHA] = ResourceManager::GetInstance().LoadTexture(alphaMaskPath);
28+
29+
m_alpha = ResourceManager::GetInstance().LoadTexture(alphaMaskPath);
30+
}
31+
32+
/***********************************************************************************/
33+
void PBRMaterial::Init(const std::string_view name,
34+
const glm::vec3& albedo,
35+
const glm::vec3& ao,
36+
const glm::vec3& metallic,
37+
const glm::vec3& normal,
38+
const glm::vec3& roughness,
39+
const float alpha)
40+
{
41+
Name = name;
42+
43+
m_materialColors[ALBEDO] = albedo;
44+
m_materialColors[AO] = ao;
45+
m_materialColors[METALLIC] = metallic;
46+
m_materialColors[NORMAL] = normal;
47+
m_materialColors[ROUGHNESS] = roughness;
48+
49+
m_alpha = alpha;
2250
}
2351

2452
/***********************************************************************************/
@@ -27,6 +55,6 @@ unsigned int PBRMaterial::GetParameterTexture(const ParameterType parameter) con
2755
}
2856

2957
/***********************************************************************************/
30-
float PBRMaterial::GetParameterColor(const ParameterType parameter) const noexcept {
58+
glm::vec3 PBRMaterial::GetParameterColor(const ParameterType parameter) const noexcept {
3159
return m_materialColors[parameter];
3260
}

MP-APS/PBRMaterial.h

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
#pragma once
22

3+
#include <glm/vec3.hpp>
4+
35
#include <memory>
46
#include <array>
7+
#include <variant>
58

69
// Material for a PBR pipeline
710
class PBRMaterial {
8-
911
public:
12+
PBRMaterial();
1013

1114
enum ParameterType {
1215
ALBEDO = 0,
1316
AO,
1417
METALLIC,
1518
NORMAL,
16-
ROUGHNESS,
17-
ALPHA
19+
ROUGHNESS
1820
};
1921

2022
void Init(const std::string_view name,
@@ -25,20 +27,33 @@ class PBRMaterial {
2527
const std::string_view roughnessPath,
2628
const std::string_view alphaMaskPath);
2729

30+
void Init(const std::string_view name,
31+
const glm::vec3& albedo,
32+
const glm::vec3& ao,
33+
const glm::vec3& metallic,
34+
const glm::vec3& normal,
35+
const glm::vec3& roughness,
36+
const float alpha = 1.0f);
37+
2838
auto operator==(const PBRMaterial& rhs) const noexcept {
2939
return Name == rhs.Name;
3040
}
3141

3242
std::string_view Name;
3343

3444
unsigned int GetParameterTexture(const ParameterType parameter) const noexcept;
35-
float GetParameterColor(const ParameterType parameter) const noexcept;
45+
glm::vec3 GetParameterColor(const ParameterType parameter) const noexcept;
46+
47+
// Gets active alpha texture/value from union
48+
auto GetAlpha() const noexcept;
3649

3750
private:
51+
std::variant<unsigned int, float> m_alpha;
52+
3853
// unsigned int HeightMap;
3954

40-
std::array<unsigned int, 6> m_materialTextures;
41-
std::array<float, 6> m_materialColors;
55+
std::array<unsigned int, 5> m_materialTextures;
56+
std::array<glm::vec3, 5> m_materialColors;
4257
};
4358

4459
using PBRMaterialPtr = std::shared_ptr<PBRMaterial>;

0 commit comments

Comments
 (0)