Page 1 of 3

### Random Texture Transforms over Instances

Posted: Wed Jul 30, 2014 9:27 am
Dear Lua Coders,

First of all I'd like to thank to everyone who contributed to "Render and save all render targets to PNG".

Now I have a huge request which is extremely important in my work. It is possible to construct nodes - see orbx attached, but on the greater scale - LUA is necessary.

Namely: I can use "random color texture" and assign to gradient control points the same jpg texture and modify their input values independently - see the screenshot. This allows to transform the same texture over instances. The effect is - THEY DON'T LOOK THE SAME In my simple example (the screenshot) you see only 3 different transforms. But I can add more and more control points to the gradient node and get more and more different transforms of the same texture.

Let's assume I have 1000 instances. And I want to create 1000 control points in the gradient, connect the same image texture to them (as copies) and modify their transform independently and randomly.

The script may look like this (I am not LUA coder, so forgive me my way of presenting the algorithm)

1. Set N (no of max transforms/control points), to e.g. 1000.
2. Create the gradient node with N control points.
3. Let "i=1,...,N" enumerate consecutive control points in the gradient.
4. For every i-th control point set its position value equal to
pv(i) = (1/(N-1))*(i-1)
(If N=1000, pv(1)=(1/(1000-1))*(1-1)=0;
pv(2)=(1/(1000-1))*(2-1)=0.001;
...
pv(1000)=(1/(1000-1))*(1000-1)=1)

5. Load an image texture (would be very nice to load more than one )
6. Connect the same image textures (as copies) to i-th value (let's call it v(i))
7. Randomly assign values for 3D transforms, also for gamma and power if possible.

in a do loop form:
=========
N=1000;
for i (from 1 to 1000);
set i-th position value (in the gradient node)to pv(i)=(1/(N-1))*(i-1);
connect an i-th image copy to v(i);
randomly assign values (taken from the input panel)to the image texture 3D transforms, (also to gamma and power if possible);
i=i+1;
endfor;
=========

The input panel for random values may look like this - see the attachement.

Guys, I am begging you - please help with writing the script. This is the most important feature I need. I am creating tons (literally millions of mouldings on my classical architecture buildings) and the must by UVed and unfortunately they look the same. This script would solve this problem.

smicha

### Re: Random Texture Transforms over Instances

Posted: Wed Jul 30, 2014 10:11 am
This is like random color texture, but now it is just working with color, right?
And you want to see a random image texture (instead of only color) with kind of mixture... Is that correct?
I have also a lot of problems with textures that repeat is seen on large surfaces... Is that one of the problems to solved then?

If I understand it correctly... I say 'yeah, yeah, yeah... Please go for it'

### Re: Random Texture Transforms over Instances

Posted: Wed Jul 30, 2014 10:43 am
rappet wrote:This is like random color texture, but now it is just working with color, right?
And you want to see a random image texture (instead of only color) with kind of mixture... Is that correct?

I want image texture to be randomly transformed, scaled, rotated - over instances. But surely you could mix it with random colors.

Please download the orbx attached in the first post and play with seed values. You'll see the effect.

### Re: Random Texture Transforms over Instances

Posted: Wed Jul 30, 2014 11:19 am
Hi Smicha,

that's quite a clever way to "scatter" textures over instances. There is only one problem: The gradient node only allows up to 256 (I think - would need to check the code) input textures. You could create more pins, but to achieve a fast (constant time) mapping from input value to to output texture, the maximum number of possible positions needs to be limited. When I wrote it, I thought 256 should be enough. In the beginning it was even limited to 16 positions...

We can have a look at how hard it would be to create a random float value node instead. Basically with a min/max/step for X/Y/Z as displayed in your mockup.

Cheers,
Marcus

### Re: Random Texture Transforms over Instances

Posted: Wed Jul 30, 2014 12:16 pm
abstrax wrote:Hi Smicha,

that's quite a clever way to "scatter" textures over instances. There is only one problem: The gradient node only allows up to 256 (I think - would need to check the code) input textures. You could create more pins, but to achieve a fast (constant time) mapping from input value to to output texture, the maximum number of possible positions needs to be limited. When I wrote it, I thought 256 should be enough. In the beginning it was even limited to 16 positions...

We can have a look at how hard it would be to create a random float value node instead. Basically with a min/max/step for X/Y/Z as displayed in your mockup.

Cheers,
Marcus

Marcus,

N=256 is more than enough. So please if you can try to code it. And a random float value node is something I asked some time ago.

Look forward to see some code guys

### Re: Random Texture Transforms over Instances

Posted: Mon Aug 04, 2014 8:14 pm
Ok here is a first version of the script:
Texture Scatter.lua

Please make sure that you use version 2.05.2, since previous versions have a bug in the property binding which breaks the script (basically the greyscale check box and texture directory field aren't read out).

I hope it does what you want. I have limited the maximum number of variations to 256 which is the maximum number of input pins that make sense on the gradient node (for the reasons I explained before).

The last settings will be stored in a file in your temp folder and loaded automatically the next time you run the script.

### Re: Random Texture Transforms over Instances

Posted: Mon Aug 04, 2014 8:34 pm
abstrax wrote:Ok here is a first version of the script:
Texture Scatter.lua

Please make sure that you use version 2.05.2, since previous versions have a bug in the property binding which breaks the script (basically the greyscale check box and texture directory field aren't read out).

I hope it does what you want. I have limited the maximum number of variations to 256 which is the maximum number of input pins that make sense on the gradient node (for the reasons I explained before).

The last settings will be stored in a file in your temp folder and loaded automatically the next time you run the script.

Marcus!
THANK YOU I start playing with it and let you know how it goes.

### Re: Random Texture Transforms over Instances

Posted: Mon Aug 04, 2014 9:34 pm
YES!!! IT WORKS. I am happy like a kid

At the screenshot you see one box, two textures and almost 2000 UVed instances - (almost, up to 256 variations) all look different.

So now it's time for more wishes

1. Could you please code extra option to select not only a folder for texture path but also a single image, or holding ctrl more images?
2. Could you please code extra option to lock U and V scaling together?

What is your opinion: is it possible to create just a node that would replace the script and it would have inputs same as inputs from the panel?

### Re: Random Texture Transforms over Instances

Posted: Mon Aug 04, 2014 9:44 pm
That awesome guys,

Unbelievable teamwork too bringing together pseudocode & an idea with the expertise to execute it..

Well done all round

P.s. Yoink!

### Re: Random Texture Transforms over Instances

Posted: Mon Aug 04, 2014 9:47 pm
smicha wrote:YES!!! IT WORKS. I am happy like a kid

At the screenshot you see one box, two textures and almost 2000 UVed instances - (almost, up to 256 variations) all look different.

So now it's time for more wishes

1. Could you please code extra option to select not only a folder for texture path but also a single image, or holding ctrl more images?

That's unfortunately not supported in the current Lua API. We may add this in the future, but I don't have time right now.

2. Could you please code extra option to lock U and V scaling together?