Fixed shadows for animation

This commit is contained in:
Brandon Mak 2023-03-10 18:37:28 +08:00
parent 683ce6146a
commit 801da75d87
5 changed files with 41 additions and 8 deletions

View File

@ -2419,7 +2419,7 @@
Components: Components:
Transform Component: Transform Component:
Translate: {x: 0, y: 0, z: 0} 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} Scale: {x: 1, y: 1, z: 1}
IsActive: true IsActive: true
Renderable Component: Renderable Component:
@ -6858,8 +6858,8 @@
NumberOfChildren: 0 NumberOfChildren: 0
Components: Components:
Transform Component: Transform Component:
Translate: {x: 2.13981342, y: 0.0490087792, z: -1.96055627} Translate: {x: 2.13981342, y: 0.0490087792, z: -1.86932743}
Rotate: {x: 0, y: -1.53675354, z: 0} Rotate: {x: -0, y: -1.53675354, z: 0}
Scale: {x: 1, y: 1, z: 1} Scale: {x: 1, y: 1, z: 1}
IsActive: true IsActive: true
Renderable Component: Renderable Component:
@ -8217,3 +8217,23 @@
Clicked: false Clicked: false
IsActive: true IsActive: true
Scripts: ~ 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; mat4 projMat;
} cameraData; } cameraData;
layout (std430, set = 2, binding = 1) buffer AnimBoneMatrices
{
mat4 data[];
} BoneMatrices;
void main() void main()
{ {
Out2.materialIndex = gl_InstanceIndex; Out2.materialIndex = gl_InstanceIndex;
@ -63,6 +69,13 @@ void main()
Out.normal.rgb = transposeInv * aNormal.rgb; Out.normal.rgb = transposeInv * aNormal.rgb;
Out.normal.rgb = normalize (Out.normal.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 // 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(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(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::UINT32_4D) }, 6, 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(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_4D) }, 7, 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(true, true, { SHVertexAttribute(SHAttribFormat::UINT32_1D) }, 8, 11); // Instance bone matrix first index at index 7
//shadowMapAnimVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); //shadowMapAnimVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) });

View File

@ -496,7 +496,7 @@ namespace SHADE
{ {
if (!dummyPipelineLayout) if (!dummyPipelineLayout)
{ {
auto const& batchingSystemData = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING); auto const& batchingSystemData = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING_ANIM);
std::vector newLayouts = batchingSystemData.descSetLayouts; std::vector newLayouts = batchingSystemData.descSetLayouts;
if (inputDescriptorLayout) if (inputDescriptorLayout)
{ {