Object still casting shadow with castShadow = false

Most of the objects in my scene I want to cast shadows. So I set castShadow=true and the shadows all render properly. However, a handful of objects I do NOT want to cast a shadow. Yet castShadow=false is notworking . They still cast a shadow.

            this.renderer.shadowMap.enabled = true;
            this.renderer.shadowMap.type = THREE.PCFSoftShadowMap;

My material is being created as:
var material = new THREE.MeshStandardMaterial({
transparent : true,
opacity: 0
});

Then I am turning the shadow off:

    mesh.castShadow = false;
    mesh.receiveShadow = false;

I can’t see what else I should be doing but I still have shadows :frowning:

The green is where I have the object and the red is the shadow its casting:

I bet there are multiple meshes in the scene and you’re only disabling for one of them?

try

scene.traverse( e=>e.isMesh && (e.castShadow=e.receiveShadow = false))

1 Like

But that’s what I want. I want MOST of the objects to cast a shadow. But I want the transparent ones to not cast a shadow. Won’t the traverse turn off everything?

Add an “is transparent?” condition to your traverse function:

scene.traverse((object) => {
    if(object.isMesh && object.material.opacity === 0) {
       object.receiveShadow = false;
       object.castShadow = false;
    }
})

Gave it a go and can see it’s hitting the code and setting castShadow to false but there is still a shadow being displayed :frowning:

OH… I misunderstood. When we talk about casting shadows, we usually mean the shadow cast by an object onto the rest of the scene… not the shading on the side of the object facing away from the light.

This more of a lighting issue. You could try switching off your DirectionalLight , and switching on an AmbientLight

Ambient lights light things uniformly from all directions… but it can make it had to differentiate between similar colored objects. so something a combination of lights helps.

1 Like

I am a little embarassed: -( There was a castShadow setting buried deep in the code which escaped my attention and that was causing the issue. It’s not a threejs issue. Thanks for taking the time to try and assist. I did learn something new with the traverse, so that was useful.

Thanks.

2 Likes