Jump to content

CubeTextures in scene - how to optimise


Vousk-prod.
 Share

Recommended Posts

Hi everybuddy, a little question for you.

 

If I instanciate many CubeTextures with the same skybox maps

var 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 materials

mat_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;
Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

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;    };
Link to comment
Share on other sites

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?

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.

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

Loading...
 Share

  • Recently Browsing   0 members

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