Skip to content

Commit d85159d

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 005209c + 5a8d832 commit d85159d

13 files changed

Lines changed: 72 additions & 45 deletions

MP-APS/Core/RenderSystem.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ void RenderSystem::Init(const pugi::xml_node& rendererNode) {
2828
std::cout << "OpenGL Renderer: " << glGetString(GL_RENDERER) << '\n';
2929
#endif
3030

31+
getHardwareFeatures();
32+
3133
const auto width = rendererNode.attribute("width").as_uint();
3234
const auto height = rendererNode.attribute("height").as_uint();
3335

@@ -47,15 +49,18 @@ void RenderSystem::Init(const pugi::xml_node& rendererNode) {
4749
shaders.emplace_back(shader.attribute("path").as_string(), shader.attribute("type").as_string());
4850
}
4951

52+
//GLShaderProgram prgrm;
53+
//prgrm.Init(program.attribute("name").as_string(), shaders);
54+
5055
// Compile and cache shader program
56+
//m_shaderCache.try_emplace(program.attribute("name").as_string(), prgrm);
5157
m_shaderCache.try_emplace(program.attribute("name").as_string(), program.attribute("name").as_string(), shaders);
5258
}
5359

5460
setupScreenquad();
5561
setupTextureSamplers();
5662
setupShadowMap();
5763
setupPostProcessing();
58-
5964

6065
#ifdef _DEBUG
6166
glEnable(GL_DEBUG_OUTPUT);
@@ -294,7 +299,6 @@ void RenderSystem::renderShadowMap(const SceneBase& scene, RenderListIterator re
294299
glCullFace(GL_BACK);
295300
}
296301

297-
298302
/***********************************************************************************/
299303
void RenderSystem::setupScreenquad() {
300304
const std::array<Vertex, 4> screenQuadVertices {
@@ -317,17 +321,13 @@ void RenderSystem::setupScreenquad() {
317321

318322
/***********************************************************************************/
319323
void RenderSystem::setupTextureSamplers() {
320-
// Find max supported hardware anisotropy
321-
float aniso = 0.0f;
322-
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &aniso);
323-
324324
// Sampler for PBR textures used on meshes
325325
glGenSamplers(1, &m_samplerPBRTextures);
326326
glSamplerParameteri(m_samplerPBRTextures, GL_TEXTURE_WRAP_S, GL_REPEAT);
327327
glSamplerParameteri(m_samplerPBRTextures, GL_TEXTURE_WRAP_T, GL_REPEAT);
328328
glSamplerParameteri(m_samplerPBRTextures, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
329329
glSamplerParameteri(m_samplerPBRTextures, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
330-
glSamplerParameterf(m_samplerPBRTextures, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso);
330+
glSamplerParameterf(m_samplerPBRTextures, GL_TEXTURE_MAX_ANISOTROPY_EXT, m_features.MaxAnisotropy);
331331

332332
}
333333

@@ -424,3 +424,10 @@ void RenderSystem::setupPostProcessing() {
424424
bloomBlendShader.SetUniform("vibranceCoefficient", m_coefficient);
425425

426426
}
427+
428+
/***********************************************************************************/
429+
void RenderSystem::setProjectionMatrix(const Camera& camera) {
430+
m_projMatrix = camera.GetProjMatrix(m_width, m_height);
431+
glBindBuffer(GL_UNIFORM_BUFFER, m_uboMatrices);
432+
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), value_ptr(m_projMatrix));
433+
}

MP-APS/Core/RenderSystem.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <unordered_map>
1010
#include <vector>
1111

12+
//https://github.com/tapio/weep/blob/master/engine/glrenderer/renderdevice.cpp
13+
// https://github.com/pboechat/PCSS
14+
1215
/***********************************************************************************/
1316
// Forward Declarations
1417
class Camera;
@@ -40,6 +43,18 @@ class RenderSystem {
4043
);
4144

4245
private:
46+
struct Features {
47+
float MaxAnisotropy;
48+
int MaxArrayTextureLayers;
49+
int MaxTextureSamples;
50+
int MaxTextureSamplers;
51+
int MaxVertexUniformBlocks;
52+
int MaxGeometryUniformBlocks;
53+
int MaxFragmentUniformBlocks;
54+
int MaxComputeWorkGroupSize;
55+
int MaxComputeWorkGroupCount;
56+
} m_features;
57+
4358
// Helper functions
4459

4560

@@ -61,6 +76,8 @@ class RenderSystem {
6176
void setupShadowMap();
6277
// Configure post-processing effects
6378
void setupPostProcessing();
79+
// Sets projection matrix variable and updates UBO
80+
void setProjectionMatrix(const Camera& camera);
6481

6582
// Screen dimensions
6683
std::size_t m_width{ 0 }, m_height{ 0 };

MP-APS/Data/Shaders/PBRps.glsl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,19 @@ float ComputeShadow(const vec4 fragPosLightSpace, const vec3 N, const vec3 L) {
4646

4747
const float closestDepth = texture(shadowMap, projCoords.xy).r;
4848
const float currentDepth = projCoords.z;
49-
5049
const float bias = max(0.05 * (1.0 - dot(N, L)), 0.005); // Bias to solve shadow acne
51-
const float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
50+
51+
// PCF
52+
float shadow = 0.0;
53+
const vec2 texelSize = 1.0 / textureSize(shadowMap, 0);
54+
for(int x = -2; x <= 2; ++x) {
55+
for(int y = -2; y <= 2; ++y) {
56+
const float pcfDepth = texture(shadowMap, projCoords.xy + vec2(x, y) * texelSize).r;
57+
shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0;
58+
}
59+
}
60+
61+
shadow /= 25.0;
5262

5363
return shadow;
5464
}

MP-APS/Data/hdri/hdriHaven4k.hdr

22.7 MB
Binary file not shown.

MP-APS/Graphics/GLVertexArray.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#include "GLVertexArray.h"
22

33
/***********************************************************************************/
4-
void GLVertexArray::Init() {
4+
void GLVertexArray::Init() noexcept {
55
glGenVertexArrays(1, &m_vao);
66
}
77

88
/***********************************************************************************/
9-
void GLVertexArray::AttachBuffer(const BufferType type, const size_t size, const DrawMode mode, const void* data) {
9+
void GLVertexArray::AttachBuffer(const BufferType type, const size_t size, const DrawMode mode, const void* data) noexcept {
1010

1111
GLuint buffer;
1212
glGenBuffers(1, &buffer);
@@ -16,17 +16,17 @@ void GLVertexArray::AttachBuffer(const BufferType type, const size_t size, const
1616
}
1717

1818
/***********************************************************************************/
19-
void GLVertexArray::Bind() const {
19+
void GLVertexArray::Bind() const noexcept {
2020
glBindVertexArray(m_vao);
2121
}
2222

2323
/***********************************************************************************/
24-
void GLVertexArray::Delete() {
24+
void GLVertexArray::Delete() noexcept {
2525
glDeleteVertexArrays(1, &m_vao);
2626
}
2727

2828
/***********************************************************************************/
29-
void GLVertexArray::EnableAttribute(const unsigned int index, const int size, const unsigned int offset, const void* data) {
29+
void GLVertexArray::EnableAttribute(const unsigned int index, const int size, const unsigned int offset, const void* data) noexcept {
3030
glEnableVertexAttribArray(index);
3131
glVertexAttribPointer(index, size, GL_FLOAT, GL_FALSE, offset, data);
3232
}

MP-APS/Graphics/GLVertexArray.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class GLVertexArray {
1616
STREAM = GL_STREAM_DRAW
1717
};
1818

19-
void Init();
20-
void AttachBuffer(const BufferType type, const size_t size, const DrawMode mode, const void* data);
21-
void Bind() const;
22-
void EnableAttribute(const GLuint index, const int size, const GLuint offset, const void* data);
23-
void Delete();
19+
void Init() noexcept;
20+
void AttachBuffer(const BufferType type, const size_t size, const DrawMode mode, const void* data) noexcept;
21+
void Bind() const noexcept;
22+
void EnableAttribute(const GLuint index, const int size, const GLuint offset, const void* data) noexcept;
23+
void Delete() noexcept;
2424

2525
private:
2626
GLuint m_vao{ 0 };

MP-APS/ResourceManager.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ unsigned int ResourceManager::LoadHDRI(const std::string_view path) const {
7272
}
7373

7474
/***********************************************************************************/
75-
unsigned int ResourceManager::LoadTexture(const std::string_view path, const bool useMipMaps) {
75+
unsigned int ResourceManager::LoadTexture(const std::string_view path, const bool useMipMaps, const bool useUnalignedUnpack) {
7676

7777
// Check if texture is already loaded somewhere
7878
const auto val = m_textureCache.find(path.data());
@@ -82,6 +82,10 @@ unsigned int ResourceManager::LoadTexture(const std::string_view path, const boo
8282
return val->second;
8383
}
8484

85+
if (useUnalignedUnpack) {
86+
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
87+
}
88+
8589
// Create and cache a new texture
8690
unsigned int textureID;
8791
glGenTextures(1, &textureID);
@@ -119,6 +123,10 @@ unsigned int ResourceManager::LoadTexture(const std::string_view path, const boo
119123
std::cout << "Resource Manager: loaded texture: " << path << std::endl;
120124
#endif
121125

126+
if (useUnalignedUnpack) {
127+
glPixelStorei(GL_UNPACK_ALIGNMENT, 0);
128+
}
129+
122130
return m_textureCache.try_emplace(path.data(), textureID).first->second;
123131
}
124132

@@ -185,7 +193,7 @@ PBRMaterialPtr ResourceManager::CacheMaterial(const std::string_view name, const
185193

186194
/***********************************************************************************/
187195
void ResourceManager::UnloadModel(const std::string_view modelName) {
188-
auto model = m_modelCache.find(modelName.data());
196+
const auto model = m_modelCache.find(modelName.data());
189197

190198
if (model != m_modelCache.end()) {
191199
model->second->Delete();

MP-APS/ResourceManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ResourceManager {
2626
// Loads an HDR image and generates an OpenGL floating-point texture.
2727
unsigned int LoadHDRI(const std::string_view path) const;
2828
// Loads an image (if not cached) and generates an OpenGL texture.
29-
unsigned int LoadTexture(const std::string_view path, const bool useMipMaps = true);
29+
unsigned int LoadTexture(const std::string_view path, const bool useMipMaps = true, const bool useUnalignedUnpack = false);
3030
// Loads a binary file into a vector and returns it
3131
std::vector<char> LoadBinaryFile(const std::string_view path) const;
3232

MP-APS/SceneBase.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ void SceneBase::Init(const std::string_view sceneName) {
1515
void SceneBase::Update(const double dt) {
1616
}
1717

18+
/***********************************************************************************/
19+
void SceneBase::AddIBLProbe(const glm::vec3& position, const float radiusOfInfluence) {
20+
m_IBLProbes.emplace_back(position, radiusOfInfluence);
21+
}
22+
1823
/***********************************************************************************/
1924
void SceneBase::AddLight(const StaticDirectionalLight& light) {
2025
m_staticDirectionalLights.push_back(light);

MP-APS/SceneBase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class SceneBase {
3636

3737
private:
3838
std::string m_sceneName;
39+
std::string m_skyboxPath = "Data/hdri/barcelona.hdr";
40+
std::size_t m_skyboxResolution = 2048;
3941

4042
std::vector<StaticDirectionalLight> m_staticDirectionalLights;
4143
std::vector<StaticPointLight> m_staticPointLights;

0 commit comments

Comments
 (0)