Creating custom material with babylon in npm

Hello. First post here!

I’ve been trying to follow the guide at Create a Material for the Materials Library - Babylon.js Documentation.

Doing that is a bit akward since I use babylon using npm so I can’t change the material library there. Instead I need to clone a fresh babylon and do my work there to produce a new material library. I build it using gulp. However I am having issues using it (my own material library) from typescript.

My question then; Is there an example where a custom material is added outside of the babylon source code? Preferably in typescript.

If not, is there an example that does what I tried above succeesfully? I ran into issues with importing modules but it might be due to my inexperience with typescript. If this is the way to do it I can show the exact issues I am running into (if there is no example to look at).

Cheers!

Hey!

You actually need nothing more than this file:

The only change you need is to provide the shader code as a text

Other option is to use:

1 Like

Oh. I was trying that but did not think it would work out in the end. That is encouraging!

Will that work even if the shaders (in text) uses include? To me it seems that the build steps that process the fx-files does quite a bit of work that I am not sure would work without it.

My goal is to clone the pbr material since I need to change it in ways that is not currently possible so we are not talking about short shaders snippets I am afraid :frowning: So using includes would help.

Thanks for you help so far. I am trying on my side to understand what is possible.

Have you tried PBRCustomMaterial?

https://doc.babylonjs.com/api/classes/babylon.pbrcustommaterial

https://www.babylonjs-playground.com/#LIVRIY#11
https://www.babylonjs-playground.com/#VGWB9T#5

Hi Evgeni,

I’ve seen it and I came to the conclusion that I would need to customize the shader more than what it allowed for. I was thinking of copying it and then adding mechanism for adding custom shaders anywhere (not only at the CUSTOM-defined points), but that would be very brittle when we change the babylon version and the PBR-material shader source is changed. Will try the other approach some more!