Applying toon shader to a model

Hi everyone!

I have a bit of a pickle trying to get the toon shader working on my model. I decided to try and hack this together in a playground here:

But as you can see, the model is pretty much black after I try to replace my emission material with the node material. Could someone explain what I do wrong here :frowning:

Also, not sure if this is due to this particular node material being “old”, but touching the “Light Information” -node seems to crash the whole editor :exploding_head: Take a look: https://nme.babylonjs.com/#81NNDY#126

Never mind it seems I was copy pasting a wrong texture to the node material one. https://playground.babylonjs.com/#S7E00P#285

I wonder if there is any other way of doing this than manually copy pasting the texture from emissive/whatever texture to the node material texture slot… :thinking:

I seem to not get into same results I get with shaderball here:
shader-ball-toon
vs

I wonder if it is the lighting in the playground or something else… Any ideas? This is the most current pg:

Yeah it was lighting, check this pg :slight_smile:

Carry on everyone! Nothing to see here :laughing:

Sorry for the spam, I have some other question as well. I updated the model since I forgot to add an texture for the body… And then there was some weird depth/transparency problems that I could not get fixed without setting:

cnm.needAlphaBlendingForMesh = () => false

But I do now know how to actually set this initially from the node material editor? Could someone advice me on this? :slight_smile:

Here is the latest playground with the line that “fixes” the problem.

Hmm I took a look at the NME and there isn’t a way to set the transparencyMode (which setting to opaque would solve your problem), only alpha mode… any objections to just adding it here @PatrickRyan ?
image

And the reason we have to set the transparency mode is because of this material that does use alpha blending, so it ends up turning alpha blending for all the meshes I think (is that right @sebavan ?):

1 Like

There is a ignoreAlpha prop for this on nme IIRC ?

1 Like

@Panuchka, what is happening is that your mesh has vertex color baked into every vertex. It is set to Color4(1, 1, 1, 1) which gives the vertices an alpha value. If the mesh has data for alpha or a node material has a value wired to alpha, the material will be considered to be in alpha blend mode.

The easiest way around this would be to remove the vertex color from your mesh. The other would be to explicitly set the Transparency Mode on your material which will override the automatic assignment based on mesh color alpha or nme alpha connection. You would do this with:

nodeMaterial.transparencyMode = 0

2 Likes