Three.js: setting material.morphTargets = true on ShaderMaterial does not add influences

Created on 18 Nov 2019  路  4Comments  路  Source: mrdoob/three.js

Follow-up to https://github.com/mrdoob/three.js/issues/8799#issuecomment-554796956 - it appears this is broken in r110:

THREE.WebGLProgram: shader error:  0 35715 true gl.getProgramInfoLog Must have a compiled vertex shader attached. THREE.WebGLShader: gl.getShaderInfoLog() vertex
ERROR: 0:55: 'morphTargetInfluences' : undeclared identifier
ERROR: 0:55: 'expression' :  left of '[' is not of type array, matrix, or vector 
ERROR: 0:56: 'morphTargetInfluences' : undeclared identifier
ERROR: 0:56: 'expression' :  left of '[' is not of type array, matrix, or vector1: precision highp float;
2: precision highp int;
3: #define HIGH_PRECISION
4: #define SHADER_NAME ShaderMaterial
5: #define VERTEX_TEXTURES
6: #define GAMMA_FACTOR 2
7: #define MAX_BONES 0
8: #define BONE_TEXTURE
9: #define USE_MORPHTARGETS
10: uniform mat4 modelMatrix;
11: uniform mat4 modelViewMatrix;
12: uniform mat4 projectionMatrix;
13: uniform mat4 viewMatrix;
14: uniform mat3 normalMatrix;
15: uniform vec3 cameraPosition;
16: uniform bool isOrthographic;
17: #ifdef USE_INSTANCING
18:  attribute mat4 instanceMatrix;
19: #endif
20: attribute vec3 position;
21: attribute vec3 normal;
22: attribute vec2 uv;
23: #ifdef USE_TANGENT
24:     attribute vec4 tangent;
25: #endif
26: #ifdef USE_COLOR
27:     attribute vec3 color;
28: #endif
29: #ifdef USE_MORPHTARGETS
30:     attribute vec3 morphTarget0;
31:     attribute vec3 morphTarget1;
32:     attribute vec3 morphTarget2;
33:     attribute vec3 morphTarget3;
34:     #ifdef USE_MORPHNORMALS
35:         attribute vec3 morphNormal0;
36:         attribute vec3 morphNormal1;
37:         attribute vec3 morphNormal2;
38:         attribute vec3 morphNormal3;
39:     #else
40:         attribute vec3 morphTarget4;
41:         attribute vec3 morphTarget5;
42:         attribute vec3 morphTarget6;
43:         attribute vec3 morphTarget7;
44:     #endif
45: #endif
46: #ifdef USE_SKINNING
47:     attribute vec4 skinIndex;
48:     attribute vec4 skinWeight;
49: #endif
50:
(my shader starts here)

we see #define USE_MORPHTARGETS added at line 9, and morphTarget* added at line 30, but influences are nowhere to be seen.

p.s. fiddle

Most helpful comment

your fiddle is messed up since you pass in an invalid vertex and fragment shader

that was to log the shader code.

include

so this is needed for influences to be added. I wish this was documented somewhere. but now it is - here. thanks @Mugen87

All 4 comments

In addition, if I use my own uniforms for the influences, it still does not work until you do this:

        mesh.updateMorphTargets ();
        // these need to be non-zero, or the attributes will not be uploaded
        mesh.morphTargetInfluences[ 0 ] = 1;
        mesh.morphTargetInfluences[ 1 ] = 1;
        ....

is this a bug, or three.js trying to be smart?

It seems your fiddle is messed up since you pass in an invalid vertex and fragment shader. I've created a new one here: https://jsfiddle.net/8f4cyto2/3/

It demonstrates that it is not necessary to call manually updateMorphTargets() if the geometry passed into the Mesh ctor already has valid morph data. Apart from that, you only have to include the shader chunks morphtarget_pars_vertex, begin_vertex and morphtarget_vertex into your vertex shader.

Note that Material.morphTargets only ensures that the define USE_MORPHTARGETS is set. The necessary uniforms and program logic are only present if you include the respective shader chunks.

your fiddle is messed up since you pass in an invalid vertex and fragment shader

that was to log the shader code.

include

so this is needed for influences to be added. I wish this was documented somewhere. but now it is - here. thanks @Mugen87

that was to log the shader code.

Oh, okay. I was not aware of this intention^^.

I wish this was documented somewhere.

Related https://github.com/mrdoob/three.js/issues/17088

Was this page helpful?
0 / 5 - 0 ratings