So I implemented BatchMesh. Worked great. The Shader that is attached to the BatchMesh is blocking the shadows on the objects using that material. I tried making some tweaks but no luck. What’s the best way to get Shadows on this Shader?
I’m using a ( THREE.PointLight( 0xffffff, 4 )
)
with
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
Material:
const m2 = new THREE.MeshStandardMaterial({
// const m2 = new THREE.ShadowMaterial({
// material.opacity = 0.5,
// depthPacking: THREE.RGBADepthPacking,
// alphaTest: 0.5,
// side: THREE.FrontSide,
color: 0x797979,
wireframe: false,
roughness: 0.5,
metalness: 0.7,
});
m2.onBeforeCompile = ( shader, shader1 ) => {
shader.uniforms.instanceMatrices = m2.userData.instanceMatrices;
shader.vertexShader = `
uniform mat4[ ${ gs.length } ] instanceMatrices;
attribute float meshIdx;
${shader.vertexShader}
`.replace(
`#include <uv_vertex>`,
`mat4 instanceMatrix = instanceMatrices[ int( floor( meshIdx + 1.0 ))];
#include <uv_vertex>`
).replace(
`#include <default normal_vertex>`,
`#include <fog_vertex>`,
`vec3 transformedNormal = objectNormal;
mat3 m2 = mat3( instanceMatrix );
transformedNormal /= vec3( dot( m2[ 0 ], m2[ 0 ] ), dot( m2[ 1 ], m2[ 1 ] ), dot( m2[ 2 ], m2[ 2 ] ) );
transformedNormal = m2 * transformedNormal;
transformedNormal = normalMatrix * transformedNormal;
`
).replace(
`#include <project_vertex>;
#include <fog_vertex>`,
`vec4 mvPosition = vec4( transformed, 1.0 );
mvPosition = instanceMatrix * mvPosition;
mvPosition = modelViewMatrix * mvPosition;
gl_Position = projectionMatrix * mvPosition;
`
)
}
Thanks in Advance!