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.
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 » 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: 1808
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 472 times
screenshot.png
oscartung
Licensed Customer
Licensed Customer
 
Posts: 64
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: 1808
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: 64
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: 64
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 482 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: 1808
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 452 times
oscartung
Licensed Customer
Licensed Customer
 
Posts: 64
Joined: Wed May 21, 2014 5:33 pm

Re: Create random textures over instances

Postby pegot » Thu Mar 26, 2020 3:09 pm

pegot Thu Mar 26, 2020 3:09 pm
Is there any way to have file paths to the images in the script use relative paths instead of hard coded ones? I opened an old project using this script and as things were moved around quite a bit the images no longer link.
Win 10
3.7Ghz i9 10900k / 64GB
ASUS STRIX Z490-E
PSU: PowerSpec 850Wd
RTX 3090 Asus Tuff

Network rendering:
Win 10
4.2Ghz i7 7700k / 64GB
AsRock SuperCarrier
PSU: EVGA 1200w
RTX 3080 Ti EVGA Hybrid
RTX 3080 ASUS Tuff
GTX 1080ti SC Black (wc)
pegot
Licensed Customer
Licensed Customer
 
Posts: 921
Joined: Mon Nov 07, 2011 3:44 am

Re: Create random textures over instances

Postby v-cube » Sun Feb 21, 2021 6:39 pm

v-cube Sun Feb 21, 2021 6:39 pm
Hi roeland,

I am really sorry to dig out this old tread but this topic is super interesting and important for me and my work.
I have been searching the forum for methods of randomization for tiled multi textures and ended up here.

I tried out your OSL shader "procedural flooring 2" and I am really impressed. For me this could become a real game changer for my work, since I do architectural visualizations, I deal with these kind of textures on a daily basis.
However I am not a programmer and although I try to figure out what you guys are doing, I have a really hard time. I tried to modify the code so that it would implement the ability to use multi textures like this: https://www.vizpark.com/shop/beech-wood-parquet/ , but although I spent several hours trying I failed to do it.

So here is my wish:
Could you please take the time to create a "procedural flooring 3" shader that would add the following features to the existing "procedural floor 2":

1. - Give the user the ability to add a custom number of bitmap textures and optional define a priority for the random selection e.g. texture 1 will distribute 22% of the tiles, texture 2 will distribute 30 % and so on.
2. - Give the user a way to define the cell size by input X size, Y size (this should be independent from the aspect ration of the bitmaps) and a mortar thickness and if possible basic brick patterns like this:
pattern.jpg

3. - Have the option to randomly rotate the texture by a given increment like e.g. 90 deg, together with the option to horizontally and vertically flip the images randomly.
4. Give the user the option to define a texture for the mortar (diffuse color) while preserving the possibility to have a independant displacement map like in the existing shader.

I suspect that a lot of this already exists somewhere in some tread but I am unable to put the pieces together.

IMHO this is a big, big feature for everyone involved in architectural visualization, so if someone could do this and maybe place it more prominently that buried under this thread I think a lot of people would profit from this.

I would really appreciate some help and also be happy to pay for such a shader.

Best

Andreas



P.S. : IMHO this is so important that it should become an official octane texture node and not just some OSL code inaccessible for a lot of users, who are using Octane but are not so savvy when it comes to coding.

PPS: : here is an example of a first test I did with the "procedural floor 2" shader:
villa-34.jpg
Architectural Rendering Services
1 x 4090 GTX, 1 x 3090 GTX
http://www.v-cube.de
User avatar
v-cube
Licensed Customer
Licensed Customer
 
Posts: 485
Joined: Fri Jul 22, 2011 11:02 am
Location: Aachen, Germany
PreviousNext

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 4 guests

Thu Mar 28, 2024 1:17 pm [ UTC ]