Create random textures over instances

Forums: Create random textures over instances
Forum for OctaneRender Lua scripting examples, discussion and support.

Re: Create random textures over instances

Postby Yugs » Fri Sep 15, 2017 2:34 pm

Yugs Fri Sep 15, 2017 2:34 pm
Hi,

Would it be possible to have this scripted graph working with an image texture input instead of a string value ?

That way one could, for instance, link an image node with UV transform information directly to the script. I tried to do it but I don't know the first thing about LUA. I just managed to change the string input to a texture one, but all I get is a blank material.

Thanks for this anyway, it comes very handy!

Cheers,

Yugs
Yugs
Licensed Customer
Licensed Customer
 
Posts: 11
Joined: Sat May 05, 2012 10:50 pm

Re: Create random textures over instances

Postby smicha » Mon Mar 19, 2018 8:49 pm

smicha Mon Mar 19, 2018 8:49 pm
Could you please help and make this script working under V4?
3090, Titan, Quadro, Xeon Scalable Supermicro, 768GB RAM; Sketchup Pro, Classical Architecture.
Custom alloy powder coated laser cut cases, Autodesk metal-sheet 3D modelling.
build-log http://render.otoy.com/forum/viewtopic.php?f=9&t=42540
User avatar
smicha
Licensed Customer
Licensed Customer
 
Posts: 3151
Joined: Wed Sep 21, 2011 4:13 pm
Location: Warsaw, Poland

Re: Create random textures over instances

Postby roeland » Mon Apr 09, 2018 3:00 am

roeland Mon Apr 09, 2018 3:00 am
As far as I can see the script still works under version 4.

Yugs wrote:Would it be possible to have this scripted graph working with an image texture input instead of a string value ?


It's possible to create a similar script with texture inputs, how exactly depends on what exactly you want to achieve. Do you want one image texture input with a bunch of random additional transforms applied to it?

--
Roeland
User avatar
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1808
Joined: Wed Mar 09, 2011 10:09 pm

Re: Create random textures over instances

Postby whersmy » Mon Apr 09, 2018 7:58 pm

whersmy Mon Apr 09, 2018 7:58 pm
It's possible to create a similar script with texture inputs, how exactly depends on what exactly you want to achieve. Do you want one image texture input with a bunch of random additional transforms applied to it?


Would be very welcome.

Would it be possible to create an Amount and Scale input for the scatter node? I would like to reproduce a texture like this on a big surface

Actually OSL should be able to simulate this I think
Attachments
klinkers-abbeystones_968x584_Pic_362.jpg
klinkers-abbeystones_968x584_Pic_362.jpg (24.67 KiB) Viewed 7922 times
Octane 2022.1.1 nv535.98
mac pro g5| pentium g2030 iGPU| maximus extreme V| 2x gtx590 - 8gb - SSD - win7-x64- 1500W Silverstone|
x201t - gtx580 - egpu ec
Dell G5 - 16GB - dgpu GTX1060 - TB3 egpu @ 1060 / RTX 4090

Octane Render experiments
User avatar
whersmy
Licensed Customer
Licensed Customer
 
Posts: 723
Joined: Thu Aug 30, 2012 7:40 am

Re: Create random textures over instances

Postby roeland » Mon Apr 09, 2018 8:48 pm

roeland Mon Apr 09, 2018 8:48 pm
Yes, this can be done using an OSL texture: You can start from the laminate example here: viewtopic.php?p=326508#p326508

Set the plankAspect to 1.0 for square tiles.

However, this shader will generate a random offset for every row of tiles. To get a regular pattern like in your picture find and replace the lines

Code: Select all
    // random offset for each row
    float x = p[0] + noise("cell", y, 0);

with
Code: Select all
    // alternate offset for each row
    float x = p[0] + 0.5 * ((int) y & 1);
User avatar
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1808
Joined: Wed Mar 09, 2011 10:09 pm

Re: Create random textures over instances

Postby whersmy » Tue Apr 10, 2018 9:18 am

whersmy Tue Apr 10, 2018 9:18 am
Getting there! Is it possible to add a random rotation for the square planks/tiles? In practice you would only need 4 options, each 90 degrees turned. In order to get the right irregularity for now I solved it roughness.
Attachments
osltiles.png
Last edited by whersmy on Tue Apr 10, 2018 9:30 am, edited 1 time in total.
Octane 2022.1.1 nv535.98
mac pro g5| pentium g2030 iGPU| maximus extreme V| 2x gtx590 - 8gb - SSD - win7-x64- 1500W Silverstone|
x201t - gtx580 - egpu ec
Dell G5 - 16GB - dgpu GTX1060 - TB3 egpu @ 1060 / RTX 4090

Octane Render experiments
User avatar
whersmy
Licensed Customer
Licensed Customer
 
Posts: 723
Joined: Thu Aug 30, 2012 7:40 am

Re: Create random textures over instances

Postby smicha » Tue Apr 10, 2018 9:25 am

smicha Tue Apr 10, 2018 9:25 am
Share the scene please - great job.
3090, Titan, Quadro, Xeon Scalable Supermicro, 768GB RAM; Sketchup Pro, Classical Architecture.
Custom alloy powder coated laser cut cases, Autodesk metal-sheet 3D modelling.
build-log http://render.otoy.com/forum/viewtopic.php?f=9&t=42540
User avatar
smicha
Licensed Customer
Licensed Customer
 
Posts: 3151
Joined: Wed Sep 21, 2011 4:13 pm
Location: Warsaw, Poland

Re: Create random textures over instances

Postby whersmy » Tue Apr 10, 2018 9:36 am

whersmy Tue Apr 10, 2018 9:36 am
Here we go. Usable for buildings as well if displacement is not necessary.
Attachments
Tiles.orbx
(3.13 MiB) Downloaded 431 times
Octane 2022.1.1 nv535.98
mac pro g5| pentium g2030 iGPU| maximus extreme V| 2x gtx590 - 8gb - SSD - win7-x64- 1500W Silverstone|
x201t - gtx580 - egpu ec
Dell G5 - 16GB - dgpu GTX1060 - TB3 egpu @ 1060 / RTX 4090

Octane Render experiments
User avatar
whersmy
Licensed Customer
Licensed Customer
 
Posts: 723
Joined: Thu Aug 30, 2012 7:40 am

Re: Create random textures over instances

Postby roeland » Wed Apr 11, 2018 4:44 am

roeland Wed Apr 11, 2018 4:44 am
Yes. The script as it is contains code to randomly rotate the texture by 180°:
Code: Select all
    int flip = (rnd - floor(rnd)) < .5;
    // make UV mapping per cell and evaluate the right texture
    float plU = x - floor(x);
    float plV = y - floor(y);
    if (flip)
    {
        plU = 1 - plU;
        plV = 1 - plV;
    }


We can extend this code: for instance this randomly picks any of the 8 combinations of rotation (0°, 90°, 180°, 270°) and mirroring.
Code: Select all
    int flip = (int) ((rnd - floor(rnd)) * 8);
    // make UV mapping per cell and evaluate the right texture
    float plU = x - floor(x);
    float plV = y - floor(y);
    if (flip & 1)
    {
        // flip U
        plU = 1 - plU;
    }
    if (flip & 2)
    {
        // flip V
        plV = 1 - plV;
    }
    if (flip & 4)
    {
        // flip over diagonal
        float tmp = plU;
        plU = plV;
        plV = tmp;
    }
User avatar
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1808
Joined: Wed Mar 09, 2011 10:09 pm

Re: Create random textures over instances

Postby Rik » Wed Apr 11, 2018 7:20 am

Rik Wed Apr 11, 2018 7:20 am
Hi Rowland
Can you tell us how we would use this in the plugins? I use max but have no idea about how to incorporate the code.
It look like it would be really useful.
Rik
Licensed Customer
Licensed Customer
 
Posts: 419
Joined: Wed Jul 28, 2010 8:57 pm
PreviousNext

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 6 guests

Thu Mar 28, 2024 2:29 pm [ UTC ]