Skip to content

Commit a41404c

Browse files
committed
fix: correctly specify aPosition attribute index
1 parent 2da7284 commit a41404c

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

app/(articles)/render.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ uniform float size_div;
2222
uniform float far_grain;
2323
uniform float close_grain;
2424
uniform float blur_size;
25-
uniform vec2 spawn;
2625
uniform vec2 start;
2726
uniform vec2 size;
2827
@@ -112,7 +111,6 @@ vec3 get_uv_clr (vec2 uv) {
112111
}
113112
114113
void main() {
115-
// vec2 uv = vTexCoord;
116114
vec2 uv = vec2((gl_FragCoord.x - start.x) / size.x, gl_FragCoord.y / size.y);
117115
uv.x = uv.x * size_div;
118116
uv.xy = uv.xy * 0.9;
@@ -152,7 +150,7 @@ function rand(_min: number, _max: number) {
152150
return _min * (1 - t) + _max * t;
153151
}
154152

155-
function randCoors(): [number, number] {
153+
function randCoords(): [number, number] {
156154
return [rand(0.1, 0.9), rand(0.1, 0.9)];
157155
}
158156

@@ -238,7 +236,6 @@ export function drawGradients(
238236

239237
// Prepare uniform variables
240238
const size_div = gl.getUniformLocation(progDraw, "size_div");
241-
const spawn = gl.getUniformLocation(progDraw, "spawn");
242239
const blur_size = gl.getUniformLocation(progDraw, "blur_size");
243240
const far_grain = gl.getUniformLocation(progDraw, "far_grain");
244241
const close_grain = gl.getUniformLocation(progDraw, "close_grain");
@@ -250,6 +247,7 @@ export function drawGradients(
250247
const g2_coords = gl.getUniformLocation(progDraw, "g2_coords");
251248
const g3_clr = gl.getUniformLocation(progDraw, "g3_clr");
252249
const g3_coords = gl.getUniformLocation(progDraw, "g3_coords");
250+
const inPos = gl.getAttribLocation(progDraw, "aPosition");
253251
gl.useProgram(progDraw);
254252

255253
gl.enable(gl.DEPTH_TEST);
@@ -288,17 +286,16 @@ export function drawGradients(
288286
gl.DYNAMIC_DRAW,
289287
);
290288

291-
gl.enableVertexAttribArray(0);
292-
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
289+
gl.enableVertexAttribArray(inPos);
290+
gl.vertexAttribPointer(inPos, 2, gl.FLOAT, false, 0, 0);
293291

294292
// Set uniform variable values
295293
const chosen_clrs = shuffle(allColors).slice(0, 3);
296-
const g1 = { clr: chosen_clrs[0], coords: randCoors() };
297-
const g2 = { clr: chosen_clrs[1], coords: randCoors() };
298-
const g3 = { clr: chosen_clrs[2], coords: randCoors() };
294+
const g1 = { clr: chosen_clrs[0], coords: randCoords() };
295+
const g2 = { clr: chosen_clrs[1], coords: randCoords() };
296+
const g3 = { clr: chosen_clrs[2], coords: randCoords() };
299297

300298
gl.uniform1f(size_div, w / h); // to normalize coords in case canvas is rectangle
301-
gl.uniform2f(spawn, Math.random() * 1000, Math.random() * 1000); // random coordinate shift on simplex field
302299
gl.uniform1f(blur_size, 0.09); // read the name
303300
gl.uniform1f(far_grain, 0.3); // grain for inner parts of shapes
304301
gl.uniform1f(close_grain, 0.09); // grain for smoothing shapes between lines

0 commit comments

Comments
 (0)