Magic in source shader code

#include<samplerVertexDeclaration>(_DEFINENAME_,ALBEDO,_VARYINGNAME_,Albedo)
...
#include<samplerVertexImplementation>(_DEFINENAME_,ALBEDO,_VARYINGNAME_,Albedo,_MATRIXNAME_,albedo,_INFONAME_,AlbedoInfos.x)

How do these two magic “include” work? Their inputs(I just guess) are kind of like macro, but I have no idea how they work.

It simply includes the content of the file referenced between <...> (found in Shaders/ShadersInclude/) applying some global replacing on the content:

#include<file>(a,b,c,d,e,f,...)

=> it replaces all occurrences of a by b, all occurrences of c by d, etc on the content of file.

7 Likes

That’s very smart :star_struck: Where can I learn more about this? Any reference will be helpful.

There’s no documentation about this as it is some implementation detail. You can learn more by reading the Babylon.js source code :slight_smile:

Its here: Babylon.js/shaderProcessor.ts at master · BabylonJS/Babylon.js · GitHub

1 Like

That’s what I am looking for! :laughing: