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 whersmy » Sun Apr 15, 2018 10:40 am

whersmy Sun Apr 15, 2018 10:40 am
Wonderful roeland! Is it also possible to add a seperate pin for the mortar/cement. Like an offset rule between each plank from 0 to around 10 (cm), to simulate more raw brick material? Even better would be an extra noise option to simulate "un-perfect" straight lines from the mortar/cement material.

You could also kind of achieve this by drawing in the mortar/cement on the seperate plank-texture, but then each plank would need a small overlap.
mac pro g5| pentium g2030 iGPU| maximus extreme V| 2x gtx590 - 8gb - SSD - win7-x64- 1500W Silverstone|
x201t - gtx580 - egpu ec
Octane Render experiments
User avatar
whersmy
Licensed Customer
Licensed Customer
 
Posts: 555
Joined: Thu Aug 30, 2012 7:40 am

Re: Create random textures over instances

Postby roeland » Sun Apr 15, 2018 10:19 pm

roeland Sun Apr 15, 2018 10:19 pm
Rik wrote: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.

That will depend on the plug-in. You have to use one of the new 3.08 releases.
User avatar
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1700
Joined: Wed Mar 09, 2011 10:09 pm

Re: Create random textures over instances

Postby oscartung » Fri Jul 06, 2018 7:16 am

oscartung Fri Jul 06, 2018 7:16 am
Been trying to create a procedural texture using a combination of this script and OSL textures found on this forum.
Here is my take so far.
screenshot2.png


Would anyone be so kind to modify the script so everything is sourced from one texture and it takes in an arbitrary Input node instead of the randomize color input node
screenshot2.png


i will the upload my orbx file here also
Attachments
procedural flooring.orbx
(485.58 KiB) Downloaded 35 times
screenshot.png
oscartung
Licensed Customer
Licensed Customer
 
Posts: 49
Joined: Wed May 21, 2014 5:33 pm

Re: Create random textures over instances

Postby roeland » Mon Jul 09, 2018 4:54 am

roeland Mon Jul 09, 2018 4:54 am
There are a few ways to implement a parquet shader like that. For a setup similar to yours, you can implement your shader as an OSL projection instead of an OSL texture, and return the UV coordinates where to sample the image. Return some magic number for the seams.

Code: Select all
shader brick(
        matrix Transform = .25,
        point Projection = point(u, v, 0) [[string inputType = "projection"]],
        float seed = 0.1 [[float min = 0, float max=10, float sliderexponent=1]],
        float offset = 0,
        float thick=0.05,
        float rat=0.6,
        float  rep=2,
        int TileCount = 1 [[ int min = 0, int max = 30 ]],
        output point c = 0 )
{
    point p = transform(1/Transform, Projection);
   
    float y=rat*rep*p[1];
    float x=rep*p[0]+noise("cell", floor(y)) * seed * 100 + offset*((int) y & 1); 
    float nx=x-floor(x);
    float ny=y-floor(y);
   
    if (nx>1-thick || ny<rat*thick)
    {
        c = point(0, 0, 1);
    }
    else
    {
        // map horizontal slices of the input texture:
        float brg = noise("cell", point(floor(x),floor(y),0));
        c = point(nx, (ny + floor(TileCount * brg)) / TileCount, 0);
    }
}


The OSL projection node is then connected to the projection pin of the image texture. Reset the UV transform to the default settings. You don't need the node graph with the color correction and gradient node anymore.

For the Mortar Map you can check for the magic number with a simple OSL texture node:

Code: Select all
shader OslTexture(
    point map = P,
    output color c = 0)
{
    // test: map.z == 0
    c = (map[2] == 0);
}
User avatar
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1700
Joined: Wed Mar 09, 2011 10:09 pm

Re: Create random textures over instances

Postby oscartung » Sun Jul 15, 2018 8:34 am

oscartung Sun Jul 15, 2018 8:34 am
Hi Roeland, thank you or your reply.

I managed to get it working to randomize the position of the UV texture, however I without the UVW transform node and color correction node I cannot rotate/scale the texture and provide random hue/brigthness like my previous example , is there a way around this?
oscartung
Licensed Customer
Licensed Customer
 
Posts: 49
Joined: Wed May 21, 2014 5:33 pm

Re: Create random textures over instances

Postby oscartung » Mon Jul 16, 2018 2:55 am

oscartung Mon Jul 16, 2018 2:55 am
Hi Roeland, I have an idea to but I am not sure if it is possible to implement through LUA or not. Is it possible to make turn this into a pin which provides a random value per pin within a certain range(specified by user) through LUA script?
random value.png
oscartung
Licensed Customer
Licensed Customer
 
Posts: 49
Joined: Wed May 21, 2014 5:33 pm

Re: Create random textures over instances

Postby roeland » Wed Jul 18, 2018 9:56 pm

roeland Wed Jul 18, 2018 9:56 pm
I think generally, random variations in hue or brightness are much easier to implement entirely in OSL. For the hue, see _hueshift().

For instance, to randomize the hue and saturation of a texture:

Code: Select all
#include <octane-oslintrin.h>
shader Randomize(
    color img = 0,
    point p = P,
    output color c = 0)
{
    color rnd2 = noise("cell", p);
    c = _hueshift(img, mix(-.1, .1, rnd2[0]));
    c *= mix(.3, 1, rnd2[1]);
}


You can add parameters to this shader as needed.

The cell noise in this shader will supply a different random value depending on the value connected to the p input. You can connect the output of the brick shader to the p input, but as is, this will always generate the same value. You can change the brick projection shader to return a different value per tile in the Z channel (which is ignored by the image texture):

Code: Select all
    ...
    if (nx>1-thick || ny<rat*thick)
    {
        // magic number for joint
        c = point(0, 0, -1);
    }
    else
    {
        // map horizontal slices of the input texture:
        float brg = noise("cell", point(floor(x),floor(y),0));
        // supply a different coordinate for each tile in the Z channel:
        float z = floor(x) + 100 * floor(TileCount * brg);
        c = point(nx, (ny + floor(TileCount * brg)) / TileCount, z);
    }
}


and change the test in the mortar map to c = (map[2] >= 0).

I think one of the reason there are seams in the texture are the UVW transform nodes. If you use these, carefully pick the transforms so they don't map seams in the middle of the UV tile. For debugging, you can set the image border mode to black, and verify you don't get black areas in your material.

So that's the material with the above modifications:
procedural flooring 2.orbx
(474.4 KiB) Downloaded 43 times


Another tip, you can slightly blur the displacement by using the filter type and filter size inputs, this can improve the appearance of the edges of the tiles.
User avatar
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1700
Joined: Wed Mar 09, 2011 10:09 pm

Re: Create random textures over instances

Postby oscartung » Mon Nov 19, 2018 1:47 am

oscartung Mon Nov 19, 2018 1:47 am
First of all I'd like to thank you again for this very useful script.
I am trying to drive the randomness by using a OSL node (random value for each UV tile) instead of instances.
It works great however each time I try to update the texture the random osl node is replaced with random color node
Is there a way around so that the OSL node remains the same after pressing update texutre?

I have updated the scene file here.
thank you in advance
Attachments
Scattered Texture.orbx
scattered texture
(367.67 KiB) Downloaded 8 times
oscartung
Licensed Customer
Licensed Customer
 
Posts: 49
Joined: Wed May 21, 2014 5:33 pm
Previous

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 1 guest

Thu Dec 13, 2018 12:34 am [ UTC ]