add uResolution uniform2f

This commit is contained in:
Emile Clark-Boman 2026-01-31 11:40:22 +10:00
parent 9681cc76fa
commit 6ffcfa692e
3 changed files with 15 additions and 9 deletions

View file

@ -18,6 +18,12 @@ function drawScene(gl, programInfo, buffers, time) {
programInfo.uniformLocations.time,
time,
);
// Viewport resolution in pixels
gl.uniform2f(
programInfo.uniformLocations.resolution,
gl.drawingBufferWidth,
gl.drawingBufferHeight,
);
{
const offset = 0;

View file

@ -121,7 +121,7 @@ function main() {
vertexPosition: gl.getAttribLocation(shaderProgram, "aVertexPosition"),
},
uniformLocations: {
// resolution: context.getUniformLocation(program, "uResolution"),
resolution: context.getUniformLocation(program, "uResolution"),
time: gl.getUniformLocation(shaderProgram, "uTime"),
},
};
@ -141,7 +141,6 @@ function main() {
// deltaTime = time - prevTime;
// prevTime = time;
console.log(time)
drawScene(gl, programInfo, buffers, time);
requestAnimationFrame(render);
}

View file

@ -9,6 +9,7 @@ precision highp float;
#endif
uniform float uTime;
uniform vec2 uResolution;
/* ==== Text Colouring ==== */
#define PHOSPHOR_COL vec4(1, 1., 1., 1.)
@ -150,9 +151,9 @@ float roundLine(vec2 p, vec2 a, vec2 b) {
b -= a + vec2(1.0,0.);
p -= a;
float f = length(p-clamp(dot(p,b)/dot(b,b),0.0,1.0)*b);
if (iResolution.y < 320.) // attempt to get rid of aliasing on small resolution
if (uResolution.y < 320.) // attempt to get rid of aliasing on small resolution
return smoothstep(1.0, 0.9, f);
else if (iResolution.y < 720.)
else if (uResolution.y < 720.)
return smoothstep(0.75, 0.5, f);
else
return smoothstep(1., 0., f);
@ -357,12 +358,12 @@ float bloom(vec2 uv2) {
}
void mainImage(out vec4 fragColor) {
vec2 uv = vec2(gl_FragCoord.x, iResolution.y - gl_FragCoord.y);
vec2 uvT = ROWCOLS * FONT_SIZE * uv / iResolution.xy;
vec2 uvG = floor(ROWCOLS * uv / iResolution.xy);
vec2 uvC = gl_FragCoord/iResolution.xy;
vec2 uv = vec2(gl_FragCoord.x, uResolution.y - gl_FragCoord.y);
vec2 uvT = ROWCOLS * FONT_SIZE * uv / uResolution.xy;
vec2 uvG = floor(ROWCOLS * uv / uResolution.xy);
vec2 uvC = gl_FragCoord/uResolution.xy;
vec2 uvNoise = gl_FragCoord.xy / iResolution.xy;
vec2 uvNoise = gl_FragCoord.xy / uResolution.xy;
uvNoise = ceil(uvNoise * ROWCOLS) / ROWCOLS;
float val;