Jump to content

Screen flash when adding VolumetricLightScatteringPostProcess (and CPU load)


Recommended Posts

I'm adding a VolumetricLightScatteringPostProcess on mouse click, and there is a noticeable screen flash when I do this. It is the screen going all black for one frame.


I am actually adding two of them (one each to two different meshes), and the flash is longer (at least twice as long). (So I tried adding some more, and it gets longer and longer - but the FPS is plummeting by this point, so harder to be objective.)


Previously I was actually adding them at app initialization, with decay set to 0, then just setting decay when they were needed. But I realized they still use CPU in that case, so I am now not creating the object until it is needed.


BTW, the CPU load is quite significant: I'm getting 45 to 55fps before, then with one VolumetricLightScatteringPostProcess added it drops to 30-35fps, and with two of them it drops to 18-22fps.  (i.e. 50 -> 33 -> 20)  (Not a problem as they only run for a few seconds; but it is a problem if they run all the time.)


So, my first question is if the screen flash is a bug that can be fixed, or just tough?


And, if tough, is there a way to pre-create the objects (so I can have the screen flash when it does not matter), but still not have them use any CPU until I am ready?

P.S. I guess I mean GPU, not CPU, as according to 'top' the load average does not change, nor do the CPU% shown by Firefox or Xorg. But when I add the effect the FPS goes down and the CPU core temperatures go up!! I'm developing on a nothing-special notebook, i7-4702MQ with integrated Intel HD Graphics 4600.




Link to comment
Share on other sites

Hi Q!  Hey, how does this demo look/act for you?   http://www.babylonjs-playground.com/#1BAPRM#18

Click on those mesh, if you please. The VLS rays should project from the bullet holes.


I had 20 VLS bullet hole beams clicked onto the mesh, and still at 59 fps.


But, all the VLS/godrays in the above demo... are instances of a "papa" godray-diator, which is located way out in the country.  (pan camera a bit... you'll see tiny dot flashes from papa godray). 


You might not be using instances, so your mileage may vary.


Is it possible for you to create a playground scene that shows the issue, Q?  thx.

Link to comment
Share on other sites

The difference is I don't create the godrays until the first click. I've hacked your demo, and I can see the flash on the first click:



I added a wireframe grid to make it easier to see, though it is literally just one frame. Also because the background gets lighter, it is hard to spot.

BTW, I get 35-50fps on your demo (http://www.babylonjs-playground.com/#1BAPRM#18) in Firefox. It does not change however bullet holes I shoot in the crate. But if I change so the godrays are not created then I get 60fps, and then it drops to the 35-50fps rate after the first click.  Conclusion: the god rays are what are taking the time.

Under Chromium I get 60fps either way. (My own code also has notably better FPS under Chromium...)  Conclusion: Chrome is quicker than Firefox for WebGL stuff!

Link to comment
Share on other sites

Hi qqdarren !

For your questions :


"So, my first question is if the screen flash is a bug that can be fixed, or just tough?"

I can't reproduce the bug and I can't see the bug in the demo provided in this topic :(


And, if tough, is there a way to pre-create the objects (so I can have the screen flash when it does not matter), but still not have them use any CPU until I am ready ?

The method should be to unattach the post-process from the camera. Then, it'll save performances.

The post-process is CPU and GPU computed. When the post-process is created, an internal pass is rendered every frame into a render target texture. Also, if the post-process is attached to a camera, the GPU will execute the post-process on every pixel, even if decay = 0.0;.

Link to comment
Share on other sites

Thanks for the idea. I tried passing camera as null, to set it later, but instantly get a JavaScript error This line:




I then tried creating the object, then setting camera to null:

godrays = new BABYLON.VolumetricLightScatteringPostProcess('godrays',1, camera, Q, 50, BABYLON.Texture.BILINEAR_SAMPLINGMODE, engine, true);godrays.camera = null;

But that seems to have no effect, as the objects are still glowing.


...a bit more searching, and I suspect you are telling me to use one of the functions described here? https://github.com/BabylonJS/Babylon.js/wiki/How-to-use-PostProcessRenderPipeline   However I don't explicitly have a PostProcessRenderPipelineManager: do I need to create one, or is one already existing behind the scenes?

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...