diff --git a/Assets/Shaders/Anim_VS.glsl b/Assets/Shaders/Anim_VS.glsl new file mode 100644 index 00000000..c9aa64aa --- /dev/null +++ b/Assets/Shaders/Anim_VS.glsl @@ -0,0 +1,75 @@ +#version 450 +#extension GL_KHR_vulkan_glsl : enable + +//#include "ShaderDescriptorDefinitions.glsl" + + +layout(location = 0) in vec3 aVertexPos; +layout(location = 1) in vec2 aUV; +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 = 0) out struct +{ + vec4 vertPos; // location 0 + vec2 uv; // location = 1 + vec4 normal; // location = 2 + +} Out; + +// material stuff +layout(location = 3) out struct +{ + int materialIndex; + uint eid; + uint lightLayerIndex; + +} Out2; + +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() +{ + Out2.materialIndex = gl_InstanceIndex; + Out2.eid = integerData[0]; + Out2.lightLayerIndex = integerData[1]; + + // for transforming gBuffer position and normal data + mat4 modelViewMat = cameraData.viewMat * worldTransform; + + // gBuffer position will be in view space + Out.vertPos = modelViewMat * vec4(aVertexPos, 1.0f); + + // uvs for texturing in fragment shader + Out.uv = aUV; + + mat3 transposeInv = mat3 (transpose(inverse(modelViewMat))); + + // normals are also in view space + Out.normal.rgb = transposeInv * aNormal.rgb; + Out.normal.rgb = normalize (Out.normal.rgb); + + // Compute bone matrix + mat4 boneMatrix = BoneMatrices.data[aBoneIndices[0]] * aBoneWeights[0]; + boneMatrix += BoneMatrices.data[aBoneIndices[1]] * aBoneWeights[1]; + boneMatrix += BoneMatrices.data[aBoneIndices[2]] * aBoneWeights[2]; + boneMatrix += BoneMatrices.data[aBoneIndices[3]] * aBoneWeights[3]; + + // clip space for rendering + gl_Position = cameraData.vpMat * worldTransform * boneMatrix * vec4 (aVertexPos, 1.0f); +} \ No newline at end of file diff --git a/Assets/Shaders/Anim_VS.shshaderb b/Assets/Shaders/Anim_VS.shshaderb new file mode 100644 index 00000000..b1940e98 Binary files /dev/null and b/Assets/Shaders/Anim_VS.shshaderb differ diff --git a/Assets/Shaders/Anim_VS.shshaderb.shmeta b/Assets/Shaders/Anim_VS.shshaderb.shmeta new file mode 100644 index 00000000..e5c75fbe --- /dev/null +++ b/Assets/Shaders/Anim_VS.shshaderb.shmeta @@ -0,0 +1,3 @@ +Name: Anim_VS +ID: 47911992 +Type: 2 diff --git a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp index c50804d7..af77f17f 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MaterialInspector/SHMaterialInspector.cpp @@ -201,7 +201,7 @@ namespace SHADE // Get interface for the shader combination auto interface = fragShader->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface ( - mappings.at(SHPredefinedDescriptorTypes::MATERIALS), + mappings.at(SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH), SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA ); if (!interface) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index 44fc87b0..50fce74e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -420,7 +420,7 @@ namespace SHADE // - Material Properties Data const Handle SHADER_INFO = pipeline->GetPipelineLayout()->GetShaderBlockInterface ( - descMappings.at(SHPredefinedDescriptorTypes::MATERIALS), + descMappings.at(SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH), SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA, vk::ShaderStageFlagBits::eFragment ); @@ -581,7 +581,7 @@ namespace SHADE return; // Bind all required objects before drawing - static std::array dynamicOffset{ 0 }; + static std::array dynamicOffset{ 0U, static_cast(boneMatrixData.size() * sizeof(SHMatrix)) }; cmdBuffer->BeginLabeledSegment("SHBatch for Pipeline #" + std::to_string(pipeline.GetId().Data.Index)); cmdBuffer->BindPipeline(pipeline); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer[frameIndex], 0); @@ -594,7 +594,7 @@ namespace SHADE ( instanceDataDescSet[frameIndex], SH_PIPELINE_TYPE::GRAPHICS, - descMappings.at(SHPredefinedDescriptorTypes::MATERIALS), + descMappings.at(SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH), dynamicOffset ); } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp index 2d741f7f..bbd1a1b1 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.cpp @@ -23,17 +23,9 @@ namespace SHADE { perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descMappings.AddMappings ({ - {SHPredefinedDescriptorTypes::STATIC_DATA, 0}, - {SHPredefinedDescriptorTypes::CAMERA, 1}, - {SHPredefinedDescriptorTypes::MATERIALS, 2}, - }); - - perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING_ANIM)].descMappings.AddMappings - ({ - {SHPredefinedDescriptorTypes::STATIC_DATA, 0}, - {SHPredefinedDescriptorTypes::CAMERA, 1}, - {SHPredefinedDescriptorTypes::MATERIALS, 2}, - {SHPredefinedDescriptorTypes::BONES, 3}, + {SHPredefinedDescriptorTypes::STATIC_DATA, 0}, + {SHPredefinedDescriptorTypes::CAMERA, 1}, + {SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH, 2}, }); perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descMappings.AddMappings @@ -137,7 +129,14 @@ namespace SHADE .BindPoint = SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA, .DescriptorCount = 1, }; - Handle materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding }); + SHVkDescriptorSetLayout::Binding boneDataBinding + { + .Type = vk::DescriptorType::eStorageBufferDynamic, + .Stage = vk::ShaderStageFlagBits::eVertex, + .BindPoint = SHGraphicsConstants::DescriptorSetBindings::PER_INST_BONE_DATA, + .DescriptorCount = 1, + }; + Handle materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding, boneDataBinding }); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, materialDataPerInstanceLayout->GetVkHandle(), "[Descriptor Set Layout] Material Globals"); // font bitmap data (texture) @@ -185,15 +184,7 @@ namespace SHADE ( SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::STATIC_DATA | SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::CAMERA | - SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::MATERIALS - ); - - perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING_ANIM)].descSetLayouts = GetPredefinedDescSetLayouts - ( - SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::STATIC_DATA | - SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::CAMERA | - SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::MATERIALS | - SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::BONES + SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::MATERIALS ); perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descSetLayouts = GetPredefinedDescSetLayouts diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h index 5f574b2d..8c304e4c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h @@ -35,7 +35,6 @@ namespace SHADE enum class SystemType { BATCHING = 0, - BATCHING_ANIM, TEXT_RENDERING, RENDER_GRAPH_NODE_COMPUTE, NUM_TYPES diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedDescriptorTypes.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedDescriptorTypes.h index 64a7fa6d..7a7bb826 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedDescriptorTypes.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedDescriptorTypes.h @@ -11,7 +11,7 @@ namespace SHADE STATIC_DATA, LIGHTS, CAMERA, - MATERIALS, + PER_INSTANCE_BATCH, BONES, FONT, RENDER_GRAPH_RESOURCE, diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 8a9737c2..a2be7405 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -126,6 +126,7 @@ namespace SHADE // 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); @@ -424,10 +425,16 @@ namespace SHADE // Create default materials defaultMaterial = AddMaterial ( - defaultVertShader, defaultFragShader, + defaultVertShader, defaultFragShader, renderGraph->GetNode("G-Buffer")->GetSubpass("G-Buffer Write") ); defaultMaterial->SetProperty("data.textureIndex", defaultTexture->TextureArrayIndex); + defaultAnimMaterial = AddMaterial + ( + animtVertShader, defaultFragShader, + renderGraph->GetNode("G-Buffer")->GetSubpass("G-Buffer Write") + ); + defaultAnimMaterial->SetProperty("data.textureIndex", defaultTexture->TextureArrayIndex); } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 76c14700..c2151b21 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -457,6 +457,7 @@ namespace SHADE // Built-In Shaders Handle defaultVertShader; + Handle animtVertShader; Handle defaultFragShader; Handle debugVertShader; Handle debugFragShader; @@ -474,6 +475,7 @@ namespace SHADE // Built-In Materials Handle defaultMaterial; + Handle defaultAnimMaterial; Handle debugDrawPipeline; Handle debugDrawDepthPipeline; Handle debugDrawLineMeshPipeline; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.cpp index 59f3ba73..2ee56c51 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.cpp @@ -100,7 +100,7 @@ namespace SHADE auto const& mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); return pipeline->GetPipelineLayout()->GetShaderBlockInterface ( - mappings.at (SHPredefinedDescriptorTypes::MATERIALS), + mappings.at (SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH), //SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA, vk::ShaderStageFlagBits::eFragment diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.cpp index 70204401..6ebb2661 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.cpp @@ -81,7 +81,7 @@ namespace SHADE { return baseMaterial->GetPipeline()->GetPipelineLayout()->GetShaderBlockInterface ( - SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING).at(SHPredefinedDescriptorTypes::MATERIALS), + SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING).at(SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH), //SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA, vk::ShaderStageFlagBits::eFragment diff --git a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp index ece0e452..08f1262f 100644 --- a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp +++ b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp @@ -325,7 +325,7 @@ namespace SHADE { auto fragShader = SHResourceManager::LoadOrGet(spec.fragShader); auto const& mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); - auto interface = fragShader->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(mappings.at(SHPredefinedDescriptorTypes::MATERIALS), SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA); + auto interface = fragShader->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(mappings.at(SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH), SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA); int const varCount = static_cast(interface->GetVariableCount()); for (int i = 0; i < varCount; ++i)