Recent Material Pipeline Changes

So, a PR has been merged:

With it, you can do this change in _buildCustomShader:

private _buildCustomShader(shaderName: string, uniforms: string[], 
      uniformBuffers: string[], samplers: string[], defines: BABYLON.PBRMaterialDefines, 
      attributes?: string[], options?: ICustomShaderNameResolveOptions) : string {

    options!.processFinalCode = (type: string, code: string) => {
        if (type === "vertex") {
            return code;
        }
        const sci = new BABYLON.ShaderCodeInliner(code);
        sci.inlineToken = "#define pbr_inline";
        sci.processCode();
        return sci.code;
    };
    [...]

You can provide through options.processFinalCode a function that will be called with the final shader code before it is being compiled, and you can modify this code.

So, what is done here is that the code (only in fragment, no need for vertex) is inlined: after the processing there’s no more (pbr) function calls, all the calls have been replaced by the function body code, so you end up with having all your fragment code in a single chunk inside the main function of the shader, which is what you wanted in the first place.

The inlineToken #define pbr_inline is the marker that let ShaderCodeInliner locate the functions that need to be inlined: we marked all the pbr block functions with this token.

Let us know if that solves your problems.

1 Like