Skip to content

Commit 613e6cb

Browse files
authored
Merge pull request #15 from Absulit/dev
small issues fixed
2 parents 0f9da72 + 73ced71 commit 613e6cb

2 files changed

Lines changed: 21 additions & 18 deletions

File tree

src/main.js

Lines changed: 7 additions & 4 deletions
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', './../80s-pulse-synthwave-dude-212407.mp3', 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>');
@@ -345,8 +349,6 @@ if (await points.init(renderPasses)) {
345349
el.classList.toggle('show');
346350
}
347351

348-
349-
350352
points.canvas.addEventListener('click', _ => {
351353
if (pauseClickTimeout) {
352354
return;
@@ -356,7 +358,8 @@ points.canvas.addEventListener('click', _ => {
356358
pauseClickTimeout = null;
357359
}, 300);
358360
});
359-
document.addEventListener('dblclick', _ => {
361+
362+
points.canvas.addEventListener('dblclick', _ => {
360363
clearTimeout(pauseClickTimeout);
361364
pauseClickTimeout = null;
362365
points.fullscreen = !points.fullscreen;

src/renderpasses/renderpass0/frag.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ 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;
133-
const MAXBITS = 256;
132+
const MAXBYTES = 256;
134133
const CHLEN = 0.125;
135134
const DINTENSITY = .0041;//0.0151;
136135
const B = vec3(); // black
@@ -159,19 +158,19 @@ fn main(
159158
160159
// params.audioLength 1024
161160
162-
let audioX = audio.data[ u32(uv.x * audioLength)] / MAXBITS;
163-
let audioX2 = audio.data[ u32(audioLength - uv.x * audioLength)] / MAXBITS;
164-
let audio1 = audio.data[ u32(.9 * audioLength)] / MAXBITS;
161+
let audioX = audio.data[ u32(uv.x * audioLength)] / MAXBYTES;
162+
let audioX2 = audio.data[ u32(audioLength - uv.x * audioLength)] / MAXBYTES;
163+
let audio1 = audio.data[ u32(.9 * audioLength)] / MAXBYTES;
165164
166165
// CHANNELS
167-
let c0 = audio.data[ 0 ] / MAXBITS;
168-
let c1 = audio.data[ u32(CHLEN * 1 * audioLength)] / MAXBITS;
169-
let c2 = audio.data[ u32(CHLEN * 2 * audioLength)] / MAXBITS;
170-
let c3 = audio.data[ u32(CHLEN * 3 * audioLength)] / MAXBITS;
171-
let c4 = audio.data[ u32(CHLEN * 4 * audioLength)] / MAXBITS;
172-
let c5 = audio.data[ u32(CHLEN * 5 * audioLength)] / MAXBITS;
173-
let c6 = audio.data[ u32(CHLEN * 6 * audioLength)] / MAXBITS;
174-
let c7 = audio.data[ u32(CHLEN * 7 * audioLength)] / MAXBITS;
166+
let c0 = audio.data[ 0 ] / MAXBYTES;
167+
let c1 = audio.data[ u32(CHLEN * 1 * audioLength)] / MAXBYTES;
168+
let c2 = audio.data[ u32(CHLEN * 2 * audioLength)] / MAXBYTES;
169+
let c3 = audio.data[ u32(CHLEN * 3 * audioLength)] / MAXBYTES;
170+
let c4 = audio.data[ u32(CHLEN * 4 * audioLength)] / MAXBYTES;
171+
let c5 = audio.data[ u32(CHLEN * 5 * audioLength)] / MAXBYTES;
172+
let c6 = audio.data[ u32(CHLEN * 6 * audioLength)] / MAXBYTES;
173+
let c7 = audio.data[ u32(CHLEN * 7 * audioLength)] / MAXBYTES;
175174
176175
177176
let s = sdfCircle(center, maxCircleRadius * c4, .1 * audioX, uvr);
@@ -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)