jdurrant Posted March 26, 2015 Share Posted March 26, 2015 I've been playing with BABYLON.SceneOptimizer. It's great to be able to reduce the render quality in response to low FPS. I'd also like to be able to UPGRADE the quality if the FPS recovers. For example, if I start running another application in the background that's keeping my computer busy, the render quality should decrease to compensate for the lower FPS. But once I close the background application and the FPS increases, I'd like to restore the old quality. Some of the built-in optimization functions could be easily adapted to upgrade quality, but, if I'm reading the js code correctly, BABYLON.TextureOptimization permanently decreases the texture resolution. Is that right? In general, is there any way to use the existing BABYLON.SceneOptimizer to also upgrade quality when appropriate? I've done some preliminary experiments, thinking I could store the original textures in an array for later restoring, but I can't even resize existing textures without going through BABYLON.TextureOptmization. Here's some example code: http://www.babylonjs-playground.com/#KYPUJ Can anyone tell me why the texture is not being resized in the sample code? Thanks for all your help! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 26, 2015 Share Posted March 26, 2015 Hello, this is because there is no .scale() function on texture Quote Link to comment Share on other sites More sharing options...
jdurrant Posted March 27, 2015 Author Share Posted March 27, 2015 Well, that would definitely explain why it doesn't work! I assumed this function exists because of this code from BABYLON.TextureOptimization (babylon.sceneOptimizer.js): var TextureOptimization = (function (_super) { __extends(TextureOptimization, _super); function TextureOptimization(priority, maximumSize) { var _this = this; if (priority === void 0) { priority = 0; } if (maximumSize === void 0) { maximumSize = 1024; } _super.call(this, priority); this.priority = priority; this.maximumSize = maximumSize; this.apply = function (scene) { var allDone = true; for (var index = 0; index < scene.textures.length; index++) { var texture = scene.textures[index]; if (!texture.canRescale) { continue; } var currentSize = texture.getSize(); var maxDimension = Math.max(currentSize.width, currentSize.height); if (maxDimension > _this.maximumSize) { texture.scale(0.5); allDone = false; } } return allDone; }; } return TextureOptimization; })(SceneOptimization);The "texture" variable, taken from scene.textures, isn't the same kind of texture used in materials, then? Thanks, Jacob Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 27, 2015 Share Posted March 27, 2015 OMG! You're right...I'm totally stupid. Yes there is a scale()function on textures I just forgot about it (...) But scaling up won't give you great result as we already scale the texture down and then we already lost texture data Quote Link to comment Share on other sites More sharing options...
jdurrant Posted March 28, 2015 Author Share Posted March 28, 2015 No worries Deltakosh! I know how hard it can be to keep track of so many functions, especially as a library gets more and more complex. My plan isn't to scale up the image resolution. My plan is to store all the original textures in an array and then scale down from there (always from the originals) depending on the current FPS. But I can't get resized textures to appear on their respective meshes. I think it's likely I'm overlooking something obvious. This link illustrates my current (flawed) approach to resizing textures: http://www.babylonjs-playground.com/#KYPUJ As you can see in the example, the texture on the sphere doesn't change when I resize. Thanks! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 30, 2015 Share Posted March 30, 2015 OOOKKK I know why I know that they were something special with scale Scale is only implemented by renderTargetTexture. Scale has no effect on regular textures Quote Link to comment Share on other sites More sharing options...
jdurrant Posted April 28, 2017 Author Share Posted April 28, 2017 Seems silly to be following up two years after this question was originally posted, but I once again need to resize textures in babylonjs. If scale() does not apply to standard textures, then how is BABYLON.TextureOptimization able to scale all the textures in the scene? I'd now like to be able to create a function that resizes all the textures on the fly, independent of scene optimization. Something like resizeAllTextures(scene, maxWidth). Is it possible? This doesn't work: for (var index = 0; index < scene.textures.length; index++) { var texture = scene.textures[index]; var currentSize = texture.getSize(); var maxDimension = Math.max(currentSize.width, currentSize.height); var scale = 128.0 / maxDimension; if (scale < 1.0) { texture.scale(scale); } } Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 28, 2017 Share Posted April 28, 2017 Hello this should work. Do you mind creating a PG to repro the issue? Quote Link to comment Share on other sites More sharing options...
jdurrant Posted April 28, 2017 Author Share Posted April 28, 2017 Thanks for your help. Here's the PG: https://www.babylonjs-playground.com/#H52JTC Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 30, 2017 Share Posted April 30, 2017 Thanks! I'll check https://github.com/BabylonJS/Babylon.js/issues/2078 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 30, 2017 Share Posted April 30, 2017 Ok actually I should have read my own previous response Scale is not supported by regular textures. Only renderTargetTextures can be scaled Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 30, 2017 Share Posted April 30, 2017 But actually there is a way to control the max size of your textures: https://www.babylonjs-playground.com/#H52JTC#5 See line #81 Quote Link to comment Share on other sites More sharing options...
jdurrant Posted April 30, 2017 Author Share Posted April 30, 2017 Very handy function! But it seems it has to be called early in the load process. See https://www.babylonjs-playground.com/#H52JTC#7 In that example, the first resize works great, but when I try to resize the textures again later (on click), it doesn't work. I show a settings page when the user starts my app. The scene begins to load immediately in the background. One of the options on the settings page is to use low-res textures. But by the time the user presses "Start" on that page, the load process in the background has progressed to the point that the texture resize doesn't work. Does that make sense? Hopefully the PG example shows what I mean... Thanks! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 1, 2017 Share Posted May 1, 2017 Yes it makes sense If you have an option to resize your textures after having already loading them, you will be forced to dispose all of them first (to remove them from cache) 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.