mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 05:58:27 +02:00
Remove magic numbers
This commit is contained in:
parent
e914f02445
commit
b423bc38ba
2 changed files with 11 additions and 7 deletions
|
@ -18,7 +18,9 @@ LightStage::Shadow::Shadow(model::LightPointer light) : _light{ light}, _frustum
|
||||||
map = framebuffer->getDepthStencilBuffer();
|
map = framebuffer->getDepthStencilBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightStage::Shadow::setKeylightFrustum(ViewFrustum* viewFrustum, float near, float far) {
|
void LightStage::Shadow::setKeylightFrustum(ViewFrustum* viewFrustum, float nearDepth, float farDepth) {
|
||||||
|
assert(nearDepth >= 0 && farDepth > 0);
|
||||||
|
|
||||||
// Orient the keylight frustum
|
// Orient the keylight frustum
|
||||||
const auto& direction = glm::normalize(_light->getDirection());
|
const auto& direction = glm::normalize(_light->getDirection());
|
||||||
glm::quat orientation;
|
glm::quat orientation;
|
||||||
|
@ -32,7 +34,7 @@ void LightStage::Shadow::setKeylightFrustum(ViewFrustum* viewFrustum, float near
|
||||||
_frustum->setOrientation(orientation);
|
_frustum->setOrientation(orientation);
|
||||||
|
|
||||||
// Position the keylight frustum
|
// Position the keylight frustum
|
||||||
_frustum->setPosition(viewFrustum->getPosition() - (glm::abs(near) + glm::abs(far))*direction);
|
_frustum->setPosition(viewFrustum->getPosition() - (nearDepth + farDepth)*direction);
|
||||||
|
|
||||||
_view = _frustum->getView();
|
_view = _frustum->getView();
|
||||||
const Transform viewInverse{ _view.getInverseMatrix() };
|
const Transform viewInverse{ _view.getInverseMatrix() };
|
||||||
|
@ -40,8 +42,8 @@ void LightStage::Shadow::setKeylightFrustum(ViewFrustum* viewFrustum, float near
|
||||||
viewFrustum->calculate();
|
viewFrustum->calculate();
|
||||||
//const auto nearCorners = viewFrustum->getCorners(0);
|
//const auto nearCorners = viewFrustum->getCorners(0);
|
||||||
const auto nearClip = viewFrustum->getNearClip();
|
const auto nearClip = viewFrustum->getNearClip();
|
||||||
const auto nearCorners = viewFrustum->getCorners(near);
|
const auto nearCorners = viewFrustum->getCorners(nearDepth);
|
||||||
const auto farCorners = viewFrustum->getCorners(far);
|
const auto farCorners = viewFrustum->getCorners(farDepth);
|
||||||
|
|
||||||
vec3 min{ viewInverse.transform(nearCorners.bottomLeft) };
|
vec3 min{ viewInverse.transform(nearCorners.bottomLeft) };
|
||||||
vec3 max{ min };
|
vec3 max{ min };
|
||||||
|
|
|
@ -102,7 +102,6 @@ void RenderShadowTask::run(const SceneContextPointer& sceneContext, const Render
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: If we're not using the global keylight, bail
|
|
||||||
const auto& lightStage = DependencyManager::get<DeferredLightingEffect>()->getLightStage();
|
const auto& lightStage = DependencyManager::get<DeferredLightingEffect>()->getLightStage();
|
||||||
const auto globalLight = lightStage.lights[0];
|
const auto globalLight = lightStage.lights[0];
|
||||||
|
|
||||||
|
@ -113,8 +112,11 @@ void RenderShadowTask::run(const SceneContextPointer& sceneContext, const Render
|
||||||
|
|
||||||
ViewFrustum* viewFrustum = args->_viewFrustum;
|
ViewFrustum* viewFrustum = args->_viewFrustum;
|
||||||
|
|
||||||
const auto nearClip = viewFrustum->getNearClip();
|
auto nearClip = viewFrustum->getNearClip();
|
||||||
globalLight->shadow.setKeylightFrustum(viewFrustum, nearClip - 1, nearClip + 20);
|
const int SHADOW_NEAR_DEPTH = -1;
|
||||||
|
const int SHADOW_FAR_DEPTH = 20;
|
||||||
|
globalLight->shadow.setKeylightFrustum(viewFrustum,
|
||||||
|
glm::max(0.0f, nearClip - SHADOW_NEAR_DEPTH), nearClip + SHADOW_FAR_DEPTH);
|
||||||
|
|
||||||
// Set the keylight frustum
|
// Set the keylight frustum
|
||||||
args->_viewFrustum = globalLight->shadow.getFrustum().get();
|
args->_viewFrustum = globalLight->shadow.getFrustum().get();
|
||||||
|
|
Loading…
Reference in a new issue