diff --git a/Assets/Shaders/DeferredComposite_CS.glsl b/Assets/Shaders/DeferredComposite_CS.glsl index e73ea9eb..2402d4f8 100644 --- a/Assets/Shaders/DeferredComposite_CS.glsl +++ b/Assets/Shaders/DeferredComposite_CS.glsl @@ -7,6 +7,7 @@ struct DirectionalLightStruct uint cullingMask; vec4 diffuseColor; mat4 pvMatrix; + uint shadowData; }; struct AmbientLightStruct @@ -65,6 +66,8 @@ void main() vec3 fragColor = vec3 (0.0f); + vec4 shadowMapColor = vec4 (1.0f); + for (int i = 0; i < lightCounts.directionalLights; ++i) { if ((lightLayer & DirLightData.dLightData[i].cullingMask) != 0) @@ -77,6 +80,13 @@ void main() // Calculate the fragment color fragColor += DirLightData.dLightData[i].diffuseColor.rgb * diffuseStrength.rrr * pixelDiffuse; + + if ((DirLightData.dLightData[i].shadowData & uint(1)) == 1) + { + // calculate shadow map here + vec2 texCoord = vec2 (gl_GlobalInvocationID.xy) / vec2 (imageSize (targetImage)); + shadowMapColor = texture (shadowMaps[0], texCoord).xxxx; + } } } @@ -95,6 +105,8 @@ 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)); } \ No newline at end of file diff --git a/Assets/Shaders/DeferredComposite_CS.shshaderb b/Assets/Shaders/DeferredComposite_CS.shshaderb index df956040..fc527efa 100644 Binary files a/Assets/Shaders/DeferredComposite_CS.shshaderb and b/Assets/Shaders/DeferredComposite_CS.shshaderb differ diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp index 3e504fb5..b425bc5f 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp +++ b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp @@ -198,6 +198,7 @@ namespace SHADE vk::PhysicalDeviceDescriptorIndexingFeatures descIndexingFeature{}; descIndexingFeature.descriptorBindingVariableDescriptorCount = true; descIndexingFeature.shaderSampledImageArrayNonUniformIndexing = true; + descIndexingFeature.descriptorBindingPartiallyBound = true; descIndexingFeature.runtimeDescriptorArray = true; // Prepare to create the device diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 1fadc7b1..eaf9b767 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -265,12 +265,6 @@ namespace SHADE // Add another pass to blur SSAO Handle ssaoBlurPass = gBufferNode->AddNodeCompute("SSAO Blur Step", ssaoBlurShader, { "SSAO", "SSAO Blur" }); - /*-----------------------------------------------------------------------*/ - /* SHADOW MAP PASS */ - /*-----------------------------------------------------------------------*/ - // Shadow map pass will have no resources bound at first. Lighting system will add resources to the node. - // It will initially also not have any subpasses since they will be added for each light that casts shadows. - //auto shadowMapPassNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data(), {}, {}); /*-----------------------------------------------------------------------*/ /* DEFERRED COMPOSITE NODE */ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 8a2fb3e3..bc9554c4 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -60,7 +60,15 @@ namespace SHADE // write view projection matrix if renderer is available auto lightRenderer = lightComp->GetRenderer(); if (lightRenderer) + { lightPtr->pvMatrix = lightRenderer->GetCPUCameraData().viewProjectionMatrix; + + // Boolean to cast shadows in first 8 bits (1 byte) + lightPtr->shadowData = lightData.castShadows; + + // Next 24 bits for shadow map index + lightPtr->shadowData |= (lightData.shadowMapIndex << 8); + } break; } case SH_LIGHT_TYPE::POINT: diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index 3cc5bac8..f3a98d14 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -44,6 +44,9 @@ namespace SHADE //! Matrix for world to projection from light's perspective SHMatrix pvMatrix; + //! Represents boolean for casting shadows in first byte and shadow map index in the other 3. + uint32_t shadowData; + }; // Represents how the data will be interpreted in GPU. we want to copy to a container of these before passing to GPU. @@ -62,8 +65,6 @@ namespace SHADE //! when a fragment is being evaluated, the shader will use the fragment's //! layer value to AND with the light's. If result is 1, do lighting calculations. uint32_t cullingMask; - - }; class SH_API SHLightingSubSystem diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp index d9ff07dd..6a6ef879 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp +++ b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipelineLayout.cpp @@ -205,7 +205,7 @@ namespace SHADE newBinding.DescriptorCount = SHVkDescriptorSetLayout::Binding::VARIABLE_DESCRIPTOR_UPPER_BOUND; // Set the flags for variable bindings - newBinding.flags = vk::DescriptorBindingFlagBits::eVariableDescriptorCount; + newBinding.flags = vk::DescriptorBindingFlagBits::eVariableDescriptorCount | vk::DescriptorBindingFlagBits::ePartiallyBound; } else {