How to make GridMaterial transparent

Hi,

I have a mesh with GridMaterial, and I am trying to animate fading in/out with various methods

  • mesh.visibility
  • material.alpha
  • material.opacity

but nothing seems to work. See

https://playground.babylonjs.com/#LY8G86#3

The material.opacity seems to successfully make grid lines transparent, but it does not work properly with the area inbetween. I am looking for some advice.

Hey,
Opacity is the property
https://playground.babylonjs.com/#LY8G86#5
line 17

1 Like

@MarianG it is not. It only affects the opacity of lines. The area inbetween is always either at 100% or 8%. Here is what the documentation says

  • opacity : the opacity helps changing the lines opacity. In transparent mode (opacity < 1.0), the empty area will always be at an opacity level of 0.08

Note that despite you set opacity to 0.98, the black color is not at 0.98. And for a smooth transition I need to be able to change the transparency smoothly in range between 0 and 1.

Please look more carefully at the playground example I provided to see that opacity does not animate smoothly all values.
https://playground.babylonjs.com/#LY8G86#6

I don’t think there is control that works here in the current state. Looking at the shader, the closest thing is opacity, but it doesn’t do a visibility fade like other materials.

I made some local changes to the code to make mesh.visibility work, but I’m not sure if it should be added. @Deltakosh/@sebavan/@Evgeni_Popov What do you think?

Comparing BabylonJS:master…bghgary:gridMaterial-visibility · BabylonJS/Babylon.js (github.com)

LGTM :slight_smile:

Awesome. PR created: Add mesh.visibility support to grid material by bghgary · Pull Request #10519 · BabylonJS/Babylon.js (github.com) :slight_smile:

3 Likes

Note that you can also use the NME version of this material, if you want more control:

1 Like

@bghgary @Evgeni_Popov @sebavan thank you so much!

I think for now I will stick to the modified GridMaterial, but once I need to texture it, I will consider the NME version.

1 Like