Jump to content

How to update a PostProcess aspect ratio? (when the window is resized)


Recommended Posts

Resizing the window when there is no post process means the views aspect ratio gets updated when the engine.resize() function is used.

However resizing the window while a postprocess is enabled means the view gets stretched even while the engine.resize() function is running.

The "engine.resize()" function still updates the resolution if there is a post process, since there are no stretched or blurry pixels, it's just the aspect ratio that doesn't change.

Everything works if the window is resized and then the page is refreshed but it would be nice for it to update without a refresh



(using the "pass" postProcess)


Is there a way to update the postprocess ratio when the window is resized?


PostProcess code:

postProcess0 = new BABYLON.PassPostProcess("Scene copy", 1.0, camera);
Link to comment
Share on other sites

Got it working

To get it working I made this function, which loops through all of the post process textures (there's probably a better way to do this) and then sets their width and height based on the canvas width and height

function refreshTextureRatios() {    var loadedTextures = engine.getLoadedTexturesCache();    console.log(loadedTextures);     for (var index = 0; index < loadedTextures.length ; index++) {        if (loadedTextures[index].__smartArrayFlags != null) {            loadedTextures[index]._width = canvas.width;            loadedTextures[index]._height = canvas.height;        }    }} 

To apply it to just a single postProcess you can do this:

function refreshTextureRatio(postProcessName) {    postProcessName._textures.data[0]._width = canvas.width;    postProcessName._textures.data[0]._height = canvas.height;}

And then I ran the function inside the resize event after the engine.resize() function

window.addEventListener("resize", function () {    engine.resize();    refreshTextureRatios();}

and now all of the post process's aren't stretched

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...