Trying a different way of determining the cascade threshold distances.

This commit is contained in:
Andrzej Kapolka 2014-05-29 16:49:51 -07:00
parent 391902f79b
commit 0b4484a153
4 changed files with 10 additions and 2 deletions

View file

@ -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

View file

@ -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;

View file

@ -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();
}

View file

@ -234,6 +234,7 @@ private:
static ProgramObject _perlinModulateProgram;
static ProgramObject _shadowMapProgram;
static ProgramObject _cascadedShadowMapProgram;
static int _shadowDistancesLocation;
int _hookID;
std::vector<glBufferIndex> _freeIndexes;