ian Posted March 16, 2018 Share Posted March 16, 2018 function getDeltaTime() { return scene.getLastFrameDuration() / 1000; } How can I get same function with EngineInstrumentation? I am playing around instrumentation. Can any body help me getDeltaTime? getLastFrameDuration is not working anymore. Which counter can get me solve getDeltaTime like code above? Any help hint? http://doc.babylonjs.com/how_to/optimizing_your_scene#instrumentation function instrumentFun() { //console.log(instrumentation.gpuFrameTimeCounter.current); //console.log(instrumentation.gpuFrameTimeCounter.average); //console.log(instrumentation.gpuFrameTimeCounter.average); console.log( "current frame time (GPU): " + (instrumentation.gpuFrameTimeCounter.current * 0.000001).toFixed(2) + "ms" ); console.log( "average frame time (GPU): " + (instrumentation.gpuFrameTimeCounter.average * 0.000001).toFixed(2) + "ms" ); console.log( "total shader compilation time: " + (instrumentation.shaderCompilationTimeCounter.total).toFixed(2) + "ms" ); console.log( "average shader compilation time: " + (instrumentation.shaderCompilationTimeCounter.average).toFixed(2) + "ms" ); console.log( "compiler shaders count: " + instrumentation.shaderCompilationTimeCounter.count ); } I am useing chrome (with debian) And I get "current frame time (GPU)" and "average frame time (GPU)" 0. I always get current frame time (GPU): 0.00ms average frame time (GPU): 0.00ms Should I get also CPU time anyhow? Should I get also CPU frame time? Can anybody help me code getDeltaTime function with instrumentations counters? I test chrome with http://webglreport.com/ and I get WebGL 1 Platform: Linux x86_64 Browser User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36 Context Name: webgl GL Version: WebGL 1.0 (OpenGL ES 2.0 Chromium) Shading Language Version: WebGL GLSL ES 1.0 (OpenGL ES GLSL ES 1.0 Chromium) Vendor: WebKit Renderer: WebKit WebGL Unmasked Vendor: Intel Open Source Technology Center Unmasked Renderer: Mesa DRI Intel(R) Sandybridge Desktop Antialiasing: Available ANGLE: No Major Performance Caveat: No Vertex Shader Max Vertex Attributes: 16 Max Vertex Uniform Vectors: 4096 Max Vertex Texture Image Units: 16 Max Varying Vectors: 32 Best float precision: [-2127, 2127] (23) Transform Feedback Coming in WebGL 2 Rasterizer Aliased Line Width Range: [1, 7.375] Aliased Point Size Range: [1, 255] Fragment Shader Max Fragment Uniform Vectors: 4096 Max Texture Image Units: 16 float/int precision: highp/highp Best float precision: [-2127, 2127] (23) Framebuffer Max Color Buffers: 8 RGBA Bits: [8, 8, 8, 8] Depth / Stencil Bits: [24, 8] Max Render Buffer Size: 8192 Max Viewport Dimensions: [8192, 8192] Textures Max Texture Size: 8192 Max Cube Map Texture Size: 8192 Max Combined Texture Image Units: 48 Max Anisotropy: 16 Uniform Buffers Coming in WebGL 2 Supported Extensions: Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted March 16, 2018 Share Posted March 16, 2018 Hi @ian I don't think you should use instrumentation at runTime in a production environment, if all you need is deltaTime, too much unneeded measuring etc going on. This will calculate the deltaTime from the start of last render and to the start of current/this render, var deltaTime = null; var lastUpdate = null; function updateDelta(){ // Get timestamp in MS. var now = +new Date(); if(!lastUpdate){ lastUpdate = now; } // Update deltaTime variable. deltaTime = now - lastUpdate; // Update lastUpdate to being now. lastUpdate = now; // return it incase the function is used as a "variable". return deltaTime; } // Using it.. scene.registerBeforeRender(function(){ // as Variable, after calling the function. updateDelta(); console.log(deltaTime); myUiText.text = deltaTime.toString(); // as Function directly, if you only use it once. myUiText.text = updateDelta().toString(); }); https://www.babylonjs-playground.com/#XCPP9Y#452 ian 1 Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted March 16, 2018 Share Posted March 16, 2018 Hi again @ian I just notised that engine.getDeltaTime() appears to work flawlessly in the latest versions (including stable), I wrote the above code a few versions ago where it(engine.getDeltaTime()) was giving me some issues. and i also needed the full timestamp. But it seems you can just use that instead Quote Link to comment Share on other sites More sharing options...
ian Posted March 16, 2018 Author Share Posted March 16, 2018 thank you aWerdo your previous answare works also fine. I'll try tomorrow with engine.getDeltaTime on the latest babylon.js engine. I don't know if babylon did fix this problem, so we will not nedd deltatime anymore. The problem is if same things is running on PS (faster gpu) or phone/tablet (slowest gpu) ??? I don't know if rendering and physics works with same speed regardless of hardware (cpu,gpu) speed ??? @Deltakosh Is there any playground example to test/see this? greetings Quote Link to comment Share on other sites More sharing options...
Guest Posted March 16, 2018 Share Posted March 16, 2018 We have several demo of physics. Just look in the PG search for "enablePhysics": http://doc.babylonjs.com/playground?code=enablePhysics Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.