{"record":{"id":"573b43ee7e3c2c73","repo":"phaserjs/phaser","slug":"fragment-shader-failed","errorCode":null,"errorMessage":"Fragment Shader failed:\n","messagePattern":"Fragment Shader failed:\n","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/renderer/webgl/wrappers/WebGLProgramWrapper.js","lineNumber":342,"sourceCode":"        var renderer = this.renderer;\n        var gl = renderer.gl;\n        var vs = this._vertexShader;\n        var fs = this._fragmentShader;\n\n        var failed = 'Shader failed:\\n';\n\n        if (!gl.getProgramParameter(program, gl.LINK_STATUS))\n        {\n            if (!gl.getShaderParameter(vs, gl.COMPILE_STATUS))\n            {\n                console.log(this.vertexSource);\n                throw new Error('Vertex ' + failed + gl.getShaderInfoLog(vs));\n            }\n\n            if (!gl.getShaderParameter(fs, gl.COMPILE_STATUS))\n            {\n                console.log(this.fragmentSource);\n                throw new Error('Fragment ' + failed + gl.getShaderInfoLog(fs));\n            }\n            console.log(this.vertexSource, this.fragmentSource);\n            throw new Error('Link Shader failed:' + gl.getProgramInfoLog(program));\n        }\n\n        this._setupAttributesAndUniforms();\n\n        this.compileTimeMs = performance.now() - this._compileStartTime;\n        this.compiling = false;\n    },\n\n    /**\n     * Set up the attributes and uniforms for this program.\n     * This is called after the program is created or re-created.\n     *\n     * @method Phaser.Renderer.WebGL.Wrappers.WebGLProgramWrapper#_setupAttributesAndUniforms\n     * @private\n     * @since 4.0.0","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/phaserjs/phaser/blob/41be1e462bc600064e498cba370bfa8c5c055a22/src/renderer/webgl/wrappers/WebGLProgramWrapper.js#L324-L360","documentation":"Thrown by WebGLProgramWrapper when the program fails to link and the fragment shader (not the vertex shader) failed to compile. Message is 'Fragment ' + 'Shader failed:\\n' + the info log; the fragment source is console.logged first so you can see the exact GLSL the compiler saw.","triggerScenarios":"Fragment shader with a syntax error, undefined function, precision qualifier problems, unsupported extension, type mismatch, or a uniform/texture lookup that doesn't match.","commonSituations":"Missing precision qualifiers (e.g. no 'precision mediump float;'); using #version 300 es 'out' declaration but writing gl_FragColor; sampling a texture with the wrong sampler type; vendor-specific extension requirements; typo in a uniform name used in a lookup.","solutions":["Read the info log in the error for the exact line/cause.","Look at the console.log of fragmentSource to confirm what was actually compiled.","Add the required precision statement for WebGL1-style shaders.","Ensure output variable style matches the GLSL version (gl_FragColor vs declared out vec4).","Validate sampler/texture type pairs (sampler2D vs samplerCube etc.)."],"exampleFix":"// before\nvoid main() { gl_FragColor = texture2D(uMainSampler, vUv); } // WebGL2 throws\n\n// after\n#version 300 es\nout vec4 fragColor;\nvoid main() { fragColor = texture(uMainSampler, vUv); }","handlingStrategy":"try-catch","validationCode":"function hasFragmentPrecision(src) { return /precision\\s+(lowp|mediump|highp)\\s+float/.test(src) || /^#version\\s+300/m.test(src); }","typeGuard":null,"tryCatchPattern":"try { program.create(vertexSource, fragmentSource); } catch (e) { if (/Fragment Shader failed/.test(e.message)) { console.error('Fragment compile error:', e.message, fragmentSource); /* fix GLSL */ } else throw e; }","preventionTips":["Always declare precision in WebGL1 fragment shaders.","Keep output style consistent with the GLSL version.","Validate offline before loading."],"tags":["renderer","webgl","shader","glsl","phaser4"],"backgroundTag":null,"analyzedSha":"41be1e462bc600064e498cba370bfa8c5c055a22","analyzedAt":"2026-08-13T04:23:39.729Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}