Kesshi Posted February 15, 2017 Share Posted February 15, 2017 Currently i'm trying to reduce the gpu memory usage of our app (especially for mobile devices). I just saw that BabylonJS internally uploads every texture as gl.RGBA to the gpu even if if the source was a jpg or any other image without alpha channel.https://github.com/BabylonJS/Babylon.js/blob/master/src/babylon.engine.ts#L2189 Using gl.RGB in those cases would save 25% of texture memory. I also have some grayscale textures. It would be nice if i could use gl.LUMINANCE to save even more memory. It should be possible to define the desired texture format in my opinion. Would it make sense to add this as another parameter to the Texture constructor? It has a lot of parameters already ... i don't know if there is a better option without a breaking change. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted February 15, 2017 Share Posted February 15, 2017 KTX, or multi-platform compressed textures that I added for 2.6 are much small in GPU. Your finding makes my comparisons to regular textures even worse than I thought. If you make this change, you are going to have to modify a lot more if you make it a parameter. Maybe, just determine the extension cannot possibly have alpha, and adjust internally. Otherwise, you are probably going to need to go all the way out to the exporters, since few people actually write Texture constructor code. Also, when making this change, remember to do it to createCubeTexture() too. Quote Link to comment Share on other sites More sharing options...
Kesshi Posted February 16, 2017 Author Share Posted February 16, 2017 Compressed textures are good but they are not an option for me in this case (because of our software architecture) but i will keep it in mind for other projects. I think automatic detection of the format is not a good idea. You would always have to use RGBA for png files even if the png doesn't have an alpha channel. You would also lose the option to force a conversion. For example: - you have a png with alpha channel but you don't need it -> use RGB instead of RGBA - you have a fullcolor image but you want to show it as grayscale -> use LUMINANCE, the browser will convert the image for you A parameter would be better i think. I will have a look and see if can make a PR for this (for the engine only, not for the exportes) Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted February 16, 2017 Share Posted February 16, 2017 See your PR. While I do not merge stuff on this repo, one extra line might be good for the general public. If no format arg is supplied, then test for a '.JPG' extension. If JPG, then do RGB. That way you get the benefit without changing all the way back to Blender / 3DS Max, nor complicate things. BitOfGold 1 Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted March 7, 2017 Share Posted March 7, 2017 Hey JCP, what exactly are all the values we can pass to format parameter? Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted March 7, 2017 Share Posted March 7, 2017 See internalformat parameter here. I have to get in there soon, (before 3.0 comes out). I added a compressed image type ATC, but could not find any ktx format converter. I've seen Google is trying to officially remove ATC from WebGL, so I might as well rip it out before KTX gets into a production release. Will probably add the JPG override described above, If I am not too late. 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.