Jelajahi Sumber

temp for merge

Benjamin Guignabert 5 tahun lalu
induk
melakukan
f1828acba0
2 mengubah file dengan 43 tambahan dan 3 penghapusan
  1. 3 0
      src/Materials/materialHelper.ts
  2. 40 3
      src/Shaders/pbr.vertex.fx

+ 3 - 0
src/Materials/materialHelper.ts

@@ -841,6 +841,9 @@ export class MaterialHelper {
 
                 if (matrices) {
                     effect.setMatrices("mBones", matrices);
+                    if (mesh.getScene().prePassRenderer && mesh.getScene().prePassRenderer.getIndex()) {
+                        effect.setMatrices("mPreviousBones", this._previousBonesTransformationMatrices[renderingMesh.uniqueId]);
+                    }
                 }
             }
         }

+ 40 - 3
src/Shaders/pbr.vertex.fx

@@ -179,6 +179,13 @@ void main(void) {
 #define CUSTOM_VERTEX_UPDATE_NORMAL
 
 #include<instancesVertex>
+
+#if defined(PREPASS) && defined(PREPASS_VELOCITY) && !defined(BONES_VELOCITY_ENABLED)
+    // Compute velocity before bones computation
+    vCurrentPosition = viewProjection * finalWorld * vec4(positionUpdated, 1.0);
+    vPreviousPosition = previousViewProjection * previousWorld * vec4(positionUpdated, 1.0);
+#endif
+
 #include<bonesVertex>
 
     vec4 worldPos = finalWorld * vec4(positionUpdated, 1.0);
@@ -187,10 +194,40 @@ void main(void) {
     #ifdef PREPASS_DEPTHNORMAL
         vViewPos = (view * worldPos).rgb;
     #endif
-    #if defined(PREPASS_VELOCITY) && !defined(BONES_VELOCITY_ENABLED)
-        // Compute velocity before bones computation
+
+    #if defined(PREPASS_VELOCITY) && defined(BONES_VELOCITY_ENABLED)
         vCurrentPosition = viewProjection * worldPos;
-        vPreviousPosition = previousViewProjection * previousWorld * vec4(positionUpdated, 1.0);
+
+        #if NUM_BONE_INFLUENCERS > 0
+            mat4 previousInfluence;
+            previousInfluence = mPreviousBones[int(matricesIndices[0])] * matricesWeights[0];
+            #if NUM_BONE_INFLUENCERS > 1
+                previousInfluence += mPreviousBones[int(matricesIndices[1])] * matricesWeights[1];
+            #endif  
+            #if NUM_BONE_INFLUENCERS > 2
+                previousInfluence += mPreviousBones[int(matricesIndices[2])] * matricesWeights[2];
+            #endif  
+            #if NUM_BONE_INFLUENCERS > 3
+                previousInfluence += mPreviousBones[int(matricesIndices[3])] * matricesWeights[3];
+            #endif  
+
+            #if NUM_BONE_INFLUENCERS > 4
+                previousInfluence += mPreviousBones[int(matricesIndicesExtra[0])] * matricesWeightsExtra[0];
+            #endif  
+            #if NUM_BONE_INFLUENCERS > 5
+                previousInfluence += mPreviousBones[int(matricesIndicesExtra[1])] * matricesWeightsExtra[1];
+            #endif  
+            #if NUM_BONE_INFLUENCERS > 6
+                previousInfluence += mPreviousBones[int(matricesIndicesExtra[2])] * matricesWeightsExtra[2];
+            #endif  
+            #if NUM_BONE_INFLUENCERS > 7
+                previousInfluence += mPreviousBones[int(matricesIndicesExtra[3])] * matricesWeightsExtra[3];
+            #endif
+
+            vPreviousPosition = previousViewProjection * previousWorld * previousInfluence * vec4(positionUpdated, 1.0);
+        #else
+            vPreviousPosition = previousViewProjection * previousWorld * vec4(positionUpdated, 1.0);
+        #endif
     #endif
 
 #endif