Skip to content

Commit 5a8d832

Browse files
committed
More terrain work
1 parent b93cc55 commit 5a8d832

23 files changed

+179
-157
lines changed

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

-1 KB
Binary file not shown.

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

-23.7 MB
Binary file not shown.

MP-APS/AI/AISystem.cpp

Lines changed: 0 additions & 2 deletions
This file was deleted.

MP-APS/AI/AISystem.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

MP-APS/Core/RenderSystem.cpp

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

33+
getHardwareFeatures();
34+
3335
const auto width = rendererNode.attribute("width").as_uint();
3436
const auto height = rendererNode.attribute("height").as_uint();
3537

@@ -38,7 +40,7 @@ void RenderSystem::Init(const pugi::xml_node& rendererNode) {
3840
m_shadowMapResolution = rendererNode.attribute("shadowResolution").as_uint();
3941

4042
m_hdrFBO.Init("HDR FBO", width, height);
41-
m_skybox.Init("Data/hdri/barcelona.hdr", 2048);
43+
m_skybox.Init("Data/hdri/hdriHaven4k.hdr", 3072);
4244

4345
// Compile all shader programs in config.xml
4446
for (auto program = rendererNode.child("Program"); program; program = program.next_sibling("Program")) {
@@ -49,15 +51,18 @@ void RenderSystem::Init(const pugi::xml_node& rendererNode) {
4951
shaders.emplace_back(shader.attribute("path").as_string(), shader.attribute("type").as_string());
5052
}
5153

54+
//GLShaderProgram prgrm;
55+
//prgrm.Init(program.attribute("name").as_string(), shaders);
56+
5257
// Compile and cache shader program
58+
//m_shaderCache.try_emplace(program.attribute("name").as_string(), prgrm);
5359
m_shaderCache.try_emplace(program.attribute("name").as_string(), program.attribute("name").as_string(), shaders);
5460
}
5561

5662
setupScreenquad();
5763
setupTextureSamplers();
5864
setupShadowMap();
5965
setupPostProcessing();
60-
6166

6267
#ifdef _DEBUG
6368
glEnable(GL_DEBUG_OUTPUT);
@@ -169,32 +174,42 @@ void RenderSystem::Render(const SceneBase& scene, const bool wireframe) {
169174
}
170175

171176
/***********************************************************************************/
172-
// TODO: This needs to be gutted and put elsewhere
173-
void RenderSystem::InitView(const Camera& camera) {
174-
m_projMatrix = camera.GetProjMatrix(m_width, m_height);
175-
glBindBuffer(GL_UNIFORM_BUFFER, m_uboMatrices);
176-
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), value_ptr(m_projMatrix));
177+
void RenderSystem::InitScene(const SceneBase& scene) {
178+
//m_skybox.Init(scene.m_skyboxPath, scene.m_skyboxResolution);
179+
180+
setProjectionMatrix(scene.m_camera);
177181
}
178182

179183
/***********************************************************************************/
180-
void RenderSystem::Update(const Camera& camera, const double delta) {
184+
void RenderSystem::Update(const SceneBase& scene, const double delta) {
181185

182186
// Window size changed.
183187
if (Input::GetInstance().ShouldResize()) {
184188
m_width = Input::GetInstance().GetWidth();
185189
m_height = Input::GetInstance().GetHeight();
186190

187-
InitView(camera);
191+
setProjectionMatrix(scene.m_camera);
192+
188193
glViewport(0, 0, m_width, m_height);
189194
m_shadowDepthFBO.Resize(m_width, m_height);
190195
}
191196

192197
// Update view matrix inside UBO
193-
const auto view = camera.GetViewMatrix();
198+
const auto view = scene.m_camera.GetViewMatrix();
194199
glBindBuffer(GL_UNIFORM_BUFFER, m_uboMatrices);
195200
glBufferSubData(GL_UNIFORM_BUFFER, sizeof(glm::mat4), sizeof(glm::mat4), glm::value_ptr(view));
196201
}
197202

203+
/***********************************************************************************/
204+
void RenderSystem::getHardwareFeatures() {
205+
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &m_features.MaxAnisotropy);
206+
glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &m_features.MaxArrayTextureLayers);
207+
glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &m_features.MaxTextureSamples);
208+
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &m_features.MaxTextureSamplers);
209+
glGetIntegerv(GL_MAX_VERTEX_UNIFORM_BLOCKS, &m_features.MaxVertexUniformBlocks);
210+
// finish getting hardware features
211+
}
212+
198213
/***********************************************************************************/
199214
void RenderSystem::setDefaultState() {
200215
glFrontFace(GL_CCW);
@@ -264,6 +279,10 @@ void RenderSystem::renderQuad() const {
264279

265280
/***********************************************************************************/
266281
void RenderSystem::renderShadowMap(const SceneBase& scene) {
282+
setDefaultState();
283+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
284+
glBindBuffer(GL_UNIFORM_BUFFER, m_uboMatrices);
285+
267286
static auto& shadowDepthShader = m_shaderCache.at("ShadowDepthShader");
268287
shadowDepthShader.Bind();
269288
static constexpr float near_plane = 0.0f, far_plane = 100.0f;
@@ -289,7 +308,6 @@ void RenderSystem::renderShadowMap(const SceneBase& scene) {
289308
glCullFace(GL_BACK);
290309
}
291310

292-
293311
/***********************************************************************************/
294312
void RenderSystem::setupScreenquad() {
295313
const std::array<Vertex, 4> screenQuadVertices {
@@ -312,17 +330,13 @@ void RenderSystem::setupScreenquad() {
312330

313331
/***********************************************************************************/
314332
void RenderSystem::setupTextureSamplers() {
315-
// Find max supported hardware anisotropy
316-
float aniso = 0.0f;
317-
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &aniso);
318-
319333
// Sampler for PBR textures used on meshes
320334
glGenSamplers(1, &m_samplerPBRTextures);
321335
glSamplerParameteri(m_samplerPBRTextures, GL_TEXTURE_WRAP_S, GL_REPEAT);
322336
glSamplerParameteri(m_samplerPBRTextures, GL_TEXTURE_WRAP_T, GL_REPEAT);
323337
glSamplerParameteri(m_samplerPBRTextures, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
324338
glSamplerParameteri(m_samplerPBRTextures, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
325-
glSamplerParameterf(m_samplerPBRTextures, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso);
339+
glSamplerParameterf(m_samplerPBRTextures, GL_TEXTURE_MAX_ANISOTROPY_EXT, m_features.MaxAnisotropy);
326340

327341
}
328342

@@ -419,3 +433,10 @@ void RenderSystem::setupPostProcessing() {
419433
bloomBlendShader.SetUniform("vibranceCoefficient", m_coefficient);
420434

421435
}
436+
437+
/***********************************************************************************/
438+
void RenderSystem::setProjectionMatrix(const Camera& camera) {
439+
m_projMatrix = camera.GetProjMatrix(m_width, m_height);
440+
glBindBuffer(GL_UNIFORM_BUFFER, m_uboMatrices);
441+
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), value_ptr(m_projMatrix));
442+
}

MP-APS/Core/RenderSystem.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
#include <unordered_map>
1010

11+
//https://github.com/tapio/weep/blob/master/engine/glrenderer/renderdevice.cpp
12+
// https://github.com/pboechat/PCSS
13+
1114
/***********************************************************************************/
1215
// Forward Declarations
1316
class Camera;
@@ -31,18 +34,31 @@ class RenderSystem {
3134
~RenderSystem() = default;
3235

3336
void Init(const pugi::xml_node& rendererNode);
34-
void Update(const Camera& camera, const double delta);
37+
void Update(const SceneBase& scene, const double delta);
3538
// Release OpenGL resources
3639
void Shutdown() const;
3740

38-
void InitView(const Camera& camera);
41+
void InitScene(const SceneBase& scene);
3942

4043
// Where the magic happens
4144
void Render(const SceneBase& scene, const bool wireframe = false);
4245

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

59+
// Helper functions
60+
61+
void getHardwareFeatures();
4662
// Sets the default state required for rendering
4763
void setDefaultState();
4864
// Render models contained in the renderlist
@@ -61,6 +77,8 @@ class RenderSystem {
6177
void setupShadowMap();
6278
// Configure post-processing effects
6379
void setupPostProcessing();
80+
// Sets projection matrix variable and updates UBO
81+
void setProjectionMatrix(const Camera& camera);
6482

6583
// Screen dimensions
6684
std::size_t m_width, m_height;

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/Demos/DemoPathfinding.cpp

Lines changed: 0 additions & 24 deletions
This file was deleted.

MP-APS/Demos/DemoPathfinding.h

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)