Page 1 of 1

Random Instance Textures using OSL

Posted: Wed Mar 20, 2019 2:46 pm
by baltort
Hi all,

Apologies if this has already been discussed and solved. I recently needed to add A LOT of random textures to A LOT of instances. Using Octane Gradient Texture Nodes was a bit painful so I wrote a really simple OSL node to allow texture sheets. Using this method, we can pack lots of textures into a single grid. The projection node then samples one of the cells based on a the Random Color Node which is different for each instance. As long as your textures aren't to big, or you don't mind your texture sheet getting big, you can apply a lot of textures this way.

My notes from the OSL are here:

// A quick and dirty texture sheet projection node by James Dean.
// Set max count to the total number of images in your sheet (this can less than rows X columns; leave any unused cells on the right of the bottom row)
// Set rows and columns to... the number of rows and columns (what else would you set it to?).
// Connect a RandomColor Texture node up to the Random Texture slot.
// Connect the projection pin from the OSL node into the Texture Image node that holds the texture sheet

// Texture sheets don't have to be square, and nor do the cells (although they all have to be the same size).
// I suggest making the sheet pixel dimensions divisible by the number of rows and columns.
// Sticking to powers of 2 will probably make a programmer happy somewhere.

// Enjoy
texture sheet setup.jpg

Re: Random Instance Textures using OSL

Posted: Wed Mar 20, 2019 6:06 pm
by milanm
Ha! I made one too. Very useful.

I never posted it on the forums, just mentioned it once, I need to add preview mode and interpolation.

I used _evaluateDelayed instead so that I can have more border modes for tiling and interpolation between slices.

Code: Select all

float Select = 0;
float pu = Projection[0];
float pv = Projection[1];
float cl = Columns_x;
float rw = Rows_y;
			
float uu = ((pu/cl)+mod((1/cl)*floor(Select),1));
float vv = ((((rw-1)+pv)/rw)-mod((1/rw)*floor(Select/cl),1));

c = _evaluateDelayed( FileIn,uu,vv);
I had an idea to use it for volumetric textures but now we can do that with level set volumes and vectrons of course.

Image

Edit: And, of course I misspelled columns (facepalm)...

Cheers
Milan

Re: Random Instance Textures using OSL

Posted: Wed Mar 20, 2019 11:46 pm
by juanjgon
Looks great! Thanks for sharing it.

-Juanjo

Re: Random Instance Textures using OSL

Posted: Mon Mar 25, 2019 11:10 am
by baltort
Hi Milan,

Whilst you lose credit for not posting it, you definitely win in your choice of sample image!

Looks great!

J.
milanm wrote:Ha! I made one too. Very useful.

I never posted it on the forums, just mentioned it once, I need to add preview mode and interpolation.

I used _evaluateDelayed instead so that I can have more border modes for tiling and interpolation between slices.

Code: Select all

float Select = 0;
float pu = Projection[0];
float pv = Projection[1];
float cl = Columns_x;
float rw = Rows_y;
			
float uu = ((pu/cl)+mod((1/cl)*floor(Select),1));
float vv = ((((rw-1)+pv)/rw)-mod((1/rw)*floor(Select/cl),1));

c = _evaluateDelayed( FileIn,uu,vv);
I had an idea to use it for volumetric textures but now we can do that with level set volumes and vectrons of course.

Image

Edit: And, of course I misspelled columns (facepalm)...

Cheers
Milan