Someone correct me if I’m wrong, but I’m pretty sure the “pars” chunks need to be above the “void main” call.
Also, I think ‘shadowmap_vertex’ needs to be after the “gl_Position =”.
This is mine and it works (at least for receiving shadows):
this.lambertVertex = [
'#define LAMBERT',
'varying vec3 vLightFront;',
'#ifdef DOUBLE_SIDED',
'varying vec3 vLightBack;',
'#endif',
this.pars_vertex_common,
this.instancing ? this.instanced_pars_vertex : this.standard_pars_vertex,
THREE.ShaderChunk[ "common" ],
THREE.ShaderChunk[ "uv_pars_vertex" ],
THREE.ShaderChunk[ "uv2_pars_vertex" ],
//THREE.ShaderChunk[ "envmap_pars_vertex" ],
THREE.ShaderChunk[ "bsdfs" ],
THREE.ShaderChunk[ "lights_pars_begin" ],
THREE.ShaderChunk[ "lights_pars_maps" ],
THREE.ShaderChunk[ "color_pars_vertex" ],
THREE.ShaderChunk[ "fog_pars_vertex" ],
//THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
//THREE.ShaderChunk[ "skinning_pars_vertex" ],
THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
//THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
//THREE.ShaderChunk[ "clipping_planes_pars_vertex" ],
'void main() {',
THREE.ShaderChunk[ "uv_vertex" ],
THREE.ShaderChunk[ "uv2_vertex" ],
THREE.ShaderChunk[ "color_vertex" ],
THREE.ShaderChunk[ "beginnormal_vertex" ],
//THREE.ShaderChunk[ "morphnormal_vertex" ],
//THREE.ShaderChunk[ "skinbase_vertex" ],
//THREE.ShaderChunk[ "skinnormal_vertex" ],
THREE.ShaderChunk[ "defaultnormal_vertex" ],
THREE.ShaderChunk[ "begin_vertex" ],
this.animation_vertex,
this.instancing ? this.instanced_vertex : '',
//THREE.ShaderChunk[ "morphtarget_vertex" ],
//THREE.ShaderChunk[ "skinning_vertex" ],
THREE.ShaderChunk[ "project_vertex" ],
//THREE.ShaderChunk[ "logdepthbuf_vertex" ],
//THREE.ShaderChunk[ "clipping_planes_vertex" ],
THREE.ShaderChunk[ "worldpos_vertex" ],
//THREE.ShaderChunk[ "envmap_vertex" ],
THREE.ShaderChunk[ "lights_lambert_vertex" ],
THREE.ShaderChunk[ "shadowmap_vertex" ],
THREE.ShaderChunk[ "fog_vertex" ],
'}'
].join('\n');
this.lambertFragment = [
'uniform vec3 diffuse;',
'uniform vec3 emissive;',
'uniform float opacity;',
'varying vec3 vLightFront;',
this.pars_fragment,
'#ifdef DOUBLE_SIDED',
'varying vec3 vLightBack;',
'#endif',
THREE.ShaderChunk[ "common" ],
THREE.ShaderChunk[ "packing" ],
THREE.ShaderChunk[ "dithering_pars_fragment" ],
THREE.ShaderChunk[ "color_pars_fragment" ],
THREE.ShaderChunk[ "uv_pars_fragment" ],
THREE.ShaderChunk[ "uv2_pars_fragment" ],
THREE.ShaderChunk[ "map_pars_fragment" ],
//THREE.ShaderChunk[ "alphamap_pars_fragment" ],
//THREE.ShaderChunk[ "aomap_pars_fragment" ],
//THREE.ShaderChunk[ "lightmap_pars_fragment" ],
//THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
//THREE.ShaderChunk[ "envmap_pars_fragment" ],
THREE.ShaderChunk[ "bsdfs" ],
THREE.ShaderChunk[ "lights_pars_begin" ],
THREE.ShaderChunk[ "lights_pars_maps" ],
THREE.ShaderChunk[ "fog_pars_fragment" ],
THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
THREE.ShaderChunk[ "shadowmask_pars_fragment" ],
//THREE.ShaderChunk[ "specularmap_pars_fragment" ],
//THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
//THREE.ShaderChunk[ "clipping_planes_pars_fragment" ],
'void main() {',
//THREE.ShaderChunk[ "clipping_planes_fragment" ],
'vec4 diffuseColor = vec4( diffuse, opacity );',
'ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );',
'vec3 totalEmissiveRadiance = emissive;',
//THREE.ShaderChunk[ "logdepthbuf_fragment" ],
//THREE.ShaderChunk[ "map_fragment" ],
this.map_fragment,
'if (texelColor[0] < threshold && texelColor[1] < threshold && texelColor[2] < threshold) {',
'discard;',
'} else {',
THREE.ShaderChunk[ "color_fragment" ],
//THREE.ShaderChunk[ "alphamap_fragment" ],
THREE.ShaderChunk[ "alphatest_fragment" ],
//THREE.ShaderChunk[ "specularmap_fragment" ],
//THREE.ShaderChunk[ "emissivemap_fragment" ],
'reflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );',
//THREE.ShaderChunk[ "lightmap_fragment" ],
'reflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );',
'#ifdef DOUBLE_SIDED',
'reflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;',
'#else',
'reflectedLight.directDiffuse = vLightFront;',
'#endif',
'reflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();',
//THREE.ShaderChunk[ "aomap_fragment" ],
'vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;',
//THREE.ShaderChunk[ "envmap_fragment" ],
'gl_FragColor = vec4( outgoingLight, diffuseColor.a );',
//THREE.ShaderChunk[ "tonemapping_fragment" ],
THREE.ShaderChunk[ "encodings_fragment" ],
THREE.ShaderChunk[ "fog_fragment" ],
THREE.ShaderChunk[ "premultiplied_alpha_fragment" ],
THREE.ShaderChunk[ "dithering_fragment" ],
'}',
'}'
].join('\n');