How can I add random image textures to particles?

Forums: How can I add random image textures to particles?
Blender (Export script developed by yoyoz; Integrated Plugin developed by JimStar)

How can I add random image textures to particles?

Postby pegot » Sat Nov 02, 2019 6:33 pm

pegot Sat Nov 02, 2019 6:33 pm
I have about four different materials I need to add to a particle system – each material uses different textures for variation. How do I do this in Octane Blender? All the random color nodes are only for use with solid colors and a gradient (or a single image that maps to its pixel quadrants).

How can I instruct the particle system to randomly use different materials?

I know I can duplicate my object, assign each one the different materials, and add all 4 to my particle system. But what if I wanted to randomize much more than 4 materials – that could quickly add a big performance hit to the particle system.
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: How can I add random image textures to particles?

Postby ChrisH » Sun Nov 03, 2019 1:56 am

ChrisH Sun Nov 03, 2019 1:56 am
One way (that I've done it before) is to merge the textures into one image, you can then map the UV to different parts of the image by using something like this (the input/index can be driven by random values*, or particle indexes etc):
MappingNodes.png

(This is for Cycles, but you could easily make the same setup in Octane, or even do it using OSL [I thought I had converted it to Octane, but couldn't find it, and it's way too late, 2:30am, to do it atm]).
(You could also do a OSL-script/node setup that "picks" from one of several inputs. If you only have four textures, that wouldn't be that hard but it becomes a bit of a mess for more textures, using something like the Compare Tex or just some math nodes and Mix nodes)

If you have your texture files setup according to UDIM you could probably use the Image Tile Texture Node. You still need to transform the UV in similar ways as the first way, but no need to create one single image texture.

(*Do note that this setup only works with whole numbers/integers, so a random value float between 0 and 1 needs to be mapped to a integer between 0 and your number of textures [and rounded up/down]).
Attachments
RandomUV.png
Example using Particles and random value in Cycles
Windows 10 Pro - AMD Ryzen 7 2100X 8 core 3.70GHz - 32GB RAM - GeForce GTX 1080 8GB
Octane Prime - Blender Plugin user

Metal IOR values for Octane (with .blend library): https://chris.hindefjord.se/resources/rgb-ior-metals/
User avatar
ChrisH
Licensed Customer
Licensed Customer
 
Posts: 103
Joined: Sun Mar 06, 2011 12:13 am
Location: Lidköping, Sweden

Re: How can I add random image textures to particles?

Postby J.C » Sun Nov 03, 2019 9:48 am

J.C Sun Nov 03, 2019 9:48 am
CPU – i9 13900KF, 128GB RAM, GPU – RTX 4090
System – Windows 11
My Behance portfolio, Blender plugin FB support group
J.C
Licensed Customer
Licensed Customer
 
Posts: 1721
Joined: Thu May 13, 2010 6:35 pm
Location: Wrocław

Re: How can I add random image textures to particles?

Postby pegot » Wed Nov 06, 2019 3:31 pm

pegot Wed Nov 06, 2019 3:31 pm
Thanks ChrisH and JC for the info. I’m afraid the node setup ChrisH posted for Cycles is at the moment beyond me and I would have no idea how to translate it to Octane.

I did find this Cycles tutorial for multiple textures on particles and this seems much easier and does indeed work. Again, though, I have no idea how to convert it for use in Octane – if that is even possible. The tutorial is below. It is for 32 different image textures, but I simplified the node layout in my screenshot for just two textures. I tried to replicate this with Octane gradient and instance range texture but I did not work.

https://www.youtube.com/watch?v=uRmCG5a ... e=youtu.be

Random-MultipleTextures-Cycles.png


I also tried the following OSL script from this thread:
viewtopic.php?f=73&t=53839&hilit=random+texture

It works great in Stand Alone. But when I tried to import it into a Octane Blender OSL script node I got compilation errors. So I have no idea how to use the OSL script within Blender directly. Is it possible?
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: How can I add random image textures to particles?

Postby ChrisH » Wed Nov 06, 2019 6:13 pm

ChrisH Wed Nov 06, 2019 6:13 pm
TBH the setup in the video for Cycles looks a bit painful (and complex, simply because the number of times you have to repeat the same thing [and then combine them]), using UDIM could be an easier way to go (and not as rigid), but it wasn't a thing in Blender then.
It should be possible to make that in Octane, although you forgot about the shaders/materials (like Diffuse etc) in your test. (It would probably be best to use MixRGB nodes to put them together, and then one just one shader)

The reason the script from the thread you linked to didn't work in Blender is because it's not an OSL script, it's a Lua script. A similar script for Blender would be written in Python, which is probably possible (but adds unnecessary complexity, IMHO).

I translated the node setup I've used to an OSL script:
Code: Select all
shader UVReMap
(
    color Index = 0.5,
    int Rows = 2,
    int Columns = 2,
    int Tiles = 1 [[string label = "Using Tiles", string widget = "boolean"]],
    point Projection = point(u, v, 0)
        [[string label = "Projection"]],
    output point uvw = 0)
{
    float IndexFloat = Index[0];
    float Total = (float)Rows * (float)Columns;
    float IndexFloor = floor(IndexFloat * Total);
   
    if (Tiles) {
        float perc = Total * IndexFloat;
        float row = perc / ((float)Rows);
        float row_r = floor(row);
        float col_r = floor((row - row_r) * (float)Columns);
       
        uvw[0] = Projection[0] + col_r;
        uvw[1] = Projection[1] + row_r;
    } else {

        float ColX = 0.0;
        float RowY = 0.0;   
        float ScaleX = 0;
        float ScaleY = 0;

        ColX = floor(IndexFloor / (float)Rows) / (float)Columns;
        RowY = (float)((int)IndexFloor % Rows) / (float)Rows;

        ScaleX = Projection[0] / (float)Columns;
        ScaleY = Projection[1] / (float)Rows;

        uvw[0] = ScaleX - ColX;
        uvw[1] = ScaleY + RowY;// + IndexFloat;
    }
   
    uvw[2] = Projection[2];

}

Octane_Mapping.png


It works with the Image Tile Tex*, but I can't seem to get that node working in Blender, and the documentation is more than lacking ( https://docs.otoy.com/BlenderH/BlenderP ... geTile.htm ).
By using the Image Tile Tex you would be able to have images named as image_1001.png, image_1002.png, image_1003.png etc

ETA: I have updated the script and it now works in Stand Alone, with Image Tiles, I would test it in Octane Blender as well, but I can't figure out how to get the Image Tile node to work in Blender.
BUT with this setup I can get it to "select one image" at random for each particle, with just three nodes (Random Color, OSL Projection and Image Tile), and it doesn't matter how many images you have, just set the appropriate properties.

ETA 2: I figured out how to use the Image Tile Tex, but it doesn't work properly: viewtopic.php?f=114&t=73110
Windows 10 Pro - AMD Ryzen 7 2100X 8 core 3.70GHz - 32GB RAM - GeForce GTX 1080 8GB
Octane Prime - Blender Plugin user

Metal IOR values for Octane (with .blend library): https://chris.hindefjord.se/resources/rgb-ior-metals/
User avatar
ChrisH
Licensed Customer
Licensed Customer
 
Posts: 103
Joined: Sun Mar 06, 2011 12:13 am
Location: Lidköping, Sweden

Re: How can I add random image textures to particles?

Postby J.C » Fri Nov 08, 2019 3:46 pm

J.C Fri Nov 08, 2019 3:46 pm
I've used OSL script I mentioned earlier. Works as expected on instanced meshes:

Code: Select all
#include <octane-oslintrin.h>

shader textureSheet (

    output point uvOut = 0,
   
    int maxcount = 16
        [[int min=1, int max=10000]],
       
    int columns = 4
        [[int min=1, int max=100]],
       
    int rows = 4
        [[int min=1, int max=100]],

    color RandomTexture = color(1, 0, 0)

    )
   
{
   color c2 = _evaluateDelayed(RandomTexture, 0.5, 0.5);
   int instRnd = (int) floor(c2[0]*maxcount);
   
   int column = instRnd % columns;
   int row = (int)floor(instRnd / columns);
   
   float U2 = (u + column) / columns;
   float V2 = (v + rows - row - 1) / rows;

   uvOut = point(U2, V2, 0);

}


osl random tex.png
CPU – i9 13900KF, 128GB RAM, GPU – RTX 4090
System – Windows 11
My Behance portfolio, Blender plugin FB support group
J.C
Licensed Customer
Licensed Customer
 
Posts: 1721
Joined: Thu May 13, 2010 6:35 pm
Location: Wrocław

Re: How can I add random image textures to particles?

Postby pegot » Fri Nov 08, 2019 5:34 pm

pegot Fri Nov 08, 2019 5:34 pm
J.C wrote:I've used OSL script I mentioned earlier. Works as expected on instanced meshes

Yes your script and set up works perfectly! Thanks. Only drawback I see is that one must create a very large parent texture if using high res images above 2k. Also the number of variations can become problematic if using a lot of different high res textures. It is usable with my four 2k textures fitting into a single parent image of 4096 x 4096 – but I can imagine it becoming difficult with eight different 4k textures, for example. That would require quite a massive parent texture to fit all variations into.

I think in that case the cycles approach would be better if it could be made to work with Octane nodes.

QUESTION: How did you enter the OSL script to use as internal? I tried selecting internal and copying your code into the little rectangle field of the OSL Projection node but nothing happened. I had to create a separate text file of your OSL code and open it in the OSL Projection node as an external file.
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: How can I add random image textures to particles?

Postby J.C » Fri Nov 08, 2019 10:30 pm

J.C Fri Nov 08, 2019 10:30 pm
pegot wrote:...
QUESTION: How did you enter the OSL script to use as internal? I tried selecting internal and copying your code into the little rectangle field of the OSL Projection node but nothing happened. I had to create a separate text file of your OSL code and open it in the OSL Projection node as an external file.


Use Blender's built-in text (Shift+F11) editor to enter the script that can be used as internal OSL script.
CPU – i9 13900KF, 128GB RAM, GPU – RTX 4090
System – Windows 11
My Behance portfolio, Blender plugin FB support group
J.C
Licensed Customer
Licensed Customer
 
Posts: 1721
Joined: Thu May 13, 2010 6:35 pm
Location: Wrocław

Re: How can I add random image textures to particles?

Postby pegot » Sat Nov 09, 2019 12:17 am

pegot Sat Nov 09, 2019 12:17 am
J.C wrote:Use Blender's built-in text (Shift+F11) editor to enter the script that can be used as internal OSL script.

Thank you! A Bender mystery I have been trying to figure out for a while and always fell back on the ability to load an external script.
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

Return to Blender


Who is online

Users browsing this forum: No registered users and 12 guests

Fri Apr 19, 2024 4:27 pm [ UTC ]