Jump to content

Texture on Copy based on luminance value


Recommended Posts

First post, and pretty new to Houdini (coming from C4d). What I'd like to do is have a flat grid of polygons that are acting as "pixels" whose color is driven by an underlying image sequence. That much I have been able to figure out using a grid of points, and then mapping a simple 1x1 square per point. I've been able to get a color per copy based on an image sequence as well, using a vopsop. What I'd like to do, is for each copy, read the luminance or color value, and be able to map an image to certain ranges of luminance. (example: black - nothing, gray - small circle, white - big circle) What i've tried so far always maps the pixel image to the whole grid, and not to the individual square. 

Any direction would be wonderful!! I could be heading in the complete wrong direction with this. 

I'll attach my hip, but without the image sequence it'll be hard to see what's going on so far. I'll upload a video as well showing the basics of what's happening so far. 

Pixel Grid.hipnc

example.mp4

Edited by ClintAnders
Link to comment
Share on other sites

Post is a little wordy, so on a more concised level: Is there a way to map a texture on a per copy basis, based on some factor(i.e. luminance)? Seems like I keep getting stuck with the texture mapping and stretching to the 16 x 9 grid, when I want it to look at each square and texture that. 

Link to comment
Share on other sites

One way is to create multiple materials each with a unique texture. Invent a naming convention that links the texture number to the name (i.e my_material0, my_material23 etc). On the points side of your Copy node drop down an attributeWrangle, running over points and place the following code in it.

int texture_count = 4; //The number of random textures in use.
i@rnd_index = int(rand(@ptnum+@Time) * texture_count);

Now that you have a random index in the range of 0 to texture count-1 you can use it to modify the name of a path to a material using a stamp expression. Instead of using a random number you could use your luminace value instead.

/shop/my_material`stamp("../copy1","rnd_index",0)`

One last thing. The newly created attribute @rnd_index only exists on the points side of the Copy. To use it in a stamp on the object side you need to enable Stamping for the Copy sop and type the name of the attribute into the Attribute field. This is how the Copy sop maps attributes from one side to the other.

Edited by Atom
Link to comment
Share on other sites

Here is a setup that might work. It uses the luminance from one map to control what color the copies are. The brightness threshold is set to 50%. In this image the luminance map is a black and white checkerboard. In theory the wrangle could fetch colors for the "under the threshold" value from another map/input instead of being a constant in this example.

Untitled-1.jpg

ap_luminance_colorize_copies.hipnc

Edited by Atom
Link to comment
Share on other sites

YES! Seriously, thanks so much everyone. This is all super helpful in trying to get grasps on different ways I can go about this. VEX is pretty new to me, and trying to get a better grasp for it.

Konstantin, this is super close! And it's really helpful to see a lot of the parts I was missing. I was able to work it into what I had in my head. But ideally I'm trying to be able to feed a single image per luminance range, and be able to add any amount of ranges that could each correspond to an image. Any direction on how to best go about doing that? 

Again, thank you! Loving this program. 

Link to comment
Share on other sites

4 hours ago, Atom said:

One way is to create multiple materials each with a unique texture. Invent a naming convention that links the texture number to the name (i.e my_material0, my_material23 etc). On the points side of your Copy node drop down an attributeWrangle, running over points and place the following code in it.


int texture_count = 4; //The number of random textures in use.
i@rnd_index = int(rand(@ptnum+@Time) * texture_count);

Now that you have a random index in the range of 0 to texture count-1 you can use it to modify the name of a path to a material using a stamp expression. Instead of using a random number you could use your luminace value instead.


/shop/my_material`stamp("../copy1","rnd_index",0)`

One last thing. The newly created attribute @rnd_index only exists on the points side of the Copy. To use it in a stamp on the object side you need to enable Stamping for the Copy sop and type the name of the attribute into the Attribute field. This is how the Copy sop maps attributes from one side to the other.

 

Hey Atom, stamp expressions are pretty new to me. I can't seem to get the copy stamp to read the textures at all. I've set up material networks with the textures I need, but it doesn't seem to be doing anything within the Copy. 

Link to comment
Share on other sites

Hi Max,

I have set up a shader that reads in the luminance value and has a slider for the ranges. The more texture nodes you feed into the switch the more image variation you should get.

BTW: I am still interested in a solution for dynamically creating strings in VOPs in this manner:

"../location/filename_" + int fileNumber + ".jpg"

Maybe someone could help out?

tiles.jpg

image_tiles.hipnc

  • Thanks 1
Link to comment
Share on other sites

Konstantin, this is incredible. This is exactly it. Thank you! 

One last question, mainly to satisfy my curiosity. Why does this have to take place in a material shader, and not just happen in a vopsop after lum has been established. Seems like it would translate there, and then be able to be seen in the viewport instead of only on render, but I've tried to replicate it there to no avail. Curious the reasoning behind this. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...