{"record":{"id":"c144194028f608f8","repo":"BabylonJS/Babylon.js","slug":"webgpu-shader-language-is-only-supported-with-webg","errorCode":null,"errorMessage":"WebGPU shader language is only supported with WebGPU engine","messagePattern":"WebGPU shader language is only supported with WebGPU engine","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Materials/Node/nodeMaterial.pure.ts","lineNumber":442,"sourceCode":"    }\n\n    /**\n     * A free comment about the material\n     */\n    @serialize(\"comment\")\n    public comment: string;\n\n    /**\n     * Create a new node based material\n     * @param name defines the material name\n     * @param scene defines the hosting scene\n     * @param options defines creation option\n     */\n    constructor(name: string, scene?: Scene, options: Partial<INodeMaterialOptions> = {}) {\n        super(name, scene || EngineStore.LastCreatedScene!);\n\n        if (!NodeMaterial.UseNativeShaderLanguageOfEngine && options && options.shaderLanguage === ShaderLanguage.WGSL && !this.getScene().getEngine().isWebGPU) {\n            throw new Error(\"WebGPU shader language is only supported with WebGPU engine\");\n        }\n\n        this._options = {\n            emitComments: false,\n            shaderLanguage: NodeMaterial.DefaultShaderLanguage,\n            ...options,\n        };\n\n        if (NodeMaterial.UseNativeShaderLanguageOfEngine) {\n            this._options.shaderLanguage = this.getScene().getEngine().isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL;\n        }\n\n        // Setup the default processing configuration to the scene.\n        this._attachImageProcessingConfiguration(null);\n    }\n\n    /**\n     * Gets the current class name of the material e.g. \"NodeMaterial\"","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Materials/Node/nodeMaterial.pure.ts#L424-L460","documentation":"NodeMaterial supports WGSL (WebGPU shader language), but constructing one with ShaderLanguage.WGSL is only valid when the underlying engine is a WebGPU engine. Creating a WGSL NodeMaterial on WebGL throws immediately in the constructor.","triggerScenarios":"new NodeMaterial('m', scene, { shaderLanguage: ShaderLanguage.WGSL }) while running on a WebGLEngine (engine.isWebGPU === false), with NodeMaterial.UseNativeShaderLanguageOfEngine unset.","commonSituations":"Porting WebGPU projects back to WebGL or testing on browsers without WebGPU; engine type chosen at runtime (EngineFactory) but shader language hardcoded to WGSL.","solutions":["Run on a WebGPU engine (WebGPUEngine.IsSupportedAsync + WebGPUEngine creation) when using ShaderLanguage.WGSL","Choose shaderLanguage based on engine.isWebGPU: GLSL for WebGL engines","Unify with NodeMaterial.DefaultShaderLanguage rather than forcing WGSL"],"exampleFix":"// before\nconst mat = new NodeMaterial('m', scene, { shaderLanguage: ShaderLanguage.WGSL }); // WebGL engine\n// after\nconst lang = scene.getEngine().isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL;\nconst mat = new NodeMaterial('m', scene, { shaderLanguage: lang });","handlingStrategy":"validation","validationCode":"const shaderLanguage = scene.getEngine().isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL;\nconst mat = new NodeMaterial('m', scene, { shaderLanguage });","typeGuard":"const supportsWGSL = (engine: AbstractEngine): engine is WebGPUEngine => engine.isWebGPU;","tryCatchPattern":"try {\n  return new NodeMaterial(name, scene, options);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('WebGPU shader language')) {\n    return new NodeMaterial(name, scene, { ...options, shaderLanguage: ShaderLanguage.GLSL });\n  }\n  throw e;\n}","preventionTips":["Derive shader language from engine type instead of hardcoding WGSL","Feature-detect WebGPU and fail with a clear app-level message before creating materials","Keep shader language consistent across all materials in a scene"],"tags":["babylonjs","webgpu","node-material","engine-mismatch"],"backgroundTag":"webgpu-engine-required","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}