[SOLVED] Casting shadows procedural mesh

I succeeded in creating a procedural mesh with everything I need (vertices, uv, normals, tangents and color information). But I can’t seem to make it cast any shadow. I’m setting the castShadow property to true on the mesh instance, but this doesn’t seem to make any difference.

var meshint = new pc.MeshInstance(node, mesh, material);
meshint.castShadow = true;

Anybody with an idea about how to make a mesh cast shadows?

Have you also enabled shadow casting for your light entities?

entity.light.castShadows = true;

Yes, normal entities (placed in the editor) do cast shadows, also the procedural mesh is receiving shadows from the normal entities.

Ok, by stepping through the engine code I found out that on adding a model to a modelcomponent all the meshinstance properties concerning shadows are overwritten by the modelcomponent properties. So the solution is:

var node = new pc.GraphNode();
            var model = new pc.Model();
            model.graph = node; 
            //build mesh
            this.entity.model.castShadows = true;
            this.entity.model.model = model;

Now I still have a problem left, the shadows look terrible as you can see in the screenshot (note that the back wall is completely flat, so why it is showing that pattern, I have no clue :s)

I think this is a bug in the engine. As a workaround, you can change:

        this.entity.model.model = model;
        this.entity.model.model.castShadows = true;


        this.entity.addComponent('model', {
            castShadows: true
        this.entity.model.model = model;

To get rid of the artifacts, please consult these links:


Thanks Will, I’ll go trough them! Also thanks for your post concerning the castShadows property. Your solution of adding the properties through the constructor looks cleaner!

No problem. Regarding shadow bias and normal offset bias, just set them in the Light component UI in the Editor. Try setting both to 0.05.