Search code examples
shaderwebglphaser-framework

ERROR :GL_INVALID_OPERATION : glUniform1iv: count > 1 for non-array Phaser 3.52


Phaser 3.52, cant get shader working: https://codesandbox.io/s/outlinepipeline-forked-o1jgo

Have a gl error: [.WebGL-0x7fd99580aa00]GL ERROR :GL_INVALID_OPERATION : glUniform1iv: count > 1 for non-array


Solution

  • There are two ways to address this. The first is to use an array of sampler2D since that's what MultiPipeline will be passing in (and the source of that GLSL error, I believe)

            uniform sampler2D uMainSampler[2]; // This I believe can go up to 16, but the texture we want to use is at uMainSampler[1]
            // ...
    
            void main(void) 
            {
              vec4 texture = texture2D(uMainSampler[1], outTexCoord);
              // ...
    
              
              float upAlpha = texture2D(uMainSampler[1], outTexCoord + vec2(0.0, onePixel.y)).a;
              float leftAlpha = texture2D(uMainSampler[1], outTexCoord + vec2(-onePixel.x, 0.0)).a;
              float downAlpha = texture2D(uMainSampler[1], outTexCoord + vec2(0.0, -onePixel.y)).a;
              float rightAlpha = texture2D(uMainSampler[1], outTexCoord + vec2(onePixel.x, 0.0)).a;
    
              // ...
    
              gl_FragColor = color;
            }
    

    An alternative (and I think, simpler) solution would be to have your OutlinePipeline extend from Phaser.Renderer.WebGL.Pipelines.SinglePipeline instead of MultiPipeline.

    To be honest, I don't understand why the Phaser docs state that MultiPipeline is the replacement for TextureTintPipeline when creating your own Custom pipeline when TextureTintPipelines were originally single texture pipelines. I'll admit, I'm still working my way around these pipelines, so it's possible I just don't understand something very simple.