Using shaders exported from Node Material Editor

Hi there, I’ve built my first custom shaders, using Node Material Editor, but I’m having trouble integrating them into a playground.

If I use the generate code button, and just use that as a material, it seems to work, but if I just export the shaders, I see errors in the console, and nothing renders.

https://nme.babylonjs.com/#UB2GNV#3 - I exported both code, and shaders from this NME to generate:

https://playground.babylonjs.com/#3H07XJ#4 - Shaders playground, does not render

Babylon.js Playground - Generated code playground, renders fine

Am I using the ShaderMaterial wrongly?

Thanks!

Adding @Evgeni_Popov

The exported shader code is not really meant to be used directly because it would need a lot of wrapping to be functional. See #include directives in shader code output from Node Material Editor for eg.

What you should do is either exporting the js code, as you did in your PG or use the NodeMaterial.ParseXXX functions: https://playground.babylonjs.com/#JICX85#1

2 Likes

Thank you! That thread was really helpful.

The reason I wanted to use shaders was to have a way to select a slice of a texture, per instance of a mesh.

CustomMaterial saved my day here! Here’s my example: https://playground.babylonjs.com/#NICGSS#6

You can also inject a new attribute in a node material by using the same technic than described here: Thin instances, node material and custom attribute

https://playground.babylonjs.com/#NICGSS#10