@@ -15,11 +15,11 @@ var<storage, read> indices : array<u32>;
1515#endif
1616var<storage, read> position : array<f32>;
1717#if NUM_BONE_INFLUENCERS > 0
18- var<storage, read> matricesIndices : array<vec4f >;
19- var<storage, read> matricesWeights : array<vec4f >;
18+ var<storage, read> matricesIndices : array<u32 >;
19+ var<storage, read> matricesWeights : array<f32 >;
2020 #if NUM_BONE_INFLUENCERS > 4
21- var<storage, read> matricesIndicesExtra : array<vec4f >;
22- var<storage, read> matricesWeightsExtra : array<vec4f >;
21+ var<storage, read> matricesIndicesExtra : array<u32 >;
22+ var<storage, read> matricesWeightsExtra : array<f32 >;
2323 #endif
2424#endif
2525
@@ -30,12 +30,12 @@ varying vNormalizedPosition : vec3f;
3030flat varying f_swizzle: i32;
3131
3232// Vertex buffer metadata (set via defines or defaults)
33- #ifndef POSITION_STRIDE_IN_FLOATS
34- #define POSITION_STRIDE_IN_FLOATS 3
33+ #ifndef POSITION_STRIDE
34+ #define POSITION_STRIDE 3
3535#endif
3636
37- #ifndef POSITION_OFFSET_IN_FLOATS
38- #define POSITION_OFFSET_IN_FLOATS 0
37+ #ifndef POSITION_OFFSET
38+ #define POSITION_OFFSET 0
3939#endif
4040
4141#ifndef POSITION_COMPONENT_COUNT
@@ -44,13 +44,87 @@ flat varying f_swizzle: i32;
4444
4545fn readVertexPosition (index : u32)->vec3f {
4646 var pos : vec3f;
47- let baseOffset = POSITION_OFFSET_IN_FLOATS + index * POSITION_STRIDE_IN_FLOATS ;
47+ let baseOffset = POSITION_OFFSET + index * POSITION_STRIDE ;
4848 pos.x = position[baseOffset];
4949 pos.y = position[baseOffset + 1u];
5050 pos.z = position[baseOffset + 2u];
5151 return pos;
5252}
5353
54+ #if NUM_BONE_INFLUENCERS > 0
55+ // Matrix indices are stored as UNSIGNED_BYTE (4 bytes packed into u32)
56+ #ifndef MATRICESINDICES_STRIDE
57+ #define MATRICESINDICES_STRIDE 1
58+ #endif
59+ #ifndef MATRICESINDICES_OFFSET
60+ #define MATRICESINDICES_OFFSET 0
61+ #endif
62+
63+ fn readMatrixIndices (index : u32) -> vec4f {
64+ let baseOffset = MATRICESINDICES_OFFSET + index * MATRICESINDICES_STRIDE;
65+ #if MATRICESINDICES_COMPONENT_BYTES == 1
66+ let packed = matricesIndices[baseOffset];
67+ // Extract 4 bytes from u32 and convert to floats
68+ return vec4f (
69+ f32 (packed & 0xFFu),
70+ f32 ((packed >> 8u) & 0xFFu),
71+ f32 ((packed >> 16u) & 0xFFu),
72+ f32 ((packed >> 24u) & 0xFFu)
73+ );
74+ #elif MATRICESINDICES_COMPONENT_BYTES == 2
75+ let packed1 = matricesIndices[baseOffset];
76+ let packed2 = matricesIndices[baseOffset + 1u];
77+ // Extract 4 bytes from two u32 and convert to floats
78+ return vec4f (
79+ f32 (packed1 & 0xFFFFu),
80+ f32 ((packed1 >> 16u) & 0xFFFFu),
81+ f32 (packed2 & 0xFFFFu),
82+ f32 ((packed2 >> 16u) & 0xFFFFu)
83+ );
84+ #endif
85+ }
86+
87+ #ifndef MATRICESWEIGHTS_STRIDE
88+ #define MATRICESWEIGHTS_STRIDE 4
89+ #endif
90+ #ifndef MATRICESWEIGHTS_OFFSET
91+ #define MATRICESWEIGHTS_OFFSET 0
92+ #endif
93+
94+ fn readMatrixWeights (index : u32) -> vec4f {
95+ let baseOffset = MATRICESWEIGHTS_OFFSET + index * MATRICESWEIGHTS_STRIDE;
96+ return vec4f (
97+ matricesWeights[baseOffset],
98+ matricesWeights[baseOffset + 1u],
99+ matricesWeights[baseOffset + 2u],
100+ matricesWeights[baseOffset + 3u]
101+ );
102+ }
103+
104+ #if NUM_BONE_INFLUENCERS > 4
105+ fn readMatrixIndicesExtra (index : u32) -> vec4f {
106+ let baseOffset = MATRICESINDICESEXTRA_OFFSET + index * MATRICESINDICESEXTRA_STRIDE;
107+ let packed = matricesIndicesExtra[baseOffset];
108+ return vec4f (
109+ f32 (packed & 0xFFu),
110+ f32 ((packed >> 8u) & 0xFFu),
111+ f32 ((packed >> 16u) & 0xFFu),
112+ f32 ((packed >> 24u) & 0xFFu)
113+ );
114+ }
115+
116+ fn readMatrixWeightsExtra (index : u32) -> vec4f {
117+ let baseOffset = MATRICESWEIGHTSEXTRA_OFFSET + index * MATRICESWEIGHTSEXTRA_STRIDE;
118+ return vec4f (
119+ matricesWeightsExtra[baseOffset],
120+ matricesWeightsExtra[baseOffset + 1u],
121+ matricesWeightsExtra[baseOffset + 2u],
122+ matricesWeightsExtra[baseOffset + 3u]
123+ );
124+ }
125+ #endif
126+ #endif
127+
54128fn readVertexIndex (index : u32)->u32 {
55129#ifndef VERTEX_PULLING_USE_INDEX_BUFFER
56130 return index;
@@ -96,11 +170,11 @@ let inputPosition: vec3f = positionUpdated;
96170#include <bakedVertexAnimation>
97171
98172#if NUM_BONE_INFLUENCERS > 0
99- let matrixIndex = matricesIndices[ vertIdx] ;
100- let matrixWeight = matricesWeights[ vertIdx] ;
173+ let matrixIndex = readMatrixIndices ( vertIdx) ;
174+ let matrixWeight = readMatrixWeights ( vertIdx) ;
101175 #if NUM_BONE_INFLUENCERS > 4
102- let matrixIndexExtra = matricesIndicesExtra[ vertIdx] ;
103- let matrixWeightExtra = matricesWeightsExtra[ vertIdx] ;
176+ let matrixIndexExtra = readMatrixIndicesExtra ( vertIdx) ;
177+ let matrixWeightExtra = readMatrixWeightsExtra ( vertIdx) ;
104178 #endif
105179#endif
106180#include <bonesVertex>(vertexInputs.matricesIndices,matrixIndex,vertexInputs.matricesWeights,matrixWeight)
0 commit comments