diff --git a/android/filamat-android/src/main/java/com/google/android/filament/filamat/MaterialBuilder.java b/android/filamat-android/src/main/java/com/google/android/filament/filamat/MaterialBuilder.java
index 5017f18fc5..c52cd51e0c 100644
--- a/android/filamat-android/src/main/java/com/google/android/filament/filamat/MaterialBuilder.java
+++ b/android/filamat-android/src/main/java/com/google/android/filament/filamat/MaterialBuilder.java
@@ -114,14 +114,14 @@ public class MaterialBuilder {
BONE_INDICES, // indices of 4 bones (uvec4)
BONE_WEIGHTS, // weights of the 4 bones (normalized float4)
UNUSED, // reserved for future use
- CUSTOM0, // custom or MORPH_POSITION_0
- CUSTOM1, // custom or MORPH_POSITION_1
- CUSTOM2, // custom or MORPH_POSITION_2
- CUSTOM3, // custom or MORPH_POSITION_3
- CUSTOM4, // custom or MORPH_TANGENTS_0
- CUSTOM5, // custom or MORPH_TANGENTS_1
- CUSTOM6, // custom or MORPH_TANGENTS_2
- CUSTOM7 // custom or MORPH_TANGENTS_3
+ CUSTOM0, // custom
+ CUSTOM1, // custom
+ CUSTOM2, // custom
+ CUSTOM3, // custom
+ CUSTOM4, // custom
+ CUSTOM5, // custom
+ CUSTOM6, // custom
+ CUSTOM7 // custom
}
public enum BlendingMode {
diff --git a/android/filament-android/src/main/cpp/RenderableManager.cpp b/android/filament-android/src/main/cpp/RenderableManager.cpp
index cba710637c..8d3d43dcdd 100644
--- a/android/filament-android/src/main/cpp/RenderableManager.cpp
+++ b/android/filament-android/src/main/cpp/RenderableManager.cpp
@@ -270,9 +270,9 @@ Java_com_google_android_filament_RenderableManager_nSetMorphWeights(JNIEnv* env,
jlong nativeRenderableManager, jint instance, jfloatArray weights) {
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
jfloat* vec = env->GetFloatArrayElements(weights, NULL);
- math::float4 floatvec(vec[0], vec[1], vec[2], vec[3]);
+ jsize count = env->GetArrayLength(weights);
+ rm->setMorphWeights((RenderableManager::Instance)instance, vec, count);
env->ReleaseFloatArrayElements(weights, vec, JNI_ABORT);
- rm->setMorphWeights((RenderableManager::Instance)instance, floatvec);
}
extern "C" JNIEXPORT void JNICALL
diff --git a/android/filament-android/src/main/java/com/google/android/filament/RenderableManager.java b/android/filament-android/src/main/java/com/google/android/filament/RenderableManager.java
index db4fdb8c83..1a5785ebe7 100644
--- a/android/filament-android/src/main/java/com/google/android/filament/RenderableManager.java
+++ b/android/filament-android/src/main/java/com/google/android/filament/RenderableManager.java
@@ -402,9 +402,6 @@ public class RenderableManager {
/**
* Controls if the renderable has vertex morphing targets, false by default.
*
- *
This is required to enable GPU morphing for up to 4 attributes. The attached VertexBuffer
- * must provide data in the appropriate VertexAttribute slots (MORPH_POSITION_0 etc).
- *
* See also {@link RenderableManager#setMorphWeights}, which can be called on a per-frame basis
* to advance the animation.
*/
@@ -497,14 +494,11 @@ public class RenderableManager {
/**
* Updates the vertex morphing weights on a renderable, all zeroes by default.
*
- * This is specified using a 4-tuple, one float per morph target. If the renderable has fewer
- * than 4 morph targets, then clients should fill the unused components with zeroes.
- *
* The renderable must be built with morphing enabled.
*
* @see Builder#morphing
*/
- public void setMorphWeights(@EntityInstance int i, @NonNull @Size(min = 4) float[] weights) {
+ public void setMorphWeights(@EntityInstance int i, @NonNull float[] weights) {
nSetMorphWeights(mNativeObject, i, weights);
}
diff --git a/android/filament-android/src/main/java/com/google/android/filament/VertexBuffer.java b/android/filament-android/src/main/java/com/google/android/filament/VertexBuffer.java
index d3494e81ef..359505d369 100644
--- a/android/filament-android/src/main/java/com/google/android/filament/VertexBuffer.java
+++ b/android/filament-android/src/main/java/com/google/android/filament/VertexBuffer.java
@@ -66,14 +66,14 @@ public class VertexBuffer {
BONE_INDICES, // indices of 4 bones (uvec4)
BONE_WEIGHTS, // weights of the 4 bones (normalized float4)
UNUSED, // reserved for future use
- CUSTOM0, // custom or MORPH_POSITION_0
- CUSTOM1, // custom or MORPH_POSITION_1
- CUSTOM2, // custom or MORPH_POSITION_2
- CUSTOM3, // custom or MORPH_POSITION_3
- CUSTOM4, // custom or MORPH_TANGENTS_0
- CUSTOM5, // custom or MORPH_TANGENTS_1
- CUSTOM6, // custom or MORPH_TANGENTS_2
- CUSTOM7 // custom or MORPH_TANGENTS_3
+ CUSTOM0, // custom
+ CUSTOM1, // custom
+ CUSTOM2, // custom
+ CUSTOM3, // custom
+ CUSTOM4, // custom
+ CUSTOM5, // custom
+ CUSTOM6, // custom
+ CUSTOM7 // custom
}
public enum AttributeType {
diff --git a/docs/webgl/reference.html b/docs/webgl/reference.html
index 3fd55c7de6..6b7510906d 100644
--- a/docs/webgl/reference.html
+++ b/docs/webgl/reference.html
@@ -1438,14 +1438,6 @@ This defines the following functions:
CUSTOM5
CUSTOM6
CUSTOM7
-MORPH_POSITION_0
-MORPH_POSITION_1
-MORPH_POSITION_2
-MORPH_POSITION_3
-MORPH_TANGENTS_0
-MORPH_TANGENTS_1
-MORPH_TANGENTS_2
-MORPH_TANGENTS_3
diff --git a/filament/CMakeLists.txt b/filament/CMakeLists.txt
index 4049d39130..c9c996a9d3 100644
--- a/filament/CMakeLists.txt
+++ b/filament/CMakeLists.txt
@@ -28,6 +28,7 @@ set(PUBLIC_HDRS
include/filament/LightManager.h
include/filament/Material.h
include/filament/MaterialInstance.h
+ include/filament/MorphTargetBuffer.h
include/filament/Options.h
include/filament/RenderTarget.h
include/filament/RenderableManager.h
@@ -69,6 +70,7 @@ set(SRCS
src/Material.cpp
src/MaterialInstance.cpp
src/MaterialParser.cpp
+ src/MorphTargetBuffer.cpp
src/PerViewUniforms.cpp
src/PostProcessManager.cpp
src/RenderPass.cpp
@@ -140,6 +142,7 @@ set(PRIVATE_HDRS
src/details/IndirectLight.h
src/details/Material.h
src/details/MaterialInstance.h
+ src/details/MorphTargetBuffer.h
src/details/RenderTarget.h
src/details/Renderer.h
src/details/Scene.h
diff --git a/filament/include/filament/Engine.h b/filament/include/filament/Engine.h
index 4db5ae7576..0a31013f66 100644
--- a/filament/include/filament/Engine.h
+++ b/filament/include/filament/Engine.h
@@ -39,6 +39,7 @@ class SkinningBuffer;
class IndirectLight;
class Material;
class MaterialInstance;
+class MorphTargetBuffer;
class Renderer;
class RenderTarget;
class Scene;
@@ -421,6 +422,7 @@ public:
bool destroy(const Fence* p); //!< Destroys a Fence object.
bool destroy(const IndexBuffer* p); //!< Destroys an IndexBuffer object.
bool destroy(const SkinningBuffer* p); //!< Destroys a SkinningBuffer object.
+ bool destroy(const MorphTargetBuffer* p); //!< Destroys a MorphTargetBuffer object.
bool destroy(const IndirectLight* p); //!< Destroys an IndirectLight object.
/**
diff --git a/filament/include/filament/MorphTargetBuffer.h b/filament/include/filament/MorphTargetBuffer.h
new file mode 100644
index 0000000000..f3c0877039
--- /dev/null
+++ b/filament/include/filament/MorphTargetBuffer.h
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TNT_FILAMENT_MORPHTARGETBUFFER_H
+#define TNT_FILAMENT_MORPHTARGETBUFFER_H
+
+#include
+
+#include
+
+#include