Applying randomly images from a directory

   5411   6   1
User Avatar
Member
18 posts
Joined: May 2008
Offline
Man, i know everything is possible in houdini but i don't know where and how to begin this process.

I need to place random images from a specific directory on the top of each extruded cubes which you can find in my old post:

http://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&t=14823 [sidefx.com]

Masters of illusion, i need your helllp!!! Please

thanks in advance

homer
User Avatar
Member
606 posts
Joined: May 2007
Offline
Check out the help for Material SOP [sidefx.com], as well as the Property Overrides [sidefx.com].

Here's a simple scene file showing it in action.

eetu.

Attachments:
randtex.jpg (16.2 KB)
ee_randomtextures.zip (78.6 KB)

User Avatar
Member
18 posts
Joined: May 2008
Offline
nice setup, exactly what i need.

i'll take a look more deeply through the guide

thank you very much!
User Avatar
Member
18 posts
Joined: May 2008
Offline
It's hard to understand cos' i'm a noobie:

$HIP/img/texture_`ceil(ch(“images”) * rand(97*stamp(“../copy1”, copynr, 0)))`.png

I know the $HIP/img/ command but after this part things are not easy to understand.

Sorry
User Avatar
Member
696 posts
Joined: March 2006
Offline
There is a section in the help docs (Open the Help, scroll down and look at Expression functions) where you can learn all about expressions in Houdini.

I personally prefer to use the exhelp command in the text port.

So if you go to Windows->Hscript Textport (or press alt shift t) it will open up the textport>

Type exhelp to get a list of all the expression functions
You can then type exhelp to get a description of the function.

So for example:
Houdini Master Version 9.5.406 (Compiled on Mar 13 2009)
/ -> exhelp rand
float rand (float value)
Using the same <value> always gives the same result. To vary the
result, base the <value> on a changing number (usually the current
frame $F).

| rand($F)
|
When you're randomizing component values (such as X, Y, and Z), change
the <value> for each component so they don't all get the same number:

X
rand($F)

Y
rand($F * 0.1)

Z
rand($F * 0.01)

It is a good idea to use non-integer values as the argument to rand().


so in this case, there are four functions that he is using. ceil(), ch(), rand(), stamp().

ceil() rounds a number up. ie: ceil(3.224) = 4

ch() returns the value of a channel/parameter

rand() returns a value between 0 and 1 based on whatever value is inside

stamp() is useful with the copy sop to return different values per copy.


because the texture is looking for a string, the expressions need to be enclosed in backticks ``
Stephen Tucker
VFXTD
User Avatar
Member
606 posts
Joined: May 2007
Offline
homerobaroni
It's hard to understand cos' i'm a noobie:

$HIP/img/texture_`ceil(ch(“images”) * rand(97*stamp(“../copy1”, copynr, 0)))`.png
Let's start from the inside:

stamp(“../copy1”, copynr, 0) = get the sequential number of this copy from the Copy SOP. Refers to the first stamp variable in the Copy SOP at the end of the chain.

rand(97*stamp(“../copy1”, copynr, 0)) = calculates a pseudo-random number using the stamped copy number as a seed. The 97* is not really needed, more of a habit, the output tends to be “more random” if the seeds for consecutive copies differ by more than 1.

ch(“images”) * rand(97*stamp(“../copy1”, copynr, 0)) = The output from a rand() is always between 0 and 1. This needs to be scaled by the number of images you have. I added a new parameter to the Material SOP instance from the gear menu in the upper right of the SOP's parameter pane. The new parameter is called ‘images’, and ch(“images”)* multiplies by the value of that parameter.

ceil(ch(“images”) * rand(97*stamp(“../copy1”, copynr, 0))) = the expression up to this point evaluates to a floating point value between 0.0 and the number of images, e.g. 1.11829. The ceiling function ceil(value) rounds the value always up to the next whole integer. Now we have an integer value that is pseudo-random for each copy, and between 1 and the number of images.

`ceil(ch(“images”) * rand(97*stamp(“../copy1”, copynr, 0)))` = In a string parameter backticks mark that the part between them is actually an expression and not a part of the literal string. The expression is evaluated and the result is inserted into the string. In this case the resulting string will be one of
$HIP/img/texture_1.png
$HIP/img/texture_2.png
$HIP/img/texture_3.png
depending on the copy number. Because the rand() function is pseudo-random and not truly random, the result will always be same for the same copy numbers, that is, the texture will be the same for a given copy every time the network is cooked.

eetu.

edit: darn, Allegro beat me to it
User Avatar
Member
18 posts
Joined: May 2008
Offline
maybe it will sound a little gay, but…

i love you guys, i love this community



thanks a lot for help me out
  • Quick Links