Fixed shadows with animations #419

Merged
Xenosas1337 merged 7 commits from SP3-1-Rendering into main 2023-03-10 19:30:52 +08:00
5 changed files with 41 additions and 8 deletions
Showing only changes of commit 801da75d87 - Show all commits

View File

@ -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: ~

View File

@ -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);
}

View File

@ -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) });

View File

@ -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)
{