x


Set Substance RandomSeed variable in procedural material in c#?

I am trying out the evaluation version of Substance Designer which is BRILLIANT, however one thing I am finding odd is that I have a prefab and anywhere from 0-5 instances of it within the scene, however I want each one to look slightly different, so I was planning to just tweak the exposed random seed for each instance however nothing seems to happen.

I am currently using:

var instanceMaterial = instanceGameObject.renderer.material as ProceduralMaterial;
instanceMaterial.SetProceduralFloat("RandomSeed", Random.Range(0,30));
instanceMaterial.RebuildTextures();

instanceGameObject is within a loop so will be an instance of each game object of that prefab. Anyway they all look the same as if either ALL of them have changed or none of them have. Am I doing something wrong?

more ▼

asked Aug 03 '12 at 09:22 PM

Macro gravatar image

Macro
64 6 11 18

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

3 answers: sort voted first

After debugging all the possible values at runtime using GetProceduralPropertyDescriptions() I found that the random name I wanted was $randomseed

This works!

more ▼

answered Aug 04 '12 at 10:51 PM

Macro gravatar image

Macro
64 6 11 18

That will do it if you have the right param name! Yeh but if you do experience random seed issues on same frame that happens alot in games. Glad you solved it.

Aug 05 '12 at 03:34 AM drawcode
(comments are locked)
10|3000 characters needed characters left

Random.Range(0,30) will return the same value in the same frame/tick. So you can put this in a coroutine and lag a bit by waiting for ms.. or end of frame.

OR better

Set the seed at each iteration

UnityEngine.Random.seed = i++; // or some incremental value

http://docs.unity3d.com/Documentation/ScriptReference/Random-seed.html

var instanceMaterial = instanceGameObject.renderer.material as ProceduralMaterial;
instanceMaterial.SetProceduralFloat("RandomSeed", Random.Range(0,30));
UnityEngine.Random.seed = i++;
instanceMaterial.RebuildTextures();
more ▼

answered Aug 04 '12 at 10:13 AM

drawcode gravatar image

drawcode
246 2 4

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

I dont think that the random element is really the issue, as before now I have set the random seed to just be i and it still doesn't work. I think the problem is down to how im setting the procedural value. I also have a color component which when set seems to remove all color, so this question is more around the correct way to interact with setting the procedural values.

(Although it is interesting to know the limitations on range, I am seeding it using the itteration count, still have the issue)

more ▼

answered Aug 04 '12 at 10:51 PM

Macro gravatar image

Macro
64 6 11 18

(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:

x4161
x36

asked: Aug 03 '12 at 09:22 PM

Seen: 432 times

Last Updated: Aug 05 '12 at 03:34 AM