Skip to content

Commit 53819d6

Browse files
committed
fix: starting message centered
1 parent c866eb6 commit 53819d6

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

  • src/renderpasses/renderpass0

src/renderpasses/renderpass0/frag.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { fnusin, fusin } from 'points/animation';
22
import { GREEN, layer, RED, RGBAFromHSV, WHITE } from 'points/color';
3-
import { sprite, texturePosition } from 'points/image';
3+
import { sprite, texture, texturePosition } from 'points/image';
44
import { PHI, PI, rotateVector, TAU } from 'points/math';
55
import { sdfCircle, sdfLine2, sdfSquare, sdfSegment } from 'points/sdf';
66
import { structs } from './structs.js';
@@ -11,6 +11,7 @@ ${structs}
1111
${fnusin}
1212
${sdfSegment}
1313
${sdfLine2}
14+
${texture}
1415
${texturePosition}
1516
${sdfCircle}
1617
${sdfSquare}
@@ -227,19 +228,25 @@ fn main(
227228
let charSizeF32 = vec2(f32(charSize.x) / params.screen.x, f32(charSize.y) / params.screen.y);
228229
229230
231+
// let textScale = 2.476 + c0;
230232
let textScale = 2.476 + c0;
231-
let textUVR = uvr / textScale / ratioWidth;
232-
let stringMask = texturePosition(songName, textImageSampler, fontPosition, textUVR, false).r;
233-
let stringMask2 = texturePosition(songName, textImageSampler, fontPosition, textUVR + .001 / ratioWidth, false).r;
233+
let textUVR = (uvr / textScale / ratioWidth) - fontPosition;
234+
let stringMask = texture(songName, textImageSampler, textUVR, false).r;
235+
let stringMask2 = texture(songName, textImageSampler, textUVR + .001 / ratioWidth, false).r;
236+
237+
//
238+
var debug = sdfLine2(fontPosition, fontPosition + vec2f(0,.1) * ratio, .005, uvr) * RED;
239+
//
234240
235241
var messageStringMask = 0.;
236242
if(params.showMessage == 1.){
237243
let messageScale = mix(textScale, ratioWidth, isPortrait);
238-
let dims:vec2u = textureDimensions(messageString, 0);
239-
let dimsF32 = vec2f(dims) * messageScale;
240-
let dimWidth = dimsF32.x / params.screen.x * messageScale;
244+
let dims = vec2f(textureDimensions(messageString, 0)) * messageScale;
245+
246+
let imageWidth = dims / params.screen * ratio; // if you are using uvr you have to multiply by ratio
247+
let halfImageWidth = imageWidth * .5;
241248
242-
var messageUVR = ( (uvr - center) + vec2f(dimWidth * .5, 0));
249+
var messageUVR = (uvr) - (center - halfImageWidth);
243250
messageUVR = vec2f(messageUVR.x, messageUVR.y + sin(params.time + messageUVR.x * 10 ) * .01) / messageScale;
244251
messageStringMask = texturePosition(messageString, textImageSampler, vec2f(), messageUVR, false).r;
245252
}

0 commit comments

Comments
 (0)