Сustom shadow for model

It is possible to set a custom shadow model for the mesh ?

Not really, not using public API I think.
Why do you need it?

My algorithm can specify which LOD will be displayed by changing the primitive properties.

I would like to specify which LOD was taken into account when rendering shadows.

For example, LOD 0 corresponds to buffer data:

baseVertex = 0
base = 0
count = 1024

For example, LOD 1 corresponds to buffer data:

baseVertex = 2
base = 512
count = 512

And so on, I would like the user to choose which LOD to use for shadows.

            if (buffer.hash !== patchHash) {

                // In theory we can control the quality of the model for shadows
                meshInstance.setParameter(baseVertexAttrName, baseVertex, 0xffffff);
                meshInstance.setParameter(lodCoreAttrName,    lod.core, 0xffffff);
            }

            buffer.hash              = patchHash;
            buffer.visible           = true;
            buffer.indicesBaseIndex  = baseIndex;
            buffer.indicesBaseVertex = baseVertex;
            buffer.indicesCount      = count;
            buffer.lod               = lod;

            // @ts-ignore
            primitive.baseVertex = baseVertex; // TODO
            primitive.base       = baseIndex;
            primitive.count      = count;
            primitive.indexed    = true;
            primitive.type       = this._wireframe ? pc.PRIMITIVE_LINES : pc.PRIMITIVE_TRIANGLES;

maybe in your specific case, you can set different parameters for the different passes.

// shadow pass
const shadowBitmask = 1 << pc.SHADER_SHADOW;
meshInstance.setParameter(baseVertexAttrName, baseVertex, shadowBitmask);

// normal rendering
const otherBitmask = ~(1 << pc.SHADER_SHADOW);
meshInstance.setParameter(baseVertexAttrName, baseVertex, otherBitmask);

actually not sure this would work, I don’t think we can store different parameters with the same name

maybe you could set normal parameter on the material, and shadow override on the mesh instance - but it’s likely you don’t have a unique material to do that

Is it possible to set primitives specifically for the shadow map?

For example:

const shadowPrimitiveIndex = 777;
const primitive = mesh.primitive[shadowPrimitiveIndex];

primitive.baseVertex = baseVertex; // TODO
primitive.base           = baseIndex;
primitive.count          = count;
primitive.indexed      = true;

Nope.

Thanks for the answer, without changing the engine the best option is to duplicate the meshes for shadows separately.

even then there is no option to render mesh only to the shadow map … so you’d need some workarounds.

how about this suggestion above?

maybe you could set normal parameter on the material, and shadow override on the mesh instance - but it’s likely you don’t have a unique material to do that

Can you give an example? I don’t quite understand the idea.

I assumed you could control the LOD by setting a uniform … in which case this could work. But looking at your example, I don’t think that is the case.

Yes, there is not only a uniform but also a base, count, etc. (If WebGPU use baseVertex)