How to grayscale model?: Is there any way to toggle off and on albedo color to white and back to original color?

I’m trying to grayscale my model with a toggle I managed to turn off/on the core texture channels via:

StandardMaterial.DiffuseTextureEnabled = !StandardMaterial.DiffuseTextureEnabled;
//StandardMaterial.AmbientTextureEnabled = !StandardMaterial.AmbientTextureEnabled;
StandardMaterial.SpecularTextureEnabled = !StandardMaterial.SpecularTextureEnabled;
StandardMaterial.EmissiveTextureEnabled = !StandardMaterial.EmissiveTextureEnabled;
StandardMaterial.BumpTextureEnabled = !StandardMaterial.BumpTextureEnabled;
StandardMaterial.OpacityTextureEnabled = !StandardMaterial.OpacityTextureEnabled;
// StandardMaterial.ReflectionTextureEnabled = !StandardMaterial.ReflectionTextureEnabled;
StandardMaterial.RefractionTextureEnabled = !StandardMaterial.RefractionTextureEnabled;
StandardMaterial.ColorGradingTextureEnabled = !StandardMaterial.ColorGradingTextureEnabled;
StandardMaterial.LightmapTextureEnabled = !StandardMaterial.LightmapTextureEnabled;
StandardMaterial.FresnelEnabled = !StandardMaterial.FresnelEnabled;

but the problem with this is that it leaves the textures’ albedo colors the same:

original:


texture channels toggled off:

I’d rather not save each texture’s albedo color in memory for the purposes of toggling to grayscale and back. Is there anyway to turn off the albedo color entirely? Turning off the albedoTexture channel does not achieve this. Any suggestions in a different direction are also welcome! :slight_smile:

Thanks!

Hi johntdaly7,

I’m not sure I fully understand the effect you’re trying to achieve. If you’re just trying to desaturate the render, a postprocess effect might be the easiest way to do that. There’s a built-in one for a black-and-white effect; does that do something like what you’re looking for?

1 Like

Thanks for your response, @syntheticmagus!!

Yeah I was thinking that a post process would work best, but black and white isn’t quick what I’m going for. I’m trying to achieve something like this:


Babylon doesn’t seem to offer this style of post process natively.

I can get there by disabling all of the texture channels except ambient occlusion and reflectivity.

But the issue is that (as seen above) some of the materials maintain their albedo colors. If I were to change those materials’ albedo colors to white, I would have to save their original albedo color values in order to switch back, no? I’d rather not save these values in memory, and was wondering if there was a better way to do it.

Seems that BW postProcess, as mentioned above, really could help with the grayscale effect which you are trying to achieve if I understand it correctly.
Here is the example - https://playground.babylonjs.com/#L92PHY#64

Toggle with SPACE and B key - https://playground.babylonjs.com/#L92PHY#66

I think you need baked textures with ambient occlusion and all materials are nodeMaterials with 2 textures - original and the one just with ambient occlusion. Then add a gradient node and a float input to switch hard or soft between the two textures.