Node material mesh alpha interpolation

Hello everyone.
Im totaly new at shaders. Node material makes life easier for people like me. But still, im struggling with one thing:
Im trying to interpolate alpha for mesh instances (using distance and time).
Here is the link https://nodematerial-editor.babylonjs.com/#B08JDF#18

The querstion is: How to set whole mesh alpha to 0 or 1, without “fading in”? As u can see it goes as a wave from some point (called origin) and checks if mesh is in the radius then alpha is 1, otherwise its 0.
I tried clamp, tried output of condition block straight away, but still there is fading effect.

Doing properties per full mesh is easier if you can manipulate the buffers with code, it’s not much code for that, you can see an example here: Babylon.js Playground (babylonjs.com)

Here, I’m using a custom color buffer ( Instances | Babylon.js Documentation (babylonjs.com)) to set the color of the entire instance according to the distance from the instance to the center. If you have any questions about the code, feel free to ask!

Thanks for your reply!
In your example I dont see anything related to the node materials, I expand the radius dinamically using interpolation functions and set the alpha depending on the distance. Am I able to get an access to the custom buffer data (like color) within node material?

Yes you can! You can just access the mesh.color block on the NME, it will have the per-instance attribute. Since you mentioned you change the radius dynamically, I changed the approach a bit and instead of calculating the distance and defining the color in code, I’m passing the position of the instance as the color attribute itself (you don’t need to use the color attribute for colors only, you can use for anything that needs to be set on the instance level), and performing the calculation on the node material: Babylon.js Playground (babylonjs.com)

Wow, im speechless!
Thank you so much!

1 Like

In addition want to put it here:

Looks like finalWorld[3].xyz is the instance position.
I assime this node is the finalWorld[3]

Sorry, what do you want to put here? The distance calculation?