[SOLVED] How to set an entity to 'unlit'?

Hi,
One of my entities in the scene should not be effected by lights. It should just present itself with the color in the diffuse map, independant of lights.
How can I do that? Do I have to create and set a special shader for it?

Hi @simmania ,

At the bottom of the material inspector you can uncheck “Use lighting” and set the texture/colour you want under emissive.

Thanks!

1 Like

Well, my project is engine-only. How can I do this in code?

Find your material and set the useLighting property on it:

material.useLighting = false;
material.update();

https://developer.playcanvas.com/en/api/pc.StandardMaterial.html#useLighting

1 Like

This example uses it: PlayCanvas Examples

        const material = new pc.StandardMaterial();
        material.useLighting = false; // turn off lighting - we use emissive texture only. Also, lighting needs normal maps which we don't generate
        material.diffuse = new pc.Color(0, 0, 0);
        material.emissiveVertexColor = true;
        material.blendType = pc.BLEND_ADDITIVE; // additive alpha blend
        material.depthWrite = false; // optimization - no need to write to depth buffer, as decals are part of the ground plane
        material.emissiveMap = assets.spark.resource;
        material.update();
1 Like

Thx.

That works, but I get always a black model.

I change the material of my model as follow:

        // update the material so that does not use lighting
        this.mShipWFMaterials = assets.ship_wireframe.resource.materials;
        for (const materialAsset of this.mShipWFMaterials) {
            const material = materialAsset.resource;
            material.useLighting = false; // turn off lighting - we use emissive texture only.
            material.diffuse = new pc.Color(0, 0, 0);
            material.emissiveVertexColor = true;
            material.blendType = pc.BLEND_ADDITIVE; // additive alpha blend
            material.update();
        }

It works, but the color I get is always black. Doesn’t matter what I fill in for the material.diffuse.
Do have to enable emissive somehow? I do not have an emissive texture in the model.

you need to use emissive color or emissive texture, as the diffuse color / texture is black without lighting.

1 Like

Ok, that helped!

This is the code I use now:

        this.mShipWFMaterials = assets.ship_wireframe.resource.materials;
        for (const materialAsset of this.mShipWFMaterials) {
            const material = materialAsset.resource;
            material.useLighting = false; // turn off lighting
            material.emissive = new pc.Color(244 / 255, 116 / 255, 33 / 255);
            material.update();
        }

Works perfectly now!