Added bone animation supported vertex shader
This commit is contained in:
parent
7da89def50
commit
9d17328262
|
@ -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);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
Name: Anim_VS
|
||||
ID: 47911992
|
||||
Type: 2
|
|
@ -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)
|
||||
|
|
|
@ -420,7 +420,7 @@ namespace SHADE
|
|||
// - Material Properties Data
|
||||
const Handle<SHShaderBlockInterface> 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<uint32_t, 1> dynamicOffset{ 0 };
|
||||
static std::array dynamicOffset{ 0U, static_cast<uint32_t>(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
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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<SHVkDescriptorSetLayout> 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<SHVkDescriptorSetLayout> materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding, boneDataBinding });
|
||||
SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, materialDataPerInstanceLayout->GetVkHandle(), "[Descriptor Set Layout] Material Globals");
|
||||
|
||||
// font bitmap data (texture)
|
||||
|
@ -188,14 +187,6 @@ namespace SHADE
|
|||
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::MATERIALS
|
||||
);
|
||||
|
||||
perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING_ANIM)].descSetLayouts = GetPredefinedDescSetLayouts
|
||||
(
|
||||
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::STATIC_DATA |
|
||||
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::CAMERA |
|
||||
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::MATERIALS |
|
||||
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::BONES
|
||||
);
|
||||
|
||||
perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descSetLayouts = GetPredefinedDescSetLayouts
|
||||
(
|
||||
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::STATIC_DATA |
|
||||
|
|
|
@ -35,7 +35,6 @@ namespace SHADE
|
|||
enum class SystemType
|
||||
{
|
||||
BATCHING = 0,
|
||||
BATCHING_ANIM,
|
||||
TEXT_RENDERING,
|
||||
RENDER_GRAPH_NODE_COMPUTE,
|
||||
NUM_TYPES
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace SHADE
|
|||
STATIC_DATA,
|
||||
LIGHTS,
|
||||
CAMERA,
|
||||
MATERIALS,
|
||||
PER_INSTANCE_BATCH,
|
||||
BONES,
|
||||
FONT,
|
||||
RENDER_GRAPH_RESOURCE,
|
||||
|
|
|
@ -126,6 +126,7 @@ namespace SHADE
|
|||
|
||||
// Load Built In Shaders
|
||||
static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEFAULT);
|
||||
static constexpr AssetID VS_ANIM = 47911992; animtVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_ANIM);
|
||||
static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(FS_DEFAULT);
|
||||
static constexpr AssetID VS_DEBUG = 48002439; debugVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEBUG);
|
||||
static constexpr AssetID FS_DEBUG = 36671027; debugFragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(FS_DEBUG);
|
||||
|
@ -428,6 +429,12 @@ namespace SHADE
|
|||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -457,6 +457,7 @@ namespace SHADE
|
|||
|
||||
// Built-In Shaders
|
||||
Handle<SHVkShaderModule> defaultVertShader;
|
||||
Handle<SHVkShaderModule> animtVertShader;
|
||||
Handle<SHVkShaderModule> defaultFragShader;
|
||||
Handle<SHVkShaderModule> debugVertShader;
|
||||
Handle<SHVkShaderModule> debugFragShader;
|
||||
|
@ -474,6 +475,7 @@ namespace SHADE
|
|||
|
||||
// Built-In Materials
|
||||
Handle<SHMaterial> defaultMaterial;
|
||||
Handle<SHMaterial> defaultAnimMaterial;
|
||||
Handle<SHVkPipeline> debugDrawPipeline;
|
||||
Handle<SHVkPipeline> debugDrawDepthPipeline;
|
||||
Handle<SHVkPipeline> debugDrawLineMeshPipeline;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -325,7 +325,7 @@ namespace SHADE
|
|||
{
|
||||
auto fragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(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<int>(interface->GetVariableCount());
|
||||
|
||||
for (int i = 0; i < varCount; ++i)
|
||||
|
|
Loading…
Reference in New Issue