How to get shader gl compilation errors from Babylon?

I’m working on a shader editor with support for Babylon. I’m using processFinalCode to put my own raw GLSL into a Babylon shader. When I get compilation errors, the only place I can see them is in the console. I’d like to surface these in the UI.

I see that program link errors are attached to an internal pipelineContext variable. Is this variable exposed to end users? It also looks like, from the source code, that shaders are deleted if they’re failed to link, they’re deleted? I’m not sure - however when I call mesh.material.getEffect() after a failed compile - it’s undefined.

I could get there with engine.gl.getProgramParameter(babylonvertexprogram) - but I’m not sure if it’s possible to get a material’s gl program?

Hijacking Logger.Error may be an option, although lines like these:

            if (lineErrorVertex) {
                Logger.Error(lineErrorVertex);
            }
            if (lineErrorFragment) {
                Logger.Error(lineErrorFragment);
            }

mean that I can’t as easily intercept needed messages, as these have no prefix string

1 Like

Hey @andyray, can you hook your code into the effect.OnError callback?

Else the pipelineContext is available on effect.getPipelineContext property :slight_smile:

2 Likes

Hi @Deltakosh , when I do this:

    const shaderMaterial = new BABYLON.PBRMaterial(`pbr${id()}`, scene);
    const effect = shaderMaterial.getEffect();
    effect.onError = ...;

Typescript says everything is fine, but effect is undefined at runtime.

You should hook into onEffectCreatedObservable as the effect is stored per submesh for caching purpose