From db056481ae8207e0df2bd84a44920f3e2416c6b3 Mon Sep 17 00:00:00 2001 From: harshiltewari2004 Date: Tue, 14 Jul 2026 04:38:17 +0530 Subject: [PATCH] Add mat2 uniform support to WebGL setUniform, fixing silent no-op (#8939) --- src/webgl/utils.js | 4 ++++ test/unit/visual/cases/webgl.js | 18 ++++++++++++++++++ .../mat2 uniforms are uploaded/000.png | Bin 0 -> 238 bytes .../mat2 uniforms are uploaded/metadata.json | 3 +++ 4 files changed, 25 insertions(+) create mode 100644 test/unit/visual/screenshots/WebGL/setUniform/mat2 uniforms are uploaded/000.png create mode 100644 test/unit/visual/screenshots/WebGL/setUniform/mat2 uniforms are uploaded/metadata.json diff --git a/src/webgl/utils.js b/src/webgl/utils.js index a5742c3f50..2d79b14578 100644 --- a/src/webgl/utils.js +++ b/src/webgl/utils.js @@ -222,6 +222,9 @@ export function setWebGLUniformValue(shader, uniform, data, getTexture, gl) { gl.uniform1f(location, data); } break; + case gl.FLOAT_MAT2: + gl.uniformMatrix2fv(location, false, data); + break; case gl.FLOAT_MAT3: gl.uniformMatrix3fv(location, false, data); break; @@ -360,6 +363,7 @@ export function getWebGLUniformMetadata(shader, gl) { uniform.isArray = uniformInfo.size > 1 || + uniform.type === gl.FLOAT_MAT2 || uniform.type === gl.FLOAT_MAT3 || uniform.type === gl.FLOAT_MAT4 || uniform.type === gl.FLOAT_VEC2 || diff --git a/test/unit/visual/cases/webgl.js b/test/unit/visual/cases/webgl.js index 618078bc81..8edf5523d0 100644 --- a/test/unit/visual/cases/webgl.js +++ b/test/unit/visual/cases/webgl.js @@ -1521,6 +1521,24 @@ visualTest('randomGaussian() in a fragment loop averages to the mean', (p5, scre }); }); + visualSuite('setUniform', () => { + visualTest('mat2 uniforms are uploaded', (p5, screenshot) => { + p5.createCanvas(50, 50, p5.WEBGL); + const myShader = p5.createFilterShader(` + precision highp float; + uniform mat2 uMatrix; + void main() { + // Diagonal drives red & green: expect (1.0, 0.5, 0.0) + gl_FragColor = vec4(uMatrix[0][0], uMatrix[1][1], 0.0, 1.0); + } + `); + p5.background(200); + myShader.setUniform('uMatrix', [1.0, 0.0, 0.0, 0.5]); + p5.filter(myShader); + screenshot(); + }); + }); + visualSuite('background()', function () { visualTest('background(image) works in WEBGL', function (p5, screenshot) { p5.createCanvas(50, 50, p5.WEBGL); diff --git a/test/unit/visual/screenshots/WebGL/setUniform/mat2 uniforms are uploaded/000.png b/test/unit/visual/screenshots/WebGL/setUniform/mat2 uniforms are uploaded/000.png new file mode 100644 index 0000000000000000000000000000000000000000..e0b865144266120e22c18637d2d4e54bfb5abaf5 GIT binary patch literal 238 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=1|;R|J2nET#hxyXAr*{oCOL977zi+X$KRX3 zUj9U?xbv2t2dW!5&+T}