1
votes

Is there a way to prevent a directional light from illuminating a specific object? I guess this would also apply to a spotlight. The reason for this is I would like to use two directional lights, but with one light shining on an object to give it 'self shadowing', and do not want that light it to interfere with another object.

Currently I have a single directional light declared as such :

function addpointlight()
{

    var SHADOW_MAP_WIDTH = 4096, SHADOW_MAP_HEIGHT = 2048;
    //Enabling this this light just creates serious artifacts on the obj I am trying to shadow.
    //var newlight=new THREE.DirectionalLight(0xeeeeee,0.7);
    //newlight.position.set( 0, 100, 300 );
    //newlight.castShadow=false;
    //scene.add(newlight);

// create a directional light
    pointLight = new THREE.DirectionalLight(0xeeeeee,0.80);

    //pointLight.onlyShadow=true;
    pointLight.position.set( 0, 100, 300 );
    pointLight.shadowCameraVisible=true;

    pointLight.shadowCameraNear = 10;
    pointLight.shadowCameraFar = 1500;
    pointLight.shadowCameraFov = 90;
    pointLight.castShadow=true;


    var d = 4;
    pointLight.shadowCameraLeft = -d;
    pointLight.shadowCameraRight = d;
    pointLight.shadowCameraTop = -d;
    pointLight.shadowCameraBottom = d;

    pointLight.shadowBias = 0.00;
    pointLight.shadowDarkness = 0.7;
    pointLight.shadowMapWidth = SHADOW_MAP_WIDTH;
    pointLight.shadowMapHeight = SHADOW_MAP_HEIGHT;

    // add to the scene
    scene.add(pointLight);
}

This light wraps nicely around the object I want to self shadow, eliminating shadow artifacts. It moves with a moving object that it is creating a shadow on using this :-

pointLight.position.set(obj.position.x+40,obj.position.y+5,obj.position.z+300);
pointLight.target=obj;

So I'd like to create a second directional light that only affects the other objects, not this one, tnd this one's light must not affect other objects. I'd create a fiddle, but the models I am testing with together with the textures make it a rather large fiddle in terms of bandwidth.

The three.js version in r70.

1

1 Answers

9
votes

You want to limit the objects that a light affects. Until the time at which three.js supports "layers", where a light will only affect objects in its own layer(s), you may be able to achieve what you want with a work-around: two separate scenes and two render passes.

renderer.autoClear = false;

...

renderer.clear();
renderer.render( scene1, camera );
renderer.render( scene2, camera );

If you have transparent objects, they will have to be in the second scene. Also, an object can only be in one scene, so you will have to duplicate a light if you want it in both.

three.js r.70