Skip to content

Commit 73ced71

Browse files
committed
little performance optimization
1 parent f18712b commit 73ced71

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const gui = new dat.GUI({ name: 'Points GUI' });
1414
const folderOptions = gui.addFolder('options');
1515
const folderControls = gui.addFolder('controls');
1616
const folderSongs = gui.addFolder('songs');
17+
const MAXCHARS = 30;
1718

1819
let audio = null;
1920
let loop = false;
@@ -54,6 +55,7 @@ function playSong(song) {
5455

5556
audio && audio.pause() && (audio = null);
5657
audio = points.setAudio('audio', audioUrl, options.volume, false, false);
58+
points.setUniform('numChars', title.length < MAXCHARS ? title.length : MAXCHARS);
5759
points.setStorageMap('chars', strToCodes(title));
5860
let artworkLoaded = 0;
5961
song?.artworkColors && points.setStorageMap('artworkColors', song?.artworkColors.flat());
@@ -158,6 +160,7 @@ async function onCompleteTags(result) {
158160
}
159161

160162
folderSongs.add(song, 'fn').name(song.name);
163+
points.setUniform('numChars', title.length < MAXCHARS ? title.length : MAXCHARS);
161164
points.setStorageMap('chars', strToCodes(title));
162165
}
163166

@@ -321,13 +324,14 @@ points.setSampler('textImageSampler', {
321324
});
322325
points.setTexture2d('feedbackTexture', true);
323326

324-
audio = points.setAudio('audio', '', options.volume, loop, false);
327+
audio = points.setAudio('audio', '', options.volume, loop, false); // TODO returl null if empty or null is passed
325328

326329
points.setUniform('showMessage', 1);
327330
points.setUniform('rand', 0);
328331
points.setUniform('progress', 0);
329332
points.setUniform('artworkLoaded', 0);
330333
// points.setUniform('somecolor', colors.color2, 'vec3f');
334+
points.setUniform('numChars', 12);
331335
points.setStorageMap('chars', strToCodes('Gravity Pull'), 'array<f32>')// TODO: setStorageMap doesn't work with u32 wrong sized
332336
points.setStorageMap('message', strToCodes('Select a song to Play'), 'array<f32>')// TODO: setStorageMap doesn't work with u32 wrong sized
333337
points.setStorageMap('artworkColors', Array(16).fill(1), 'array<vec4f>');

src/renderpasses/renderpass0/frag.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ const MATRIX4 = vec4f(.572,.717,.549, 1);
129129
130130
const TAU = PI * 2; // TODO: fix on main library
131131
const TAUQUARTER = TAU * .25;
132-
const NUMCHARS = 30;
133132
const MAXBYTES = 256;
134133
const CHLEN = 0.125;
135134
const DINTENSITY = .0041;//0.0151;
@@ -240,7 +239,8 @@ fn main(
240239
let textScale = 2.476 * ratio.y + c0;
241240
let textUVR = uvr / textScale;
242241
let spaceRatio = .0017 * ratio.x;
243-
for (var index = 0; index < NUMCHARS; index++) {
242+
243+
for (var index = 0; index < i32(params.numChars); index++) {
244244
let indexF32 = f32(index);
245245
let charIndex = u32(chars[index]);
246246
let charPosition = charSizeF32 * vec2(indexF32, 0);

0 commit comments

Comments
 (0)