www.xbdev.net
xbdev - software development
Thursday June 4, 2026
Home | Contact | Support | WebGPU Graphics and Compute ... | WebGPU.. Games, Tutorials, Demos, Projects, and Code.....
     
 

WebGPU..

Games, Tutorials, Demos, Projects, and Code.....

 


Time Based Movement


Instead of just hardcoding an arbirary value for movement each frame - you calculate how much time has elapsed since the last call. This means, as the frame rate increases and decreases the movements don't become jittery and unnatural - they remain consistent and smooooooth.


Functions Used: peformance.now(), setVertexBuffer(), setIndexBuffer(), drawIndexed(), createBuffer(), getMappedRange(), getContext(), requestAdapter(), getPreferredCanvasFormat(), createCommandEncoder(), beginRenderPass(), setPipeline(), draw(), end(), submit(), getCurrentTexture(), createView(), createShaderModule()

We can use the
peformance.now()
function to get timing information and calculation
dt
(time in milliseconds since the last frame update).

<?php
let lastTime    = performance.now();


function frame() 
{
  var dt        = startTime - lastTime;
  lastTime      = performance.now();
  
  
  ....
  
}



The current version of requestAnimationFrame automatically feeds a timestamp to the animation function. You can use that timestamp to calculate how much time has elapsed since you were last in the animation loop.


<?php
let start, previousTimeStamp;

function step(timeStamp) 
{
  if (start === undefined) {  start = timeStamp;  }
  
  const totalElapsed = timeStamp - start;

  if (previousTimeStamp !== timeStamp) 
  {
    // Math.min() is used here to make sure the element stops at exactly 200px
    const count = Math.min(0.1 * elapsed, 200);
    
    if (count === 200) // exist loop when finished
      break;
  }
  
}

requestAnimationFrame(step);


































WebGPU by Example: Fractals, Image Effects, Ray-Tracing, Procedural Geometry, 2D/3D, Particles, Simulations WebGPU Compute graphics and animations using the webgpu api 12 week course kenwright learn webgpu api kenwright programming compute and graphics applications with html5 and webgpu api kenwright real-time 3d graphics with webgpu kenwright webgpu api develompent a quick start guide kenwright webgpu by example 2022 kenwright webgpu gems kenwright webgpu interactive compute and graphics visualization cookbook kenwright wgsl webgpu shading language cookbook kenwright wgsl webgpugems shading language cookbook kenwright



 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2026 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.