x


Cloning Substance (Procedural Material) at Runtime

Ok, I have many different surfaces (renderers) that I want to dynamically create procedural materials for.

What I'm doing now :

I have a reference material :

public ProceduralMaterial _substanceReference;

I have a table of procedural materials :

public ProceduralMaterial [] _materials;

Then for each of them I want to create a clone that I can change independently :

_materials[_index] = Object.Instantiate(_substanceReference) as ProceduralMaterial;

Now, if I change the property of one :

if (_material.HasProceduralProperty("myColor"))
{
 _material.SetProceduralColor ("myColor", _color);
 _material.RebuildTexturesImmediately();
}

It changes them all. It seems to be changing the original and not the clone.

I must be missing something here..

Thanks for your help.

more ▼

asked Jul 24 '12 at 07:16 PM

CgShady gravatar image

CgShady
103 13 15 22

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Hi,

I figured it out, and will share my finding here.

I had a material (not procedural) reference, which I was tweaking before I would apply it to other objects. I found that applying the material to an object "creates" the instance I was looking for.

So the proper process is :

  1. assign the material to an object (say the first you want to have an individual look)
  2. reference the assigned material (putting it in a List for example)
  3. assign the referenced material to any other object that is supposed to
  4. share the same material tweak the reference as you like

I was trying to instantiate the material before I would assign it. It now works as I want, with pretty good performances.

Thanks!!

more ▼

answered Aug 08 '12 at 10:27 PM

CgShady gravatar image

CgShady
103 13 15 22

(comments are locked)
10|3000 characters needed characters left

You can instantiate substances at runtime using renderer.material instead of renderer.Sharedmaterial, Instanciate should not be used with procedural materials.

ProceduralMaterial Instance = GameObject.renderer.material as ProceduralMaterial;

This will instanciate dynamically a new copy "Instance" of the procedural material applied to GameObject.

more ▼

answered Aug 07 '12 at 08:01 AM

Jerc gravatar image

Jerc
111 2

I really must be missing something here.

I tried using : GameObject.renderer.material as ProceduralMaterial;

All I get is 3 materials using the same procedural material textures.

I want to "duplicate" a procedural material. In other words, I want to duplicate the generated textures as well. Say I have a procedural material that has a property called "sbs_color", I want to create several duplicates, each with a different colour.

Is that possible at all ?

Thanks

Aug 07 '12 at 09:58 PM CgShady
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x817
x300
x130
x36

asked: Jul 24 '12 at 07:16 PM

Seen: 646 times

Last Updated: Aug 08 '12 at 10:27 PM