|
@@ -155,6 +155,10 @@ export class MorphTargetsBlock extends NodeMaterialBlock {
|
|
|
public bind(effect: Effect, nodeMaterial: NodeMaterial, mesh?: Mesh) {
|
|
|
if (mesh && mesh.morphTargetManager && mesh.morphTargetManager.numInfluencers > 0) {
|
|
|
MaterialHelper.BindMorphTargetParameters(mesh, effect);
|
|
|
+
|
|
|
+ if (mesh.morphTargetManager.isUsingTextureForTargets) {
|
|
|
+ mesh.morphTargetManager._bind(effect);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -177,26 +181,53 @@ export class MorphTargetsBlock extends NodeMaterialBlock {
|
|
|
|
|
|
let injectionCode = "";
|
|
|
|
|
|
+ if (manager?.isUsingTextureForTargets && repeatCount > 0) {
|
|
|
+ injectionCode += `float vertexID = float(gl_VertexID) * morphTargetTextureInfo.x;\r\n`;
|
|
|
+ }
|
|
|
+
|
|
|
for (var index = 0; index < repeatCount; index++) {
|
|
|
injectionCode += `#ifdef MORPHTARGETS\r\n`;
|
|
|
- injectionCode += `${positionOutput.associatedVariableName} += (position${index} - ${position.associatedVariableName}) * morphTargetInfluences[${index}];\r\n`;
|
|
|
+ if (manager?.isUsingTextureForTargets) {
|
|
|
+ injectionCode += `${positionOutput.associatedVariableName} += (readVector3FromRawSampler(morphTargets[${index}], vertexID) - ${position.associatedVariableName}) * morphTargetInfluences[${index}];\r\n`;
|
|
|
+ injectionCode += `vertexID += 1.0;\r\n`;
|
|
|
+ } else {
|
|
|
+ injectionCode += `${positionOutput.associatedVariableName} += (position${index} - ${position.associatedVariableName}) * morphTargetInfluences[${index}];\r\n`;
|
|
|
+ }
|
|
|
|
|
|
if (hasNormals) {
|
|
|
injectionCode += `#ifdef MORPHTARGETS_NORMAL\r\n`;
|
|
|
- injectionCode += `${normalOutput.associatedVariableName} += (normal${index} - ${normal.associatedVariableName}) * morphTargetInfluences[${index}];\r\n`;
|
|
|
+ if (manager?.isUsingTextureForTargets) {
|
|
|
+ injectionCode += `${normalOutput.associatedVariableName} += (readVector3FromRawSampler(morphTargets[${index}], vertexID) - ${normal.associatedVariableName}) * morphTargetInfluences[${index}];\r\n`;
|
|
|
+ injectionCode += `vertexID += 1.0;\r\n`;
|
|
|
+ } else {
|
|
|
+ injectionCode += `${normalOutput.associatedVariableName} += (normal${index} - ${normal.associatedVariableName}) * morphTargetInfluences[${index}];\r\n`;
|
|
|
+ }
|
|
|
+ injectionCode += `#endif\r\n`;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (hasUVs) {
|
|
|
+ injectionCode += `#ifdef MORPHTARGETS_UV\r\n`;
|
|
|
+ if (manager?.isUsingTextureForTargets) {
|
|
|
+ injectionCode += `${uvOutput.associatedVariableName} += (readVector3FromRawSampler(morphTargets[${index}], vertexID).xy - ${uv.associatedVariableName}) * morphTargetInfluences[${index}];\r\n`;
|
|
|
+ injectionCode += `vertexID += 1.0;\r\n`;
|
|
|
+ } else {
|
|
|
+ injectionCode += `${uvOutput.associatedVariableName}.xy += (uv_${index} - ${uv.associatedVariableName}.xy) * morphTargetInfluences[${index}];\r\n`;
|
|
|
+ }
|
|
|
injectionCode += `#endif\r\n`;
|
|
|
}
|
|
|
|
|
|
if (hasTangents) {
|
|
|
injectionCode += `#ifdef MORPHTARGETS_TANGENT\r\n`;
|
|
|
- injectionCode += `${tangentOutput.associatedVariableName}.xyz += (tangent${index} - ${tangent.associatedVariableName}.xyz) * morphTargetInfluences[${index}];\r\n`;
|
|
|
+ if (manager?.isUsingTextureForTargets) {
|
|
|
+ injectionCode += `${tangentOutput.associatedVariableName} += (readVector3FromRawSampler(morphTargets[${index}], vertexID) - ${tangent.associatedVariableName}) * morphTargetInfluences[${index}];\r\n`;
|
|
|
+ } else {
|
|
|
+ injectionCode += `${tangentOutput.associatedVariableName}.xyz += (tangent${index} - ${tangent.associatedVariableName}.xyz) * morphTargetInfluences[${index}];\r\n`;
|
|
|
+ }
|
|
|
injectionCode += `#endif\r\n`;
|
|
|
}
|
|
|
|
|
|
- if (hasUVs) {
|
|
|
- injectionCode += `#ifdef MORPHTARGETS_UV\r\n`;
|
|
|
- injectionCode += `${uvOutput.associatedVariableName}.xy += (uv_${index} - ${uv.associatedVariableName}.xy) * morphTargetInfluences[${index}];\r\n`;
|
|
|
- injectionCode += `#endif\r\n`;
|
|
|
+ if (manager?.isUsingTextureForTargets) {
|
|
|
+ injectionCode += `vertexID = float(gl_VertexID) * morphTargetTextureInfo.x;\r\n`;
|
|
|
}
|
|
|
|
|
|
injectionCode += `#endif\r\n`;
|
|
@@ -247,6 +278,8 @@ export class MorphTargetsBlock extends NodeMaterialBlock {
|
|
|
let comments = `//${this.name}`;
|
|
|
|
|
|
state.uniforms.push("morphTargetInfluences");
|
|
|
+ state.uniforms.push("morphTargetTextureInfo");
|
|
|
+ state.samplers.push("morphTargets");
|
|
|
|
|
|
state._emitFunctionFromInclude("morphTargetsVertexGlobalDeclaration", comments);
|
|
|
state._emitFunctionFromInclude("morphTargetsVertexDeclaration", comments, {
|