diff --git a/res/shaders/BasePass.slang b/res/shaders/BasePass.slang index 2880da9..37e41e5 100644 --- a/res/shaders/BasePass.slang +++ b/res/shaders/BasePass.slang @@ -27,7 +27,7 @@ ParameterBlock pLightCullingData; static const float4x4 biasMat = float4x4( 0.5, 0.0, 0.0, 0.5, - 0.0, 0.5, 0.0, 0.5, + 0.0, -0.5, 0.0, 0.5, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0); @@ -47,13 +47,13 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target uint cascadeIndex = 0; for (uint c = 0; c < NUM_CASCADES - 1; ++c) { if (params.position_VS.z > pShadowMapping.cascadeSplits[c]) { - //cascadeIndex = c + 1; + cascadeIndex = c + 1; } } float4 lightSpacePos = mul(pShadowMapping.lightSpaceMatrices[cascadeIndex][i], float4(params.position_WS, 1)); lightSpacePos = mul(biasMat, lightSpacePos); - float4 shadowCoord = clipToScreen(lightSpacePos); - /*int3 texDim; + float4 shadowCoord = lightSpacePos; + int3 texDim; pShadowMapping.shadowMaps[cascadeIndex].GetDimensions(texDim.x, texDim.y, texDim.z); float scale = 1.5f; float dx = scale * 1.0 / float(texDim.x); @@ -68,7 +68,7 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target if (shadowCoord.z > 0.0 && shadowCoord.z < 1.0) { float dist = pShadowMapping.shadowMaps[cascadeIndex].Sample(pShadowMapping.shadowSampler, float3(shadowCoord.xy + float2(dx * x, dy * y), i)).r; - if (shadowCoord.w > 0 && dist < shadowCoord.z - 0.005f) + if (shadowCoord.w > 0 && dist > shadowCoord.z) { shadow = 0; } @@ -76,9 +76,9 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target shadowFactor += shadow; count++; } - }*/ + } - result = 1 - float3(pShadowMapping.shadowMaps[cascadeIndex].Sample(pShadowMapping.shadowSampler, float3(shadowCoord.xy, i)).r, 0, 0);//(shadowFactor / count) * pLightEnv.directionalLights[i].illuminate(lightingParams, brdf); + result = (shadowFactor / count) * pLightEnv.directionalLights[i].illuminate(lightingParams, brdf); } for (uint i = 0; i < pLightEnv.numPointLights; ++i) { diff --git a/src/Engine/Graphics/RenderPass/ShadowPass.cpp b/src/Engine/Graphics/RenderPass/ShadowPass.cpp index 0616f45..1b8753b 100644 --- a/src/Engine/Graphics/RenderPass/ShadowPass.cpp +++ b/src/Engine/Graphics/RenderPass/ShadowPass.cpp @@ -108,7 +108,7 @@ void ShadowPass::beginFrame(const Component::Camera& camera, const Component::Tr Vector maxExtents = Vector(radius); Vector minExtents = -maxExtents; - Vector lightDir = glm::normalize(-scene->getLightEnvironment()->getDirectionalLight(s).direction); + Vector lightDir = glm::normalize(scene->getLightEnvironment()->getDirectionalLight(s).direction); Vector cameraPos = frustumCenter - lightDir * -minExtents.z; Matrix4 viewMatrix = glm::lookAt(cameraPos, frustumCenter, Vector(0, 1, 0)); Matrix4 projectionMatrix = @@ -191,8 +191,8 @@ void ShadowPass::render() { .pipelineLayout = collection->pipelineLayout, .rasterizationState = { - .cullMode = Gfx::SE_CULL_MODE_FRONT_BIT, - .depthBiasEnable = true, + .cullMode = Gfx::SE_CULL_MODE_NONE, + .depthBiasEnable = false, .depthBiasConstantFactor = depthBiasConstant, .depthBiasSlopeFactor = depthBiasSlope, }, diff --git a/src/Engine/Math/CMakeLists.txt b/src/Engine/Math/CMakeLists.txt index a32f7b7..97a8af6 100644 --- a/src/Engine/Math/CMakeLists.txt +++ b/src/Engine/Math/CMakeLists.txt @@ -3,6 +3,7 @@ target_sources(Engine AABB.h Math.h Matrix.h + Matrix.cpp Transform.h Transform.cpp Vector.h diff --git a/src/Engine/Math/Matrix.cpp b/src/Engine/Math/Matrix.cpp new file mode 100644 index 0000000..da2f5bb --- /dev/null +++ b/src/Engine/Math/Matrix.cpp @@ -0,0 +1,32 @@ +#include "Matrix.h" + +using namespace Seele; + +Matrix4 Seele::orthographicProjection(float left, float right, float bottom, float top, float nearPlane, float farPlane) { + return Matrix4{ + { + 2.0f / (right - left), + 0.0f, + 0.0f, + 0.0f, + }, + { + 0.0f, + 2.0f / (top - bottom), + 0.0f, + 0.0f, + }, + { + 0.0f, + 0.0f, + 1.0f / (farPlane - nearPlane), + 0.0f, + }, + { + -(right + left) / (right - left), + -(top + bottom) / (top - bottom), + farPlane / (farPlane - nearPlane), + 1.0f, + }, + }; +} \ No newline at end of file diff --git a/src/Engine/Math/Matrix.h b/src/Engine/Math/Matrix.h index f8d5195..6837c7d 100644 --- a/src/Engine/Math/Matrix.h +++ b/src/Engine/Math/Matrix.h @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include @@ -36,32 +37,5 @@ static Matrix4 perspectiveProjection(float fov, float aspect, float nearPlane, f }, }; } -static Matrix4 orthographicProjection(float left, float right, float bottom, float top, float nearPlane, float farPlane) { - return Matrix4{ - { - 2.0f / (right - left), - 0.0f, - 0.0f, - 0.0f, - }, - { - 0.0f, - 2.0f / (top - bottom), - 0.0f, - 0.0f, - }, - { - 0.0f, - 0.0f, - -2.0f / (nearPlane - farPlane), - 0.0f, - }, - { - -(right + left) / (right - left), - -(top + bottom) / (top - bottom), - -(nearPlane + farPlane) / (nearPlane - farPlane), - 1.0f, - }, - }; -} +Matrix4 orthographicProjection(float left, float right, float bottom, float top, float nearPlane, float farPlane); } // namespace Seele \ No newline at end of file