question

Bruno Rantin avatar image
Bruno Rantin asked ·

OSL Random Texture Switch Problem

Hi there! First of all, thanks for your time!

I am having some trouble ramdomly choosing a texture procedurally. If I do it the efficient way, via OSL, sampling it inside, or just generating the texture names ramdomly, the render takes around 60 - 100x more, no joking. (even pre-generating tx files).

If I do it via aiSwitch, it renders normally, but my shader tree grows exponentially and is super hard to manage, changing textures, adding or removing and what not (hypershade does not make this easy by a long shot).


Using aiSwitch the render takes around 10 seconds, but sampling it inside the osl, or just generating the names in OSL and outputing it to the fileName of aiImage, the render takes around 21 minutes.

Tried the frame number, but I guess that is passed during translation time not render time, so I cant randomize the textures.


Thanks a lot!

textureshadingoslrandom
1 comment
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

@ Could you post the OSL shader or send it to support?

0 Likes 0 · ·
Stephen Blair avatar image
Stephen Blair answered ·

String operations in shaders at shading time is never going to be fast. We never do it in the Arnold C++ shaders.

If all the string operations could be done at compile time, that would be way better

Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Mads Drøschler avatar image
Mads Drøschler answered ·

Try upload the shader so we can profile your method and see if we can improve it or spot some technical issue that could be fixed.

Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Bruno Rantin avatar image
Bruno Rantin answered ·

Hi there! Thanks a lot Mads!

The only problem is that the number is arbitrary, it is supposed to be user selected on different folders.

I am adapting and making new features from Joost van Dongen paper.


I am randomizing all 6 room sides with different textures, then randomizing curtains and furnitures at middle of room. Currently 9 textures for each of those things. Then randomizing intensity, temperature, on/off and generating normals for lighting.


d1.jpg (546.3 KiB)
d2.jpg (492.0 KiB)
d3.jpg (501.7 KiB)
2 comments Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

I would explore an alternative way to manage your texture calls.

54 texture calls needed in 9*6 grid, and you see slowdowns.

I just ran a texture call on seperate closures even, 134 texure calls, Arnold starts virtually instantly, no slowdown in CPU render speed.

0 Likes 0 · ·

Thanks again Mads!

Its actually 9x8 6 for cube, 1 for curtains, 1 for furniture.

And I plan to add support for 20 different textures.

For now, the aiSwitch is working really well, less than a minute render time (compared to around 1:20h).

So I am solving the usability issue building a mel script to replace all texture paths.
But I will sure continue to investigate a way to do it better.


Thanks a lot for your input, really! =)

0 Likes 0 · ·
Bruno Rantin avatar image
Bruno Rantin answered ·

Thanks guys!
The shader is quite complex right now, so I've isolated the texture part, which causes the problem.

This is the simplifyed tree:


And here is the string code:

shader randTex(output string outPath = "" [[ string widget = "filename" ]], 
int Selector = 1, 
string texturePath = "" [[ string widget = "filename" ]], 
string textureName = "" [[ string widget = "filename" ]], 
string textureFormat = "jpg" [[ string widget = "filename",  ]] )
{ 
outPath =  concat(texturePath, textureName, "_", format("%i",Selector), ".", textureFormat) ; }


This issue is similar to what I had when I wanted to offset an image sequence per object, using userData, I had to use OSL then too, as the offset paramenter is not used during render time too and the OSL logic is very similar.

I was able to solve it with aiSwitch, but the shader tree grew exponentially.

Basically, this:


Turned into This (I really wish Autodesk would give hypershade some love, letting us group nodes, generate custom outputs, and not ramdomly reorganize the graph when you duplicate a node, just copy the shaderFx graph, its already there, haha, jk I know its not that simple):


But render time was reduced from over 1h to 58 seconds


hypershade.jpg (233.5 KiB)
hypershade2.jpg (539.0 KiB)
hypershade3.jpg (244.8 KiB)
2 comments Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Why not just load all textures into a 1 of x map, an array map, instead of pulling random strings.
I am fairly sure we can maintain speed while having a large pool of maps going.

How many random maps are you sampling in the folder?

1 Like 1 · ·

Hi there! Thanks a lot Mads!

The only problem is that the number is arbitrary, it is supposed to be user selected on different folders.

I am adapting and making new features from Joost van Dongen paper.


I am randomizing all 6 room sides with different textures, then randomizing curtains and furnitures at middle of room. Currently 9 textures for each of those things. Then randomizing intensity, temperature, on/off and generating normals for lighting.

0 Likes 0 · ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Welcome to the Arnold Answers community.

This is the place for Arnold renderer users everywhere to ask and answer rendering questions, and share knowledge about using Arnold, Arnold plugins, workflows and developing tools with Arnold.

If you are a new user to Arnold Answers, please first check out our FAQ and User Guide for more information.

When posting questions, please be sure to select the appropriate Space for your Arnold plugin and include the plugin version you are using.

Please include images, scene and log files whenever possible as this helps the community answer your questions.

Instructions for generating full verbosity log files are available for MtoA, MaxtoA, C4DtoA, HtoA, KtoA, and Kick.

If you are looking for Arnold Documentation and Support please visit the Arnold Support site.

To try Arnold please visit the Arnold Trial page.

Bottom No panel present for this section.