From e9dee89b170b88a8ef5eadec5ed82453432c37ea Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Fri, 10 Mar 2023 16:47:19 +0800 Subject: [PATCH 1/3] Accommodated animation when shadows are in the scene --- Assets/Shaders/ShadowMapAnim_VS.glsl | 37 ++++++++++++ Assets/Shaders/ShadowMapAnim_VS.shshaderb | Bin 0 -> 2025 bytes .../Shaders/ShadowMapAnim_VS.shshaderb.shmeta | 3 + Assets/Shaders/ShinyHighlight_VS.glsl | 3 - .../MiddleEnd/Batching/SHSuperBatch.cpp | 11 +++- .../MiddleEnd/Batching/SHSuperBatch.h | 2 +- .../GlobalData/SHGraphicsPredefinedData.cpp | 17 ++++++ .../GlobalData/SHGraphicsPredefinedData.h | 4 ++ .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 55 +++++++++++------- .../MiddleEnd/Interface/SHGraphicsSystem.h | 2 + .../src/Graphics/RenderGraph/SHSubpass.cpp | 8 +-- .../src/Graphics/RenderGraph/SHSubpass.h | 9 ++- 12 files changed, 117 insertions(+), 34 deletions(-) create mode 100644 Assets/Shaders/ShadowMapAnim_VS.glsl create mode 100644 Assets/Shaders/ShadowMapAnim_VS.shshaderb create mode 100644 Assets/Shaders/ShadowMapAnim_VS.shshaderb.shmeta diff --git a/Assets/Shaders/ShadowMapAnim_VS.glsl b/Assets/Shaders/ShadowMapAnim_VS.glsl new file mode 100644 index 00000000..f5f9ab4e --- /dev/null +++ b/Assets/Shaders/ShadowMapAnim_VS.glsl @@ -0,0 +1,37 @@ +#version 450 +#extension GL_KHR_vulkan_glsl : enable + +//#include "ShaderDescriptorDefinitions.glsl" + + +layout(location = 0) in vec3 aVertexPos; +layout(location = 4) in mat4 worldTransform; +layout(location = 9) in uvec4 aBoneIndices; +layout(location = 10) in vec4 aBoneWeights; +layout(location = 11) in uint firstBoneIndex; + +layout(set = 1, binding = 0) uniform CameraData +{ + vec4 position; + mat4 vpMat; + mat4 viewMat; + mat4 projMat; +} cameraData; + +layout (std430, set = 2, binding = 1) buffer AnimBoneMatrices +{ + mat4 data[]; +} BoneMatrices; + +void main() +{ + // // Compute bone matrix + // mat4 boneMatrix = BoneMatrices.data[firstBoneIndex + aBoneIndices[0]] * aBoneWeights[0]; + // boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[1]] * aBoneWeights[1]; + // boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[2]] * aBoneWeights[2]; + // boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[3]] * aBoneWeights[3]; + + // clip space for rendering + gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f); + // gl_Position = cameraData.vpMat * worldTransform * boneMatrix * vec4 (aVertexPos, 1.0f); +} \ No newline at end of file diff --git a/Assets/Shaders/ShadowMapAnim_VS.shshaderb b/Assets/Shaders/ShadowMapAnim_VS.shshaderb new file mode 100644 index 0000000000000000000000000000000000000000..96c45e4742177cee622935fbe17c8524f09a8178 GIT binary patch literal 2025 zcmZ9LYflqF6o!{e3!>aaE-GLFub_z6m>4ezrkK=#!RW_k(=Iq>yKS}$sGs}^>QC~Q z_%r-s;`{8(G#jQlJ@dZjoH>`7?fWwn3YHh!^ z-p!ip4fP*X9Mxl!MD?agqefQG@_o3NnksQXG*wH$ipnS zhm&?1H{YjW(miOWEn5?J6WZ};7I5YKuEJOCBzluHO(PO(dG0UgKSt*8Q`Y0T(*u)s zGZ(|8OPU#vWHT`>Xw{bbv#2|NK(aUUN!au63!nDgk*|GOyhFP@$9&+>o?||6%*1o- z;dmcaS=i%;-OqnTn6)D>IL<8P*!qC+nK;Gq`B=`zac(gVOx&Kt=Yu;PM~%feFmXR5 zJ`T>u(Fb*MR#i1~=gSi6^ms{o7TAA>b_Rp_H_6?zu=9O_&p6CogGU_Zj={_h|GUy< z$x8_{+mL4Y9z3Q87Cm^b*aIAWaVGaq556ZbJhxxAI$TKEgk#H_~z~d6uobZG+ z=TaAWxHmroYzTSIOVby2@_@NlIDhU1?a71xw6pp6IcEbC59Z$SXFl`N^h@2uFGyp9 z#~;ic!;#O=HVD4I!2h~BOnBf%(^Lr;BX1C-xsUElNIC}DaD~_YiJx!PST$K=yKlX~` fr_RN8O+tQr=z)8=A>mE(?w+elFn<3uy(g0YL9(8# literal 0 HcmV?d00001 diff --git a/Assets/Shaders/ShadowMapAnim_VS.shshaderb.shmeta b/Assets/Shaders/ShadowMapAnim_VS.shshaderb.shmeta new file mode 100644 index 00000000..e31f63b1 --- /dev/null +++ b/Assets/Shaders/ShadowMapAnim_VS.shshaderb.shmeta @@ -0,0 +1,3 @@ +Name: ShadowMapAnim_VS +ID: 39393999 +Type: 2 diff --git a/Assets/Shaders/ShinyHighlight_VS.glsl b/Assets/Shaders/ShinyHighlight_VS.glsl index 483af1f0..044a2d7a 100644 --- a/Assets/Shaders/ShinyHighlight_VS.glsl +++ b/Assets/Shaders/ShinyHighlight_VS.glsl @@ -7,9 +7,6 @@ layout(location = 2) in vec3 aNormal; layout(location = 3) in vec3 aTangent; layout(location = 4) in mat4 worldTransform; layout(location = 8) in uvec2 integerData; -layout(location = 9) in uvec4 aBoneIndices; -layout(location = 10) in vec4 aBoneWeights; -layout(location = 11) in uint firstBoneIndex; layout(location = 0) out struct { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp index f8298716..5a2a079c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp @@ -17,6 +17,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h" #include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Graphics/Descriptors/SHVkDescriptorPool.h" +#include "Graphics/Commands/SHVkCommandBuffer.h" namespace SHADE { @@ -108,11 +109,19 @@ namespace SHADE } } - void SHSuperBatch::Draw(Handle cmdBuffer, uint32_t frameIndex, bool bindBatchPipeline /*= true*/) noexcept + void SHSuperBatch::Draw(Handle cmdBuffer, uint32_t frameIndex, bool bindBatchPipeline /*= true*/, Handle nonAnimPipeline/* = {}*/, Handle animPipeline/* = {}*/) noexcept { // Build all batches for (auto& batch : batches) { + if (!bindBatchPipeline) + { + if (batch.IsAnimated()) + cmdBuffer->BindPipeline(animPipeline); + else + cmdBuffer->BindPipeline(nonAnimPipeline); + } + batch.Draw(cmdBuffer, frameIndex, bindBatchPipeline); } } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.h b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.h index 4d831b9c..3ef9fc5e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.h @@ -57,7 +57,7 @@ namespace SHADE void Clear() noexcept; void UpdateBuffers(uint32_t frameIndex, Handle descPool); void Build(Handle device, Handle descPool, uint32_t frameIndex) noexcept; - void Draw(Handle cmdBuffer, uint32_t frameIndex, bool bindBatchPipeline = true) noexcept; + void Draw(Handle cmdBuffer, uint32_t frameIndex, bool bindBatchPipeline = true, Handle nonAnimPipeline = {}, Handle animPipeline = {}) noexcept; /*-----------------------------------------------------------------------------*/ /* Getter Functions */ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp index 91ec0cea..ae2b6f35 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp @@ -14,6 +14,7 @@ namespace SHADE std::vector> SHGraphicsPredefinedData::predefinedLayouts; SHVertexInputState SHGraphicsPredefinedData::defaultVertexInputState; SHVertexInputState SHGraphicsPredefinedData::shadowMapVertexInputState; + SHVertexInputState SHGraphicsPredefinedData::shadowMapAnimVertexInputState; std::vector SHGraphicsPredefinedData::perSystemData; @@ -333,6 +334,17 @@ namespace SHADE shadowMapVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D)}); shadowMapVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::MAT_4D) }, 4, 4); // Transform at binding 4 - 7 (4 slots) + + shadowMapAnimVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); + shadowMapAnimVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::MAT_4D) }, 4, 4); // Transform at binding 4 - 7 (4 slots) + shadowMapAnimVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::UINT32_4D) }, 9, 9); // Attribute bone indices at index 5 + shadowMapAnimVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_4D) }, 10, 10); // Attribute bone weights at index 6 + shadowMapAnimVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::UINT32_1D) }, 11, 11); // Instance bone matrix first index at index 7 + + + //shadowMapAnimVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); + //shadowMapAnimVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::MAT_4D) }, 4, 4); // Transform at binding 4 - 7 (4 slots) + } void SHGraphicsPredefinedData::Init(Handle logicalDevice) noexcept @@ -368,6 +380,11 @@ namespace SHADE return shadowMapVertexInputState; } + SHVertexInputState const& SHGraphicsPredefinedData::GetShadowMapAnimViState(void) noexcept + { + return shadowMapAnimVertexInputState; + } + SHGraphicsPredefinedData::PerSystem const& SHGraphicsPredefinedData::GetSystemData(SystemType systemType) noexcept { return perSystemData[static_cast(systemType)]; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h index 4fbf06c1..051dce0d 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h @@ -67,6 +67,9 @@ namespace SHADE //! vertex input state for shadow mapping static SHVertexInputState shadowMapVertexInputState; + //! vertex input state for shadow mapping + static SHVertexInputState shadowMapAnimVertexInputState; + //! Predefined data for each type of system static std::vector perSystemData; @@ -101,6 +104,7 @@ namespace SHADE static std::vector> GetPredefinedDescSetLayouts (SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes types) noexcept; static SHVertexInputState const& GetDefaultViState (void) noexcept; static SHVertexInputState const& GetShadowMapViState (void) noexcept; + static SHVertexInputState const& GetShadowMapAnimViState (void) noexcept; static PerSystem const& GetSystemData (SystemType systemType) noexcept; static SHDescriptorMappings::MapType const& GetMappings (SystemType systemType) noexcept; //static PerSystem const& GetBatchingSystemData(void) noexcept; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index bc50d0a7..69aa4188 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -128,8 +128,9 @@ namespace SHADE SHFreetypeInstance::Init(); - SHAssetManager::CompileAsset("../../Assets/Shaders/DeferredComposite_CS.glsl", false); - //SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMap_FS.glsl", false); + //SHAssetManager::CompileAsset("../../Assets/Shaders/DeferredComposite_CS.glsl", false); + //SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMap_VS.glsl", false); + //SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMapAnim_VS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMap_FS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Shaders/SSAO_CS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Shaders/SSAOBlur_CS.glsl", false); @@ -145,24 +146,25 @@ namespace SHADE //SHAssetManager::CompileAsset("../../Assets/Shaders/Anim_VS.glsl", false); // Load Built In Shaders - static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet(VS_DEFAULT); - static constexpr AssetID VS_ANIM = 47911992; animtVertShader = SHResourceManager::LoadOrGet(VS_ANIM); - static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet(FS_DEFAULT); - static constexpr AssetID VS_DEBUG = 48002439; debugVertShader = SHResourceManager::LoadOrGet(VS_DEBUG); - static constexpr AssetID FS_DEBUG = 36671027; debugFragShader = SHResourceManager::LoadOrGet(FS_DEBUG); - static constexpr AssetID VS_DEBUG_MESH = 42127043; debugMeshVertShader = SHResourceManager::LoadOrGet(VS_DEBUG_MESH); - static constexpr AssetID CS_COMPOSITE = 45072428; deferredCompositeShader = SHResourceManager::LoadOrGet(CS_COMPOSITE); - static constexpr AssetID SSAO = 38430899; ssaoShader = SHResourceManager::LoadOrGet(SSAO); - static constexpr AssetID SSAO_BLUR = 39760835; ssaoBlurShader = SHResourceManager::LoadOrGet(SSAO_BLUR); - static constexpr AssetID TEXT_VS = 39816727; textVS = SHResourceManager::LoadOrGet(TEXT_VS); - static constexpr AssetID TEXT_FS = 38024754; textFS = SHResourceManager::LoadOrGet(TEXT_FS); - static constexpr AssetID RENDER_SC_VS = 48082949; renderToSwapchainVS = SHResourceManager::LoadOrGet(RENDER_SC_VS); - static constexpr AssetID RENDER_SC_FS = 36869006; renderToSwapchainFS = SHResourceManager::LoadOrGet(RENDER_SC_FS); - static constexpr AssetID SHADOW_MAP_VS = 44646107; shadowMapVS = SHResourceManager::LoadOrGet(SHADOW_MAP_VS); - static constexpr AssetID SHADOW_MAP_FS = 45925790; shadowMapFS = SHResourceManager::LoadOrGet(SHADOW_MAP_FS); - static constexpr AssetID TRAJECTORY_VS = 41042628; trajectoryVS = SHResourceManager::LoadOrGet(TRAJECTORY_VS); - static constexpr AssetID TRAJECTORY_FS = 45635685; trajectoryFS = SHResourceManager::LoadOrGet(TRAJECTORY_FS); - static constexpr AssetID SHADOW_BLUR_CS = 38004013; shadowMapBlurCS = SHResourceManager::LoadOrGet(SHADOW_BLUR_CS); + static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet(VS_DEFAULT); + static constexpr AssetID VS_ANIM = 47911992; animtVertShader = SHResourceManager::LoadOrGet(VS_ANIM); + static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet(FS_DEFAULT); + static constexpr AssetID VS_DEBUG = 48002439; debugVertShader = SHResourceManager::LoadOrGet(VS_DEBUG); + static constexpr AssetID FS_DEBUG = 36671027; debugFragShader = SHResourceManager::LoadOrGet(FS_DEBUG); + static constexpr AssetID VS_DEBUG_MESH = 42127043; debugMeshVertShader = SHResourceManager::LoadOrGet(VS_DEBUG_MESH); + static constexpr AssetID CS_COMPOSITE = 45072428; deferredCompositeShader = SHResourceManager::LoadOrGet(CS_COMPOSITE); + static constexpr AssetID SSAO = 38430899; ssaoShader = SHResourceManager::LoadOrGet(SSAO); + static constexpr AssetID SSAO_BLUR = 39760835; ssaoBlurShader = SHResourceManager::LoadOrGet(SSAO_BLUR); + static constexpr AssetID TEXT_VS = 39816727; textVS = SHResourceManager::LoadOrGet(TEXT_VS); + static constexpr AssetID TEXT_FS = 38024754; textFS = SHResourceManager::LoadOrGet(TEXT_FS); + static constexpr AssetID RENDER_SC_VS = 48082949; renderToSwapchainVS = SHResourceManager::LoadOrGet(RENDER_SC_VS); + static constexpr AssetID RENDER_SC_FS = 36869006; renderToSwapchainFS = SHResourceManager::LoadOrGet(RENDER_SC_FS); + static constexpr AssetID SHADOW_MAP_VS = 44646107; shadowMapVS = SHResourceManager::LoadOrGet(SHADOW_MAP_VS); + static constexpr AssetID SHADOW_MAP_ANIM_VS = 39393999; shadowMapAnimVS = SHResourceManager::LoadOrGet(SHADOW_MAP_ANIM_VS); + static constexpr AssetID SHADOW_MAP_FS = 45925790; shadowMapFS = SHResourceManager::LoadOrGet(SHADOW_MAP_FS); + static constexpr AssetID TRAJECTORY_VS = 41042628; trajectoryVS = SHResourceManager::LoadOrGet(TRAJECTORY_VS); + static constexpr AssetID TRAJECTORY_FS = 45635685; trajectoryFS = SHResourceManager::LoadOrGet(TRAJECTORY_FS); + static constexpr AssetID SHADOW_BLUR_CS = 38004013; shadowMapBlurCS = SHResourceManager::LoadOrGet(SHADOW_BLUR_CS); } @@ -919,10 +921,19 @@ namespace SHADE SHGraphicsPredefinedData::SystemType::BATCHING, SHGraphicsPredefinedData::GetShadowMapViState(), rasterState ); + + tempLibrary.CreateGraphicsPipelines + ( + { shadowMapAnimVS, shadowMapFS }, shadowMapNode->GetRenderpass(), shadowMapDrawSubpass, + SHGraphicsPredefinedData::SystemType::BATCHING_ANIM, + SHGraphicsPredefinedData::GetShadowMapAnimViState(), rasterState + ); + shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, shadowMapFS, shadowMapDrawSubpass }); + shadowMapAnimPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapAnimVS, shadowMapFS, shadowMapDrawSubpass }); } - shadowMapDrawSubpass->AddCompanionSubpass(gBufferWriteSubpass, shadowMapPipeline); // set companion subpass and pipeline - shadowMapDrawSubpass->AddCompanionSubpass(gBufferWriteVfxSubpass, shadowMapPipeline); // set companion subpass and pipeline + shadowMapDrawSubpass->AddCompanionSubpass(gBufferWriteSubpass, shadowMapPipeline, shadowMapAnimPipeline); // set companion subpass and pipeline + shadowMapDrawSubpass->AddCompanionSubpass(gBufferWriteVfxSubpass, shadowMapPipeline, shadowMapAnimPipeline); // set companion subpass and pipeline // add the shadow map and the blurred version to the lighting system uint32_t const NEW_SHADOW_MAP_INDEX = lightingSubSystem->AddShadowMap(renderGraph->GetRenderGraphResource(shadowMapBlurredResourceName), EVENT_DATA->lightEntity); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 68752a6e..e674efb6 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -479,6 +479,7 @@ namespace SHADE Handle renderToSwapchainVS; Handle renderToSwapchainFS; Handle shadowMapVS; + Handle shadowMapAnimVS; Handle shadowMapFS; Handle trajectoryVS; Handle trajectoryFS; @@ -499,6 +500,7 @@ namespace SHADE Handle debugDrawFilledPipeline; Handle debugDrawFilledDepthPipeline; Handle shadowMapPipeline; // initialized only when a shadow map is needed + Handle shadowMapAnimPipeline; // initialized only when a shadow map is needed Handle genericAndTextureDescSet; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index ca13155d..87b3fc10 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -280,8 +280,8 @@ namespace SHADE for (auto& companion : companionSubpasses) { // if not bind pipeline for companion and and execute draw command - commandBuffer->BindPipeline(companion.pipeline); - companion.subpass->superBatch->Draw(commandBuffer, frameIndex, false); + //commandBuffer->BindPipeline(companion.nonAnimPipeline); + companion.subpass->superBatch->Draw(commandBuffer, frameIndex, false, companion.nonAnimPipeline, companion.animPipeline); } } } @@ -528,9 +528,9 @@ namespace SHADE subpassIndex = index; } - void SHSubpass::AddCompanionSubpass(Handle companion, Handle pipeline) noexcept + void SHSubpass::AddCompanionSubpass(Handle companion, Handle nonAnimPipeline, Handle animPipeline) noexcept { - companionSubpasses.push_back(CompanionSubpass{companion, pipeline}); + companionSubpasses.push_back(CompanionSubpass{companion, nonAnimPipeline, animPipeline}); //companionSubpass.companion = companion; //companionSubpass.pipeline = pipeline; } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h index 7f843773..f13e0871 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h @@ -35,8 +35,11 @@ namespace SHADE // subpass whose data will be borrowed to draw Handle subpass; - // Pipeline that will be used for all the draw calls from all batches of the companion subpass - Handle pipeline; + // Pipeline that will be used for all the draw calls from all batches (that render without animation data) of the companion subpass + Handle nonAnimPipeline; + + // Pipeline that will be used for all the draw calls from all batches (that render with animation data) of the companion subpass + Handle animPipeline; }; private: @@ -167,7 +170,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* PUBLIC SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ - void AddCompanionSubpass (Handle companion, Handle pipeline) noexcept; + void AddCompanionSubpass (Handle companion, Handle nonAnimPipeline, Handle animPipeline) noexcept; Handle GetParentNode(void) const noexcept; SHSubPassIndex GetIndex() const noexcept; From 801da75d877b22d34446aa695d4c7167484772e6 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Fri, 10 Mar 2023 18:37:28 +0800 Subject: [PATCH 2/3] Fixed shadows for animation --- Assets/Scenes/Level1.shade | 26 ++++++++++++++++-- Assets/Shaders/Silhouette_VS.glsl | 15 +++++++++- Assets/Shaders/Silhouette_VS.shshaderb | Bin 4133 -> 6053 bytes .../GlobalData/SHGraphicsPredefinedData.cpp | 6 ++-- .../src/Graphics/RenderGraph/SHSubpass.cpp | 2 +- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Assets/Scenes/Level1.shade b/Assets/Scenes/Level1.shade index ca74f938..7221f55d 100644 --- a/Assets/Scenes/Level1.shade +++ b/Assets/Scenes/Level1.shade @@ -2419,7 +2419,7 @@ Components: Transform Component: Translate: {x: 0, y: 0, z: 0} - Rotate: {x: -7.50001717, y: 1.39999998, z: -3.50001717} + Rotate: {x: -1.48352981, y: 1.39999998, z: -3.50001717} Scale: {x: 1, y: 1, z: 1} IsActive: true Renderable Component: @@ -6858,8 +6858,8 @@ NumberOfChildren: 0 Components: Transform Component: - Translate: {x: 2.13981342, y: 0.0490087792, z: -1.96055627} - Rotate: {x: 0, y: -1.53675354, z: 0} + Translate: {x: 2.13981342, y: 0.0490087792, z: -1.86932743} + Rotate: {x: -0, y: -1.53675354, z: 0} Scale: {x: 1, y: 1, z: 1} IsActive: true Renderable Component: @@ -8216,4 +8216,24 @@ Hovered: false Clicked: false IsActive: true + Scripts: ~ +- EID: 503 + Name: DirectionalLight + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: -0.407547206, y: 3.60323787, z: 2.62217617} + Rotate: {x: -0, y: 0, z: -0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + Light Component: + Position: {x: 0.300000012, y: 0, z: 0} + Type: Directional + Direction: {x: -1.15900004, y: 4.79300022, z: -0.994000018} + Color: {x: 1, y: 1, z: 1, w: 1} + Layer: 4294967295 + Strength: 0.800000012 + Casting Shadows: true + IsActive: true Scripts: ~ \ No newline at end of file diff --git a/Assets/Shaders/Silhouette_VS.glsl b/Assets/Shaders/Silhouette_VS.glsl index 1b45c333..a7fe585d 100644 --- a/Assets/Shaders/Silhouette_VS.glsl +++ b/Assets/Shaders/Silhouette_VS.glsl @@ -40,6 +40,12 @@ layout(set = 1, binding = 0) uniform CameraData mat4 projMat; } cameraData; +layout (std430, set = 2, binding = 1) buffer AnimBoneMatrices +{ + mat4 data[]; +} BoneMatrices; + + void main() { Out2.materialIndex = gl_InstanceIndex; @@ -63,6 +69,13 @@ void main() Out.normal.rgb = transposeInv * aNormal.rgb; Out.normal.rgb = normalize (Out.normal.rgb); + // Compute bone matrix + mat4 boneMatrix = BoneMatrices.data[firstBoneIndex + aBoneIndices[0]] * aBoneWeights[0]; + boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[1]] * aBoneWeights[1]; + boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[2]] * aBoneWeights[2]; + boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[3]] * aBoneWeights[3]; + // clip space for rendering - gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f); + gl_Position = cameraData.vpMat * worldTransform * boneMatrix * vec4 (aVertexPos, 1.0f); + // gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f); } \ No newline at end of file diff --git a/Assets/Shaders/Silhouette_VS.shshaderb b/Assets/Shaders/Silhouette_VS.shshaderb index 1bb76ec42331e3ece2cf26e15e72fbbb613e2633..6318555888e0c1f04b668c241c14b5ab73baa8b8 100644 GIT binary patch literal 6053 zcmZ9O`FmVd8OLv$WQr6h1zJ#`&ZKCotp&BzDpDF+48_m{TZ${;lDQ2RCo^F(NoieZ za9^Rg3kbOHJMJRl0x6*)(sf zoQj-|oP%sZo`-Blu0dXnEFwpdCFBJ1Z)A{vE0`Z6=@1#l#;3+6CdS6Enwp-Qo0{(( zX=PKbyq!%o^KLfX%NH~KPO13i?djG+v+6L6N42hD);NVV9JOTSGM-I)SvOBxd)v+I z_QGanPbEpRyt(XaeXV@vmfm=JBG?ddGiVjC{b zByab!nXJ1f?WHiau!CA)wO%5MxXpudR=f0*@bv!aUWw3p}Pl%dkC(&2RZj;4c=e(5NoKrhp54OYz_8P zfA6pQQ%ZfQ)cwx6p7+n8zau#F$vFq-nsU|>oLH`Zmj;V`QJZ(qwe>lhisc(<>f*IT zc|LW-b=2Lrx??@{c?b28@7sooy_iGWWyH8Q_anEt%o+Qsqn`$Ee)H(B?wyy@zM9!s z?Ge8Qto>ZfJ5<^e=q ze|6uBoONByTu035x|c9F5P4_CJkMoz@7m3y?mLq+&o<_Isq23!cmR>tU)^^o=ULU6 zcOXe}>b_$+?c>bGYxjKjF}t>$_6cUsS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iIPZM7qW4sj$#M#_63=2UPn>wE*wd7Wr@e9x*kV%kQ*H~V15X2Gq`R@680)Fg zLn)Ar0~%C1H~gE<*infy2gougfobld{xhHqR2$bFqs!_$s;_cRTF)a-dI|0T-KT)Q zfcXd6sh4AZ!>Y+w9=$LcSf&D(abPA6NbA8>*MU6T>)&TLhHkFmM(e!oE388>2PQ#< z*h}~ake}!y_HV!+&ZvG2l##E@B76dt!ACM>_$QF3m3Y6{%VVVd|K@3Irr;`9*8FEc k4Rk>D6>v*q)y{ziP)3(ngCn5F)E~XZlS(W1$fs7o6FTo%h5!Hn diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp index ae2b6f35..3f312532 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp @@ -337,9 +337,9 @@ namespace SHADE shadowMapAnimVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); shadowMapAnimVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::MAT_4D) }, 4, 4); // Transform at binding 4 - 7 (4 slots) - shadowMapAnimVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::UINT32_4D) }, 9, 9); // Attribute bone indices at index 5 - shadowMapAnimVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_4D) }, 10, 10); // Attribute bone weights at index 6 - shadowMapAnimVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::UINT32_1D) }, 11, 11); // Instance bone matrix first index at index 7 + shadowMapAnimVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::UINT32_4D) }, 6, 9); // Attribute bone indices at index 5 + shadowMapAnimVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_4D) }, 7, 10); // Attribute bone weights at index 6 + shadowMapAnimVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::UINT32_1D) }, 8, 11); // Instance bone matrix first index at index 7 //shadowMapAnimVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index 87b3fc10..7eccbc52 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -496,7 +496,7 @@ namespace SHADE { if (!dummyPipelineLayout) { - auto const& batchingSystemData = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING); + auto const& batchingSystemData = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING_ANIM); std::vector newLayouts = batchingSystemData.descSetLayouts; if (inputDescriptorLayout) { From 1d16bd274412d0dcaa70407cea0e73a3780593f3 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Fri, 10 Mar 2023 19:22:50 +0800 Subject: [PATCH 3/3] Fixed more shadows --- Assets/Shaders/ShadowMapAnim_VS.glsl | 12 +++--- Assets/Shaders/ShadowMapAnim_VS.shshaderb | Bin 2025 -> 3749 bytes .../Graphics/MiddleEnd/Batching/SHBatch.cpp | 36 +++++++++++++----- .../GlobalData/SHGraphicsPredefinedData.cpp | 3 +- .../Graphics/RenderGraph/SHRenderGraph.cpp | 2 +- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/Assets/Shaders/ShadowMapAnim_VS.glsl b/Assets/Shaders/ShadowMapAnim_VS.glsl index f5f9ab4e..17b135e0 100644 --- a/Assets/Shaders/ShadowMapAnim_VS.glsl +++ b/Assets/Shaders/ShadowMapAnim_VS.glsl @@ -26,12 +26,12 @@ layout (std430, set = 2, binding = 1) buffer AnimBoneMatrices void main() { // // Compute bone matrix - // mat4 boneMatrix = BoneMatrices.data[firstBoneIndex + aBoneIndices[0]] * aBoneWeights[0]; - // boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[1]] * aBoneWeights[1]; - // boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[2]] * aBoneWeights[2]; - // boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[3]] * aBoneWeights[3]; + mat4 boneMatrix = BoneMatrices.data[firstBoneIndex + aBoneIndices[0]] * aBoneWeights[0]; + boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[1]] * aBoneWeights[1]; + boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[2]] * aBoneWeights[2]; + boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[3]] * aBoneWeights[3]; // clip space for rendering - gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f); - // gl_Position = cameraData.vpMat * worldTransform * boneMatrix * vec4 (aVertexPos, 1.0f); + // gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f); + gl_Position = cameraData.vpMat * worldTransform * boneMatrix * vec4 (aVertexPos, 1.0f); } \ No newline at end of file diff --git a/Assets/Shaders/ShadowMapAnim_VS.shshaderb b/Assets/Shaders/ShadowMapAnim_VS.shshaderb index 96c45e4742177cee622935fbe17c8524f09a8178..047f485b41367464e6b0a86d3dd8d80f77753127 100644 GIT binary patch literal 3749 zcmZ9MS(_785QckTGJ^{sB8v)R2Ha6Z1w@f$7%-rN41(YuLefBECJ9Lx7DWa(^vdPh zU*oUx#^>>UJ6+JyJjMCytFO+fQ*|a|f2~ULZ~3yVlSwj`Je;gdejQQCnq(PFl01@3 z3assUP%H1F#^mcWs%s?%!|x z-aMiQF&{PFH}X6;dSLI=xop{MYDzcgYUSNe-}fbF-RoG5 zMV;%5n7n#@-=BKVQ@auKbN@}O*5+OGpJ7$&UCr08Vsgf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YiJx!PST$K=yKlX~` fr_RN8O+tQr=z)8=A>mE(?w+elFn<3uy(g0YL9(8# diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index 32a4fa76..4aa33de5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -726,16 +726,34 @@ namespace SHADE cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::BONE_MATRIX_FIRST_INDEX, transformDataBuffer[frameIndex], 0); } - auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); - if (instanceDataDescSet[frameIndex]) + if (IsAnimated()) { - cmdBuffer->BindDescriptorSet - ( - instanceDataDescSet[frameIndex], - SH_PIPELINE_TYPE::GRAPHICS, - descMappings.at(SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH), - dynamicOffset - ); + auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING_ANIM); + if (instanceDataDescSet[frameIndex]) + { + cmdBuffer->BindDescriptorSet + ( + instanceDataDescSet[frameIndex], + SH_PIPELINE_TYPE::GRAPHICS, + descMappings.at(SHPredefinedDescriptorTypes::PER_INSTANCE_ANIM_BATCH), + dynamicOffset + ); + } + } + else + { + auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); + if (instanceDataDescSet[frameIndex]) + { + cmdBuffer->BindDescriptorSet + ( + instanceDataDescSet[frameIndex], + SH_PIPELINE_TYPE::GRAPHICS, + descMappings.at(SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH), + dynamicOffset + ); + } + } cmdBuffer->DrawMultiIndirect(drawDataBuffer[frameIndex], static_cast(drawData.size())); cmdBuffer->EndLabeledSegment(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp index 3f312532..76d34ff7 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp @@ -37,7 +37,8 @@ namespace SHADE {SHPredefinedDescriptorTypes::STATIC_DATA, 0}, {SHPredefinedDescriptorTypes::CAMERA, 1}, {SHPredefinedDescriptorTypes::PER_INSTANCE_ANIM_BATCH, 2}, - }); + {SHPredefinedDescriptorTypes::RENDER_GRAPH_RESOURCE, 3}, + }); perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descMappings.AddMappings ({ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index c44c9464..b9ca9d56 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -497,7 +497,7 @@ namespace SHADE } // get target node - auto targetNode = nodes.begin() + nodeIndexing.at(nodeToAddAfter); + auto targetNode = nodes.begin() + nodeIndexing.at(nodeToAddAfter) + 1; auto node = nodes.insert(targetNode, renderGraphStorage->resourceHub->Create(nodeName, renderGraphStorage, std::move(descInitParams), std::vector>(), true)); ReindexNodes ();