I’ve been experimenting with using GLSL for shaders. I’ve been able to integrate them into code. I am now having difficulties taking the generated shader output from the Node Material Editor (NME) and doing the same thing. It seems the code is having trouble expanding the several #include
statements within the code.
I am familiar with C and so am familiar with the use of a preprocessor, but am not clear on how these statements are functioning. This statement #include<lightFragmentDeclaration>[0..maxSimultaneousLights]
is odd as it includes the additional square bracket syntax and an additional parameter.
My attempt at integration can be found within this playground. First, I established that I could integrate the Phong Shader from CYOS. Then, I tried to integrate the shader from my NME instance. This fails. The playground includes these details in the comments as well.
To make experimentation on the playground simple, I implemented a conditional based on the first variable defined USE_NME_SHADER
. If false, the Phong shader from CYOS is used. Else, the shader code generated from NME is used.
I gather that the NME includes these statements to reuse existing code modules for often implemented functions, i.e., for modularity. I was able to find the relevant include code on GitHub here. I see code that should explain the use of the #include syntax, but I am not sure where it’s from.
I find that .fx extensions are used for DirectX, but it seems other options are possible too.
At this stage, I thought it’d be worthwhile to ask. Can anyone shed some light on the .fx format, and perhaps point to documentation for these include statements? I’d like to understand this code (I’m willing to work through it; I understand there will be several hundreds of lines) and be able to directly integrate the output from NME into a Babylon.js material. Is there a more direct way to get the playground to run, or to have the NME generate the shader code after the preprocessor has run?
At this stage, as I’m still learning, it’s best to dig all the way down to the code instead of relying completely on systems that hide the complexity. I see lots of code and examples online, and it’d be nice to dive into the nuts and bolts directly. It’d also be nice to see exactly what the NME is doing behind the scenes. I feel that once I better understand this, I’ll be able to use the NME more effectively as well.
Thank you very much.