Background:
I’m trying to implement the WEBGL_multi_draw extension in babylon.js, see previous context here:
Per spec, #extension GL_ANGLE_multi_draw needs to be added to the shader, but when doing this in a material plugin, it emits error:
BJS - [09:42:26]: Error: VERTEX SHADER ERROR: 0:296: '
' : extension directive must occur before any non-preprocessor tokens in ESSL3
Playground:
After hours of searching in the code base, I found engine._shaderProcessor which can do this, but it’s marked with protected, and can not be used in typescript without force cast of Reflect things:
Question:
Is there a standand way, to require GLSL extension for material
I think the easiest way would be to simply move #define CUSTOM_VERTEX_BEGIN / #define CUSTOM_FRAGMENT_BEGIN at the very start of the standard / PBR shader files, and use CUSTOM_VERTEX_BEGIN as the injection point in your material plugin.
I don’t think it would be a breaking change, as they are currently defined just after a #include<__decl__pbrXXX>, which only inject struct / uniform definitions.
No, it would work for any number of plugins: the #define CUSTOM_VERTEX_BEGIN line is not removed when a plugin inject some code, so another plugin can still inject code at the same place.