Jump to content

[SOLVED] Cloning/inheriting materials


photo

Recommended Posts

I'm trying to create multiple decals at runtime, but the code I'm trying to use results in all of the decal materials being linked (e.g. changing the texture of one changes the texture of all). Here's an example of creating two decals with supposedly different materials/textures. I've tried numerous combinations of inherit/clone/creating materials, hence the messiness, but no luck yet.

Unigine::Materials::get()->load("samples/decals/common/decals.mat");

Unigine::Materials::get()->create("newLib");
Unigine::Materials::get()->inheritMaterial("decal_deferred_base", "newLib", "decal_new");
Unigine::Materials::get()->inheritMaterial("decal_deferred_base", "newLib", "decal_new2");

Unigine::MaterialPtr baseMaterial = Unigine::Materials::get()->findMaterial("decal_deferred_base");

Unigine::MaterialPtr decalMaterial = baseMaterial->inherit("decal_new");
decal = Unigine::DecalDeferredOrtho::create(1000.f, 0.2f, 0.2f, "decal_new");
currentTexture = Unigine::Image::create();
currentTexture->load("image1.png");
decalMaterial->setImageTextureImage(decalMaterial->findTexture("diffuse"), currentTexture);

Unigine::MaterialPtr decalMaterial2 = baseMaterial->inherit("decal_new2");
decal2 = Unigine::DecalDeferredOrtho::create(1000.f, 0.2f, 0.2f, "decal_new2");
currentTexture2 = Unigine::Image::create();
currentTexture2->load("image2.png");
decalMaterial2->setImageTextureImage(decalMaterial2->findTexture("diffuse"), currentTexture2);

This code results in both decal1 and decal2 showing the same texture (currentTexture2). Can anyone tell me the correct way to duplicate materials?

Link to comment
×
×
  • Create New...