Vousk-prod. Posted March 13, 2014 Share Posted March 13, 2014 Hi everybuddy, a little question for you. If I instanciate many CubeTextures with the same skybox mapsvar cubemap_showroom1 = new BABYLON.CubeTexture("media/assets/cubemaps/showroom/showroom", scene);var cubemap_showroom2 = new BABYLON.CubeTexture("media/assets/cubemaps/showroom/showroom", scene);because I want different reflexion levels for different materialsmat_verre.reflectionTexture = cubemap_showroom1;mat_verre.reflectionTexture.level = 1;mat_metal.reflectionTexture = cubemap_showroom2;mat_verre.reflectionTexture.level = 0.2;Are the textures loaded several times or only once ? If they're loaded many times, is there an optimised way to do that ?Of course the following doesn't work (operator = assigns object by reference) :var cubemap_showroom = new BABYLON.CubeTexture("media/assets/cubemaps/showroom/showroom", scene);mat_verre.reflectionTexture = cubemap_showroom;mat_verre.reflectionTexture.level = 1;mat_metal.reflectionTexture = cubemap_showroom;mat_verre.reflectionTexture.level = 0.2; Quote Link to comment Share on other sites More sharing options...
gwenael Posted March 13, 2014 Share Posted March 13, 2014 Since you have to instantiate many CubeTextures you get several instances in javascript but internally some properties may be shared. It is what it's done when you clone a mesh for example: buffers are shared. I don't know about textures in BabylonJS though and a quick reading of code doesn't drive me to the conclusion that some properties are shared. There is also a clone method for textures, it seems to return a new texture with the same values of the source texture but without sharing references. Not sure, it helped... Sorry. Nevertheless maybe some other guys will jump on my remarks Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 13, 2014 Share Posted March 13, 2014 All textures are shared. If a specific filename is used for more than one texture, they all share the same data Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted March 13, 2014 Author Share Posted March 13, 2014 So great !! You're a boss Deltakosh Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 14, 2014 Share Posted March 14, 2014 Quote Link to comment Share on other sites More sharing options...
gwenael Posted March 15, 2014 Share Posted March 15, 2014 Is it the following line that I missed?this._texture = this._getFromCache(rootUrl);According to this function (_getFromCache), _texture is shared only if noMipmap is false or undefined for the cached entry. Is it always the case? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 16, 2014 Share Posted March 16, 2014 Not exactly. Textures are cached based on the required state (url and mipmap):BABYLON.BaseTexture.prototype._getFromCache = function (url, noMipmap) { var texturesCache = this._scene.getEngine().getLoadedTexturesCache(); for (var index = 0; index < texturesCache.length; index++) { var texturesCacheEntry = texturesCache[index]; if (texturesCacheEntry.url === url && texturesCacheEntry.noMipmap === noMipmap) { texturesCacheEntry.references++; return texturesCacheEntry; } } return null; }; Quote Link to comment Share on other sites More sharing options...
gwenael Posted March 16, 2014 Share Posted March 16, 2014 Obviously it's based on url too. I was only concerned by noMipmap so I didn't mention url but you're right to mention it since I was not clear in my post and that could be confusing. Thanks.In the constructor of CubeTexture, _getFromCache is called with noMipmap which is undefined, so the texturesCacheEntry is returned only if its noMipmap is undefined too (and it has the same url). If its noMipmap has been changed from undefined to false for example then the required state is different and data are not shared. Could this case happen? If the texturesCacheEntry doesn't exist, a new texture is created in CubeTexture constructor by calling createCubeTexture on the engine which doesn't set noMipmap so we are fine while creating a new one but could noMipmap change later on? I guess not. Nevertheless, we should remember that data are shared based on the required state (url and mipmap) and not only based on texture. A same picture (same url) could be used for a CubeTexture (noMipmap is undefined) and for a another texture without mipmaps (noMipmap is true) then data wouldn't be shared, would it? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 17, 2014 Share Posted March 17, 2014 Right Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 17, 2014 Share Posted March 17, 2014 I will add a noMipmap property for createCubeTexture 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.