How to make light affect particular objects?

Hi all. Is a way to make light effect particular objects? I tried set particular layer to light and objects, but looks like it doesn’t work. Thanks

For now, the lighting process does not take node layers into account, so I’m afraid there is no easy way to customize this behavior.

I’m not sure why would it be necessary to exclude the lighting effect for some particular models, if you would kindly elaborate.

But nevertheless you can still do this by look into the relevant pipeline code, should not be too hard to hack your way through like this:

in 3.0 preview you can do this by modifying cocos\core\pipeline\render-additive-light-queue.ts:

function cullSphereLight (light: SphereLight, model: Model) {
    return !!((model.node.layer & light.node!.layer) && model.worldBounds && !intersect.aabbWithAABB(model.worldBounds, light.aabb));
}

function cullSpotLight (light: SpotLight, model: Model) {
    return !!((model.node.layer & light.node!.layer) && model.worldBounds
        && (!intersect.aabbWithAABB(model.worldBounds, light.aabb) || !intersect.aabbFrustum(model.worldBounds, light.frustum)));
}
1 Like