Does Cloning make multiple Materiel?

I was wondering if Cloning, clone the material and make a new one out of it?

If I load a model, then I add the material and I clone the model multiple of time, will it create multiples Material or will it be the same as using the same Material on every models once they are all loaded?

And If i have multiple model using the same material (Different Model) and I applied all the material using the SDK, will it use a single material to apply on all the models or will it load a new material each time it load a model with the material? Would it be better to load the material inside the game, then apply it on every model that use it?

The reason I need to know this, is if I can save performance from MegaTexture i would do giant Texture for multiple models instead of small texture for all of them!

The default clone method does clone the material.

There is a clone method in geometry that has a cloneMaterial boolean attribute. If you set it to true it will clone the material else it will use the same material instance.

If you set the material in the SDK you’ll have several instance of the material.
But, this is not necessarily an issue. Note that the textures associated with the material won’t be duplicated in memory, also they will be cached by the asset manager so multiple subsequent loading of a material will result in 1 loading and a serie clone operation.

Also note that 2 materials that are identical (not the same instance but the same params) will be considered as the same material regarding batching operations.

Hope that helps

1 Like

Yes thank you again @nehon

So it mean if I change the Base Material all the material inside the game will change at the same time?
This is freaking awesome XD it will be of great help to make a fantastic style of the game at night,
I will send you a pic once i am done and it’s working :stuck_out_tongue:

While possible I would try a different approach.

You could instead scan trough all geometrys via the scenevisitor and change each material as required.

I dont think i would need to make a new approach if all the material already share the same material! I would only need to change the first model material to apply a new material all over the map. I would save the heavy task of making a new material for all the geometry! Unless i misunderstood what @nehon told me. Anyway i will find out my self soon!

To do what you want you need to have the same instance of the material foe every geometry.

@nehon, so does it mean, none of the clone as the same Material Object(same memory address)?

But I will go a little off topic. I was asking all this to find out why my game suddenly got a drop in the fps. I though maybe it was the texture and material the problem, but I did a small test 3 min ago, and i removed all my environment, but the floor and my fps is still low… I have no clue what I ve done 3 weeks ago, but the game is as something that slow it down. I though it was the lake(post process water) so i removed it, but i dont seem to gain any speed. And From the last verstion of the game my fps is way higher and the only thing i ve done is add Better trees, lake, and change the floor texture. I started to make the Object to old the House System, then i found that the whole game was slow. Anyway there must be an endless loop somewhere I supose… :frowning:

(Edit: I did replace the floor texture with the previous one to test)

Thank you for the help i will try to figure out the bug.

Btw the game look like this if you have any hint just let me know

2100 objects and 1.5M polygons seems pretty high. I’m not surprised you have low fps.
Your trees seems to be exactly the same so I guess you could use instancing for them.

@nehon, yes this is true but if i remove them it still lag, then if i remove all the small plants, it still show a leak.

But what does Instancing does? And is there a tutorial about it?
If it mean cloning them, i already do that. Otherwise you have to learn me about it. I ve looked on the internet and it seem i would achieve better performance doing so.

Edit, By the way will this work with the concurrency? I have my own render for close object and it load them in concurrency, I only wonder how i could use this instead of clone.

With instancing you load 1 model and tell the GPU to render it several time at different positions/rotation/scale.
The biggest advantage is that, no matter how much there are objects, they are rendered in one draw call.
The biggest limitation is that it’s the exact same object all over the place.

This feature has been added to latest JME. there are no tutorial about it but there is a test case.

Note that it’s not sure that this will out perform a classic batching strategy. From my tests, Instancing is really interesting if you have animated instances. For static objects, batching can be better regarding performance, but instancing will always use a lot less memory than batching.
So as always…it’s a trade off, and IMO it’s best to test both strategies to figure out what’s best for your need.

To solve your issue though, try removing thing until you have a decent frame rate. It’s strange that you have a bad frame rate with only the ground…
Something must be wrong, and to corner it out you have to empty the scene until you find the culprit.

1 Like