From 0b4484a153ec22e58f7a244d9e0e2bc6fdb14d10 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 29 May 2014 16:49:51 -0700 Subject: [PATCH] Trying a different way of determining the cascade threshold distances. --- interface/src/Application.cpp | 3 +++ interface/src/Application.h | 3 +++ interface/src/voxels/VoxelSystem.cpp | 5 +++-- interface/src/voxels/VoxelSystem.h | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index af94ddba01..bcb52cfabc 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2298,6 +2298,9 @@ void Application::updateShadowMap() { for (size_t j = 0; j < sizeof(points) / sizeof(points[0]); j++) { radius = qMax(radius, glm::distance(points[j], center)); } + if (i < 3) { + _shadowDistances[i] = -glm::distance(_viewFrustum.getPosition(), center) - radius; + } center = inverseRotation * center; // to reduce texture "shimmer," move in texel increments diff --git a/interface/src/Application.h b/interface/src/Application.h index 68d437815b..3fcf40b95b 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -266,6 +266,8 @@ public: void getModelViewMatrix(glm::dmat4* modelViewMatrix); void getProjectionMatrix(glm::dmat4* projectionMatrix); + const glm::vec3& getShadowDistances() const { return _shadowDistances; } + /// Computes the off-axis frustum parameters for the view frustum, taking mirroring into account. void computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal, float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const; @@ -493,6 +495,7 @@ private: static const int CASCADED_SHADOW_MATRIX_COUNT = 4; glm::mat4 _shadowMatrices[CASCADED_SHADOW_MATRIX_COUNT]; + glm::vec3 _shadowDistances; Environment _environment; diff --git a/interface/src/voxels/VoxelSystem.cpp b/interface/src/voxels/VoxelSystem.cpp index 3525a086b4..2b86a58d9b 100644 --- a/interface/src/voxels/VoxelSystem.cpp +++ b/interface/src/voxels/VoxelSystem.cpp @@ -528,8 +528,7 @@ void VoxelSystem::initVoxelMemory() { _cascadedShadowMapProgram.bind(); _cascadedShadowMapProgram.setUniformValue("shadowMap", 0); - _cascadedShadowMapProgram.setUniformValue("shadowDistances", -SHADOW_MATRIX_DISTANCES[1], - -SHADOW_MATRIX_DISTANCES[2], -SHADOW_MATRIX_DISTANCES[3]); + _shadowDistancesLocation = _cascadedShadowMapProgram.uniformLocation("shadowDistances"); _cascadedShadowMapProgram.release(); } } @@ -1179,6 +1178,7 @@ glm::vec3 VoxelSystem::computeVoxelVertex(const glm::vec3& startVertex, float vo ProgramObject VoxelSystem::_perlinModulateProgram; ProgramObject VoxelSystem::_shadowMapProgram; ProgramObject VoxelSystem::_cascadedShadowMapProgram; +int VoxelSystem::_shadowDistancesLocation; void VoxelSystem::init() { if (_initialized) { @@ -1502,6 +1502,7 @@ void VoxelSystem::applyScaleAndBindProgram(bool texture) { if (Menu::getInstance()->getShadowsEnabled()) { if (Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows)) { _cascadedShadowMapProgram.bind(); + _cascadedShadowMapProgram.setUniform(_shadowDistancesLocation, Application::getInstance()->getShadowDistances()); } else { _shadowMapProgram.bind(); } diff --git a/interface/src/voxels/VoxelSystem.h b/interface/src/voxels/VoxelSystem.h index acd0cd170a..71abc9ca93 100644 --- a/interface/src/voxels/VoxelSystem.h +++ b/interface/src/voxels/VoxelSystem.h @@ -234,6 +234,7 @@ private: static ProgramObject _perlinModulateProgram; static ProgramObject _shadowMapProgram; static ProgramObject _cascadedShadowMapProgram; + static int _shadowDistancesLocation; int _hookID; std::vector _freeIndexes;