diff --git a/Assets/Scenes/Scene2.shade b/Assets/Scenes/Scene2.shade index c8aa9c6d..de902c55 100644 --- a/Assets/Scenes/Scene2.shade +++ b/Assets/Scenes/Scene2.shade @@ -5,7 +5,7 @@ Components: Transform Component: Translate: {x: 0, y: 0.304069757, z: 1.73034382} - Rotate: {x: -1.48352981, y: 0, z: 0} + Rotate: {x: 0, y: 0, z: 0} Scale: {x: 1, y: 1, z: 1} IsActive: true Camera Component: @@ -26,8 +26,8 @@ NumberOfChildren: 1 Components: Transform Component: - Translate: {x: 0, y: 0, z: 0} - Rotate: {x: 0, y: 0, z: 0} + Translate: {x: -1.86388135, y: 0.0544953719, z: 0} + Rotate: {x: -0, y: 0, z: -0} Scale: {x: 1, y: 1, z: 1} IsActive: true Renderable Component: @@ -56,9 +56,9 @@ NumberOfChildren: 0 Components: Light Component: - Position: {x: 0, y: 0, z: 0} + Position: {x: 3, y: 4.5, z: 7} Type: Directional - Direction: {x: 0, y: 0, z: 1} + Direction: {x: -0.298000008, y: 0.522498012, z: 0.798600018} Color: {x: 1, y: 1, z: 1, w: 1} Layer: 4294967295 Strength: 0 diff --git a/Assets/Shaders/DeferredComposite_CS.glsl b/Assets/Shaders/DeferredComposite_CS.glsl index 576ce74b..51f147bb 100644 --- a/Assets/Shaders/DeferredComposite_CS.glsl +++ b/Assets/Shaders/DeferredComposite_CS.glsl @@ -24,7 +24,8 @@ layout(set = 3, binding = 1, rgba32f) uniform image2D normals; layout(set = 3, binding = 2, rgba8) uniform image2D albedo; layout(set = 3, binding = 3, r32ui) uniform uimage2D lightLayerData; layout(set = 3, binding = 4, r8) uniform image2D ssaoBlurredImage; -layout(set = 3, binding = 5, rgba8) uniform image2D targetImage; +layout(set = 3, binding = 5, rgba8) uniform image2D positionWorldSpace; +layout(set = 3, binding = 6, rgba8) uniform image2D targetImage; layout (set = 4, binding = 0) uniform sampler2D shadowMaps[]; // for textures (global) @@ -47,10 +48,12 @@ layout(std430, set = 1, binding = 4) buffer AmbientLightData AmbientLightStruct aLightData[]; } AmbLightData; -// bool IsInShadow (sampler2D shadowMap, vec2 coords, float depth, mat4 lightVP) -// { -// // vec4 fragPosLightPOV = lightVP * -// } +float CalcShadowValue (sampler2D shadowMap, vec4 worldSpaceFragPos, mat4 lightPV) +{ + vec4 fragPosLightPOV = lightPV * worldSpaceFragPos; + vec3 converted = (fragPosLightPOV.xyz / fragPosLightPOV.w) * vec3(0.5f) + vec3(0.5f); + return step (fragPosLightPOV.z, texture(shadowMap, converted.xy).r); +} void main() { @@ -61,6 +64,9 @@ void main() vec3 pixelDiffuse = imageLoad (albedo, globalThread).rgb; // Get position of fragment in world space + vec4 positionWorld = vec4 (imageLoad (positionWorldSpace, globalThread).rgb, 1.0f); + + // Get position of fragment in view spacee vec3 positionView = imageLoad (positions, globalThread).rgb; // normal of fragment @@ -100,7 +106,7 @@ void main() if ((DirLightData.dLightData[i].shadowData & uint(1)) == 1) { // calculate shadow map here - vec2 texCoord = vec2 (gl_GlobalInvocationID.xy) / vec2 (imageSize (targetImage)); + fragColor *= CalcShadowValue (shadowMaps[0], positionWorld, DirLightData.dLightData[i].pvMatrix).xxx; } } } @@ -111,7 +117,11 @@ void main() // store result into result image imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(fragColor.rgb, 1.0f)); - // imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), shadowMapColor); - //imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(ssaoVal.rrr, 1.0f)); + // vec2 normTexCoords = vec2 (gl_GlobalInvocationID.xy) / vec2 (1024.0f); + // vec4 shadowMapVal = texture(shadowMaps[0], normTexCoords); + // if (normTexCoords.x > 1.0f || normTexCoords.y > 1.0f) + // shadowMapVal = vec4(0.0f); + + // imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), shadowMapVal.xxxx); } \ No newline at end of file diff --git a/Assets/Shaders/DeferredComposite_CS.shshaderb b/Assets/Shaders/DeferredComposite_CS.shshaderb index 633fd197..8a11aa08 100644 Binary files a/Assets/Shaders/DeferredComposite_CS.shshaderb and b/Assets/Shaders/DeferredComposite_CS.shshaderb differ diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 924100d4..703de2c0 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -313,7 +313,9 @@ namespace SHADE camera.orthoProjMatrix(2, 3) = -n / (f-n); camera.orthoProjMatrix(3, 3) = 1.0f; - //camera.orthoProjMatrix = SHMatrix::OrthographicRH(camera.GetWidth(), camera.GetHeight(), camera.GetNear(), camera.GetFar()); + //camera.perspProjMatrix = SHMatrix::OrthographicLH(9.0f, 9.0f, 0.1f, 20.0f); + camera.orthoProjMatrix = SHMatrix::OrthographicRH(camera.GetWidth(), camera.GetHeight(), camera.GetNear(), camera.GetFar()); + //camera.perspProjMatrix = SHMatrix::OrthographicLH(4.0f, 4.0f, 0.1f, 200.0f); //camera.projMatrix.Transpose(); camera.dirtyProj = false; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 64fc2431..14326b93 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -283,6 +283,7 @@ namespace SHADE "Albedo", "Scene", "SSAO Blur", + "Position World Space" }, { SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS .data()}); @@ -290,7 +291,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE SUBPASS INIT */ /*-----------------------------------------------------------------------*/ - auto deferredCompositeCompute = deferredCompositeNode->AddNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_COMPUTE.data(), deferredCompositeShader, {"Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Scene"}, {}, SHLightingSubSystem::MAX_SHADOWS); + auto deferredCompositeCompute = deferredCompositeNode->AddNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_COMPUTE.data(), deferredCompositeShader, {"Position", "Normals", "Albedo", "Light Layer Indices", "SSAO Blur", "Position World Space", "Scene"}, {}, SHLightingSubSystem::MAX_SHADOWS); deferredCompositeCompute->AddPreComputeFunction([=](Handle cmdBuffer, uint32_t frameIndex) { lightingSubSystem->PrepareShadowMapsForRead(cmdBuffer); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index c3ba7ec3..31f95921 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -395,7 +395,8 @@ namespace SHADE switch (lightComp->GetLightData().type) { case SH_LIGHT_TYPE::DIRECTIONAL: - return SHMatrix::Transpose (SHMatrix::LookAtLH(/*lightComp->GetLightData().position*/SHVec3(1.27862f, 4.78952f, 4.12811f), SHVec3(-0.280564f, -0.66262f, -0.69422f), SHVec3(0.0f, -1.0f, 0.0f))); + return SHMatrix::Transpose(SHMatrix::LookAtLH(lightComp->GetLightData().position, lightComp->GetLightData().direction, SHVec3(0.0f, -1.0f, 0.0f))); + //return SHMatrix::Transpose(SHMatrix::LookAtLH(/*lightComp->GetLightData().position*/SHVec3(1.27862f, 4.78952f, 4.12811f), SHVec3(-0.280564f, -0.66262f, -0.69422f), SHVec3(0.0f, -1.0f, 0.0f))); case SH_LIGHT_TYPE::POINT: return {}; case SH_LIGHT_TYPE::SPOT: @@ -517,7 +518,7 @@ namespace SHADE if (auto renderer = light.GetRenderer()) { //SHMatrix orthoMatrix = SHMatrix::OrthographicRH() - renderer->UpdateDataManual(frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(9.0f, 9.0f, 0.1f, 20.0f)); + renderer->UpdateDataManual(frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(5.0f, 5.0f, 0.1f, 20.0f)); } auto enumValue = SHUtilities::ConvertEnum(light.GetLightData().type); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp index 6d7e6104..a5dd929c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp @@ -17,7 +17,7 @@ namespace SHADE SHPipelineLayoutParams params { - .shaderModules = std::move (modules), + .shaderModules = std::move(modules), .predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING).descSetLayouts }; @@ -35,6 +35,7 @@ namespace SHADE auto const& subpassColorReferences = subpass->GetColorAttachmentReferences(); colorBlendState.attachments.reserve(subpassColorReferences.size()); + for (auto& att : subpassColorReferences) { colorBlendState.attachments.push_back(vk::PipelineColorBlendAttachmentState