@@ -45,7 +45,8 @@ const properties = Properties({
4545
4646// Buffers
4747
48- const propertiesUniform = root . createUniform ( Properties , properties ) ;
48+ const propertiesUniform = root . createUniform ( Properties ) ;
49+ queuePropertiesBufferUpdate ( ) ;
4950
5051// these buffers are recreated with a different size on interpolationPoints change
5152function createLineVerticesBuffers ( ) {
@@ -101,7 +102,7 @@ const backgroundVertex = tgpu.vertexFn({
101102 const properties = propertiesUniform . $ ;
102103 const leftBot = properties . transformation . mul ( d . vec4f ( - 1 , - 1 , 0 , 1 ) ) ;
103104 const rightTop = properties . transformation . mul ( d . vec4f ( 1 , 1 , 0 , 1 ) ) ;
104- const canvasRatio = ( rightTop . x - leftBot . x ) / ( rightTop . y - leftBot . y ) ;
105+ const aspectRatio = ( rightTop . x - leftBot . x ) / ( rightTop . y - leftBot . y ) ;
105106
106107 const transformedPoints = [
107108 d . vec2f ( leftBot . x , 0 ) ,
@@ -111,12 +112,12 @@ const backgroundVertex = tgpu.vertexFn({
111112 ] ;
112113
113114 const currentPoint = properties . inverseTransformation . mul (
114- d . vec4f ( transformedPoints [ 2 * iid + vid / 2 ] . xy , 0 , 1 ) ,
115+ d . vec4f ( transformedPoints [ 2 * iid + d . u32 ( vid / 2 ) ] . xy , 0 , 1 ) ,
115116 ) ;
116117
117118 return {
118119 pos : d . vec4f (
119- currentPoint . x + ( d . f32 ( iid ) * std . select ( d . f32 ( - 1 ) , 1 , vid % 2 === 0 ) * 0.005 ) / canvasRatio ,
120+ currentPoint . x + ( d . f32 ( iid ) * std . select ( d . f32 ( - 1 ) , 1 , vid % 2 === 0 ) * 0.005 ) / aspectRatio ,
120121 currentPoint . y + d . f32 ( 1 - iid ) * std . select ( d . f32 ( - 1 ) , 1 , vid % 2 === 0 ) * 0.005 ,
121122 currentPoint . zw ,
122123 ) ,
@@ -294,6 +295,12 @@ async function tryRecreateComputePipeline(
294295}
295296
296297function queuePropertiesBufferUpdate ( ) {
298+ const leftBot = properties . transformation . mul ( d . vec4f ( - 1 , - 1 , 0 , 1 ) ) ;
299+ const rightTop = properties . transformation . mul ( d . vec4f ( 1 , 1 , 0 , 1 ) ) ;
300+ const currentCanvasRatio = ( rightTop . x - leftBot . x ) / ( rightTop . y - leftBot . y ) ;
301+ const desiredCanvasRatio = canvas . clientWidth / canvas . clientHeight ;
302+ const rescaleMatrix = mat4 . scaling ( [ desiredCanvasRatio / currentCanvasRatio , 1 , 1 ] , d . mat4x4f ( ) ) ;
303+ properties . transformation = std . mul ( properties . transformation , rescaleMatrix ) ;
297304 properties . inverseTransformation = mat4 . inverse ( properties . transformation , d . mat4x4f ( ) ) ;
298305 propertiesUniform . write ( properties ) ;
299306}
@@ -379,12 +386,7 @@ window.addEventListener('touchend', touchEndEventListener);
379386// Resize observer and cleanup
380387
381388const resizeObserver = new ResizeObserver ( ( ) => {
382- const leftBot = properties . transformation . mul ( d . vec4f ( - 1 , - 1 , 0 , 1 ) ) ;
383- const rightTop = properties . transformation . mul ( d . vec4f ( 1 , 1 , 0 , 1 ) ) ;
384- const currentCanvasRatio = ( rightTop . x - leftBot . x ) / ( rightTop . y - leftBot . y ) ;
385- const desiredCanvasRatio = canvas . clientWidth / canvas . clientHeight ;
386- const rescaleMatrix = mat4 . scaling ( [ desiredCanvasRatio / currentCanvasRatio , 1 , 1 ] , d . mat4x4f ( ) ) ;
387- properties . transformation = std . mul ( properties . transformation , rescaleMatrix ) ;
389+ queuePropertiesBufferUpdate ( ) ;
388390
389391 msTexture . destroy ( ) ;
390392 msTexture = device . createTexture ( {
0 commit comments