Community
Arnold for 3ds Max
Rendering with Arnold in 3ds Max using the MaxtoA plug-in.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

OSL Random Texture Switch Problem

9 REPLIES 9
Reply
Message 1 of 10
brurpo
714 Views, 9 Replies

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!

Labels (4)
9 REPLIES 9
Message 2 of 10
Stephen.Blair
in reply to: brurpo

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



// Stephen Blair
// Arnold Renderer Support
Message 3 of 10
madsd
in reply to: brurpo

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.

Message 4 of 10
Stephen.Blair
in reply to: brurpo

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



// Stephen Blair
// Arnold Renderer Support
Message 5 of 10
brurpo
in reply to: brurpo

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:

6355-hypershade.jpg


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:

6356-hypershade2.jpg


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):
6357-hypershade3.jpg


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

Message 6 of 10
madsd
in reply to: brurpo

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?

Message 7 of 10
brurpo
in reply to: brurpo

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.

6358-d1.jpg

6359-d2.jpg

6360-d3.jpg

Message 8 of 10
brurpo
in reply to: madsd

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.

6358-d1.jpg

6359-d2.jpg

6360-d3.jpg

Message 9 of 10
madsd
in reply to: brurpo

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.

Message 10 of 10
brurpo
in reply to: madsd

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! 😃

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report