paleRider Posted October 24, 2017 Share Posted October 24, 2017 Hi everybody. Here I come again with a new question for this incredible community. By the way, I think it will be "super easy" for someone which a good knowledge of the BJS internals. The case is that, following with my current development (tap simulator) I'm now focused on the performance. My doubts are mainly about the proper use of the method "clone" of the "Texture" object. Doubt 1) Suppose you have a Standard Material, you create it following the usual way, something like this: matFoo=new BABYLON.StandardMaterial("Foo_Material",myScene); matFoo.diffuseColor=new BABYLON.Color3(0,0,0); matFoo.opacityTexture=textFoo; matFoo.emissiveTexture=textFoo; Note that we are using the texture (textFoo) on two channels, opacity and emissive. Is this effective in terms of resource economy or I must follow this other approach?: matFoo=new BABYLON.StandardMaterial("Foo_Material",myScene); matFoo.diffuseColor=new BABYLON.Color3(0,0,0); matFoo.opacityTexture=textFoo.clone; matFoo.emissiveTexture=textFoo.clone; Doubt 2) Now we have a similar scenario, when we must assign a previously created texture, but this time we want to assign it to a series of Particles: ... textSprite=new BABYLON.Texture("assets/textures/flarealpha.png",myScene); ... myParticles=new BABYLON.ParticleSystem("Particles",10000,myScene); myParticles.emitter=new BABYLON.Vector3(0,0,0); myParticles.particleTexture=textSprite; ... This time, as we have a lot of particles chances are that it is better to use textSprite.clone() in order to assign the sprite image to each particle, at last line of shown code. Isn´t it? Doubt 3) Last but not least. When you (as me) arrives at the conclusion that PBR materials are the way-to-go (in order to achieve a decent look with your CGs), you are going to use, among others, the environment channel (dds files in current 3.0 version of BJS). Here I have certainly a doubt and a thought. Going first with the last, I think the environment should not be a PBR Material property (as currently is), but a scene one, as certainly is very weird to think in a scene with more than one environment (?). Anyway, as at the moment this is not the case, and we have to assign the same value of "environment" for each PBR Material, we find ourselves setting time after time the same texture (dds file) in this way (please focus only on the reflectionTexture property): ... matTube=new BABYLON.PBRMaterial("MaterialPBR_Tube",myScene); matTube.albedoTexture=new BABYLON.Texture("assets/models/Tubo_BaseColor.png",myScene); matTube.metallicTexture=new BABYLON.Texture("assets/models/Tubo_Metalico_PBR.png",myScene); matTube.bumpTexture=new BABYLON.Texture("assets/models/Tubo_Normal.png",myScene); matTube.reflectionTexture=textEnvironment; matTube.microSurface=0.96; matTube.useRoughnessFromMetallicTextureAlpha=false; matTube.useRoughnessFromMetallicTextureGreen=true; // matTap=new BABYLON.PBRMaterial("MaterialPBR_Tap",_Scene); matTap.albedoTexture=new BABYLON.Texture("assets/models/mono/Manetas_BaseColor.png",myScene); matTap.metallicTexture=new BABYLON.Texture("assets/models/mono/Manetas_Metallic_PBR.png",myScene); matTap.bumpTexture=new BABYLON.Texture("assets/models/mono/Manetas_Normal.png",myScene); matTap.reflectionTexture=textEnvironment; matTap.microSurface=0.96; matTap.useRoughnessFromMetallicTextureAlpha=false; matTap.useRoughnessFromMetallicTextureGreen=true; // matSprinkler=new BABYLON.PBRMaterial("MaterialPBR_Sprinkler",myScene); matSprinkler.albedoTexture=new BABYLON.Texture("assets/model/mono/Resto_BaseColor.png",myScene); matSprinkler.metallicTexture=new BABYLON.Texture("assets/models/mono/Resto_Metallic_PBR.png",myScene); matSprinkler.bumpTexture=new BABYLON.Texture("assets/models/mono/Resto_Normal.png",myScene); matSprinkler.reflectionTexture=textEnvironment; matSprinkler.microSurface=0.96; matSprinkler.useRoughnessFromMetallicTextureAlpha=false; matSprinkler.useRoughnessFromMetallicTextureGreen=true; ... Here, as in the case of my first doubt, I'm thinking, obviously in using "matXXX.reflectionTexture=textEnvironment.clone();", but I don´t know if that is a way to enhance performance, and by the way if dds files are buffered in a way they can benefit of texture cloning mechanism. Ok, this is all, sorry for the length of the question and, as always, thanks in advance for your time! Regards. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 25, 2017 Share Posted October 25, 2017 Hey:) so : 1. The option 1 is better. But cloning is not a big deal as only some number values will be duplicated. The internal texture will be shared 2. see #1. No need to clone either 3. scene.environmentTexture is exactly here for that. Only set this value and nothing in the material itself. The value exists at both levels because you may want to specify a specific one for a given material paleRider 1 Quote Link to comment Share on other sites More sharing options...
paleRider Posted October 26, 2017 Author Share Posted October 26, 2017 Thanks Deltakosh. I'm going to test all this, mainly the Scene.environmentTexture and we'll back again in order to check this question as "solved". Best regards. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 26, 2017 Share Posted October 26, 2017 Sounds good paleRider 1 Quote Link to comment Share on other sites More sharing options...
paleRider Posted October 27, 2017 Author Share Posted October 27, 2017 Only one more thing Deltakosh. Based on your explanation, what would be an appropriate case to use texture.clone? Thanks for your time. Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 27, 2017 Share Posted October 27, 2017 A texture has a lot of parameters which can be changed (like v and uOffset etc'). If you want to use the same texture, but change the parameters in one of the objects, you could use the clone method. Internally it will reuse the texture data, taking the new parameters. paleRider 1 Quote Link to comment Share on other sites More sharing options...
paleRider Posted October 27, 2017 Author Share Posted October 27, 2017 Ok RaananW, I see. I don´t know now why , but the case is that I thought assigning the same texture to different material "channels" (diffuse, ) of the same or a different mesh, had a performance hit when not done by means of a clone of that texture. Misunderstandings happen! Thanks for your time guys... I think this question is solved. RaananW and GameMonetize 2 Quote Link to comment Share on other sites More sharing options...
dbawel Posted October 29, 2017 Share Posted October 29, 2017 @paleRider- As for your last question: On 10/26/2017 at 10:36 PM, paleRider said: Based on your explanation, what would be an appropriate case to use texture.clone? I definitely clone meshes which are imported, along with the materials which I apply in my babylon.js script when I am creating thousands (even hundreds) of objects to apply procedural animation. Especially if the materials are 20 lines of code with multiple shaders and textures. In testing, I find this reduced my memory usage, especially garbage collection. and in cloning vs. instancing - I find cloning provides me with far more control over properties of individual meshes and their attributes. DB 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.