Is possible to apply a map of normals in a cell material?

I’m trying to apply a map of normals in a cell material but I can’t find the correct way to do it

    function createCellMaterial(texture, normalMapTexture, scene) {
        let nameCellMaterial = "cell_" + texture.name + "basic";

        let cellMaterial = scene.getMaterialByName(nameCellMaterial);

        //check if material is already created
        if (cellMaterial === null) {
            cellMaterial = new MATERIALS.CellMaterial(nameCellMaterial, scene);
        } else {
            return cellMaterial;
        }

        cellMaterial.diffuseTexture = texture;
        cellMaterial.computeHighLevel = true;
        cellMaterial.diffuseTexture.level = 10;
        cellMaterial.normal = true

        if (normalMapTexture !== null) {
            cellMaterial.bumpTexture = normalMapTexture
            cellMaterial.bumpTexture.level = 10
        }

        cellMaterial.transparencyMode = 1

        return cellMaterial;
    }

This doesn’t look like that is applying anything :frowning:

That should work. Can you try to repro in the PG so we can have a look?

Thanks for your fast answer, here you have:
https://playground.babylonjs.com/#CL06E8

If you comment line 61 you’ll see that the model has the normal map applied

Alright ;D I’ve just checked the code and actually Cellmaterial has no support for normal maps (Sorry for the bad news…)

Maybe someone from the community would be interested into adding support for it?

we might work on that!

Do you know if there is any NME material, with the official CellMaterial to have something to start with?

Thanks in advance!

I believe (and I could be totally wrong) that @PatrickRyan started something along these lines lately

1 Like

@quevedin, the cell shader I am building into a future demo isn’t quite what you were looking for, so I quickly put together a shader which gives you some control over the number of bands in the cell shading, the shadow color, and does take a normal texture and base color texture. An example of the node material looks like this:

The shader is just the minimum of what you need to create the look you are going for:

Basically, we are taking the light direction dotted with the perturbed surface normal remapped to the range 0-1 as a mask for a lerp between the base color texture and the shadow color multiplied by the base color texture.

There are a lot of other things that you could do in this shader since it’s a custom lighting method, but it really depends on the look you are going for. I hope this gets you unblocked for your project, but feel free to ping me with questions. Here is the shader:

Cell shader with normal texture support (babylonjs.com)

2 Likes

Awesome Patrick!

We can use that!
If we find a way to “improve it” we will post the node material here

Thanks for your time!!!

1 Like