Fixed shadow pass and physics system a little bit
This commit is contained in:
@@ -72,9 +72,14 @@ void ShadowPass::beginFrame(const Component::Camera& camera, const Component::Tr
|
||||
updateViewParameters(camera, transform);
|
||||
Matrix4 invCam = viewParams.inverseViewProjectionMatrix;
|
||||
float lastSplitDist = 0.0;
|
||||
constexpr float cascadeOverlap = 0.1f; // overlap factor to prevent gaps at cascade boundaries
|
||||
for (uint32 i = 0; i < NUM_CASCADES; ++i) {
|
||||
float splitDist = cascadeSplits[i];
|
||||
|
||||
// Extend each cascade's frustum slice slightly into adjacent cascades
|
||||
float overlapNear = (i > 0) ? lastSplitDist - cascadeOverlap * (lastSplitDist - (i > 1 ? cascadeSplits[i - 2] : 0.0f)) : 0.0f;
|
||||
float overlapFar = (i < NUM_CASCADES - 1) ? splitDist + cascadeOverlap * (cascadeSplits[i + 1] - splitDist) : splitDist;
|
||||
|
||||
Array<Vector> frustumCorners = {
|
||||
Vector(-1.0f, 1.0f, 0.0f), Vector(1.0f, 1.0f, 0.0f), Vector(1.0f, -1.0f, 0.0f), Vector(-1.0f, -1.0f, 0.0f),
|
||||
Vector(-1.0f, 1.0f, 1.0f), Vector(1.0f, 1.0f, 1.0f), Vector(1.0f, -1.0f, 1.0f), Vector(-1.0f, -1.0f, 1.0f),
|
||||
@@ -86,8 +91,8 @@ void ShadowPass::beginFrame(const Component::Camera& camera, const Component::Tr
|
||||
}
|
||||
for (uint32 j = 0; j < 4; j++) {
|
||||
Vector dist = frustumCorners[j + 4] - frustumCorners[j];
|
||||
frustumCorners[j + 4] = frustumCorners[j] + (dist * splitDist);
|
||||
frustumCorners[j] = frustumCorners[j] + (dist * lastSplitDist);
|
||||
frustumCorners[j + 4] = frustumCorners[j] + (dist * overlapFar);
|
||||
frustumCorners[j] = frustumCorners[j] + (dist * overlapNear);
|
||||
}
|
||||
|
||||
Vector frustumCenter = Vector(0);
|
||||
@@ -108,10 +113,10 @@ void ShadowPass::beginFrame(const Component::Camera& camera, const Component::Tr
|
||||
|
||||
for (uint32 s = 0; s < scene->getLightEnvironment()->getNumDirectionalLights(); ++s) {
|
||||
Vector lightDir = glm::normalize(scene->getLightEnvironment()->getDirectionalLight(s).direction);
|
||||
Vector cameraPos = frustumCenter - lightDir * -minExtents.z;
|
||||
Vector cameraPos = frustumCenter - lightDir * (100.0f * -minExtents.z);
|
||||
Matrix4 viewMatrix = glm::lookAt(cameraPos, frustumCenter, Vector(0, 1, 0));
|
||||
Matrix4 projectionMatrix =
|
||||
orthographicProjection(minExtents.x, maxExtents.x, minExtents.y, maxExtents.y, 0.0f, maxExtents.z - minExtents.z);
|
||||
orthographicProjection(minExtents.x, maxExtents.x, minExtents.y, maxExtents.y, 0.0f, maxExtents.z - (100.0f * minExtents.z));
|
||||
Matrix4 viewProjectionMatrix = projectionMatrix * viewMatrix;
|
||||
viewParams = {
|
||||
.viewMatrix = viewMatrix,
|
||||
@@ -193,7 +198,7 @@ void ShadowPass::render() {
|
||||
.pipelineLayout = collection->pipelineLayout,
|
||||
.rasterizationState =
|
||||
{
|
||||
.cullMode = Gfx::SE_CULL_MODE_NONE,
|
||||
.cullMode = Gfx::SE_CULL_MODE_FRONT_BIT,
|
||||
.depthBiasEnable = true,
|
||||
.depthBiasConstantFactor = depthBiasConstant,
|
||||
.depthBiasSlopeFactor = depthBiasSlope,
|
||||
|
||||
Reference in New Issue
Block a user