Skip to content

Commit d7abada

Browse files
committed
Reworked PBRMaterial to support textures and raw colours.
1 parent 595d1a5 commit d7abada

File tree

7 files changed

+45
-19
lines changed

7 files changed

+45
-19
lines changed

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

0 Bytes
Binary file not shown.

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

32 KB
Binary file not shown.

MP-APS/Core/RenderSystem.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ void RenderSystem::renderModelsWithTextures(GLShaderProgram& shader, const std::
221221
const auto meshes = model->GetMeshes();
222222
for (const auto& mesh : meshes) {
223223
glActiveTexture(GL_TEXTURE3);
224-
glBindTexture(GL_TEXTURE_2D, mesh.Material->AlbedoMap);
224+
glBindTexture(GL_TEXTURE_2D, mesh.Material->GetParameterTexture(PBRMaterial::ALBEDO));
225225
glActiveTexture(GL_TEXTURE4);
226-
glBindTexture(GL_TEXTURE_2D, mesh.Material->NormalMap);
226+
glBindTexture(GL_TEXTURE_2D, mesh.Material->GetParameterTexture(PBRMaterial::NORMAL));
227227
glActiveTexture(GL_TEXTURE5);
228-
glBindTexture(GL_TEXTURE_2D, mesh.Material->MetallicMap);
228+
glBindTexture(GL_TEXTURE_2D, mesh.Material->GetParameterTexture(PBRMaterial::METALLIC));
229229
glActiveTexture(GL_TEXTURE6);
230-
glBindTexture(GL_TEXTURE_2D, mesh.Material->RoughnessMap);
230+
glBindTexture(GL_TEXTURE_2D, mesh.Material->GetParameterTexture(PBRMaterial::ROUGHNESS));
231231
//glActiveTexture(GL_TEXTURE7);
232232
//glBindTexture(GL_TEXTURE_2D, mesh.Material.AOMap);
233233

MP-APS/PBRMaterial.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,24 @@ void PBRMaterial::Init(const std::string_view name,
99
const std::string_view metallicPath,
1010
const std::string_view normalPath,
1111
const std::string_view roughnessPath,
12-
const std::string_view alphaMaskPath) {
12+
const std::string_view alphaMaskPath)
13+
{
1314
Name = name;
1415

15-
AlbedoMap = ResourceManager::GetInstance().LoadTexture(albedoPath);
16-
AOMap = ResourceManager::GetInstance().LoadTexture(aoPath);
17-
MetallicMap = ResourceManager::GetInstance().LoadTexture(metallicPath);
18-
NormalMap = ResourceManager::GetInstance().LoadTexture(normalPath);
19-
RoughnessMap = ResourceManager::GetInstance().LoadTexture(roughnessPath);
20-
AlphaMask = ResourceManager::GetInstance().LoadTexture(alphaMaskPath);
16+
m_materialTextures[ALBEDO] = ResourceManager::GetInstance().LoadTexture(albedoPath);
17+
m_materialTextures[AO] = ResourceManager::GetInstance().LoadTexture(aoPath);
18+
m_materialTextures[METALLIC] = ResourceManager::GetInstance().LoadTexture(metallicPath);
19+
m_materialTextures[NORMAL] = ResourceManager::GetInstance().LoadTexture(normalPath);
20+
m_materialTextures[ROUGHNESS] = ResourceManager::GetInstance().LoadTexture(roughnessPath);
21+
m_materialTextures[ALPHA] = ResourceManager::GetInstance().LoadTexture(alphaMaskPath);
22+
}
23+
24+
/***********************************************************************************/
25+
unsigned int PBRMaterial::GetParameterTexture(const ParameterType parameter) const noexcept {
26+
return m_materialTextures[parameter];
27+
}
28+
29+
/***********************************************************************************/
30+
float PBRMaterial::GetParameterColor(const ParameterType parameter) const noexcept {
31+
return m_materialColors[parameter];
2132
}

MP-APS/PBRMaterial.h

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

3-
#include <string_view>
43
#include <memory>
4+
#include <array>
55

66
// Material for a PBR pipeline
7-
struct PBRMaterial {
7+
class PBRMaterial {
8+
9+
public:
10+
11+
enum ParameterType {
12+
ALBEDO = 0,
13+
AO,
14+
METALLIC,
15+
NORMAL,
16+
ROUGHNESS,
17+
ALPHA
18+
};
819

920
void Init(const std::string_view name,
1021
const std::string_view albedoPath,
@@ -20,13 +31,14 @@ struct PBRMaterial {
2031

2132
std::string_view Name;
2233

23-
unsigned int AlbedoMap;
24-
unsigned int AOMap;
25-
unsigned int MetallicMap;
26-
unsigned int NormalMap;
27-
unsigned int RoughnessMap;
28-
unsigned int AlphaMask;
34+
unsigned int GetParameterTexture(const ParameterType parameter) const noexcept;
35+
float GetParameterColor(const ParameterType parameter) const noexcept;
36+
37+
private:
2938
// unsigned int HeightMap;
39+
40+
std::array<unsigned int, 6> m_materialTextures;
41+
std::array<float, 6> m_materialColors;
3042
};
3143

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

MP-APS/ResourceManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <sstream>
55
#include <fstream>
66
#include <cassert>
7+
#include <string_view>
78

89
#define STB_IMAGE_IMPLEMENTATION
910
#define STBI_FAILURE_USERMSG

MP-APS/SceneBase.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "ViewFrustum.h"
55

66
#include <ppl.h> // Concurrency library
7+
8+
#include <string_view>
79
#include <iostream>
810

911
/***********************************************************************************/

0 commit comments

Comments
 (0)