VEX equivalent to picni() in SOP context?

   1448   5   1
User Avatar
Member
59 posts
Joined: April 2006
Offline
So I'm trying to wrap my head around VEX coding for use in the Attribute Wrangle node in SOP context and I need a function like the hscript picni() function in order to do a pixel color lookup from a COP2 node. Using the old Point SOP, I would have used an expression like this (to, for example, set the red channel of the Cd attribute):

picni("../artwork/OUT", $BBX, 1 - $BBZ, D_CR)

Where artwork is a COP2 network and OUT is simply a Null node at the end of the comp nodes yielding the final image to use for pixel lookups.

So what is the equivalent of that in SOP-context VEX code?

@Cd.r = what do I put here?
User Avatar
Member
59 posts
Joined: April 2006
Offline
So I think I figured out a solution (using an Attribute Expression node):

Setting the Color (Cd) attribute to:
rawcolormap("op:" + opfullpath("../artwork/OUT"), min(relpointbbox(0, @P)[0], 0.9999), min(1 - relpointbbox(0, @P)[2], 0.9999))

I had to clamp the bounding box values to 0.9999 because rawcolormap() wraps a value of 1.0 around to 0.0, an annoying behavior that picni() does not exhibit.

This is a lot harder to read than the hscript expression it replicates. I hope it has superior performance to make up for that.
Edited by jrcooper - April 29, 2020 17:05:33
User Avatar
Member
8648 posts
Joined: July 2007
Offline
you can also use texture() call which has variadic arguments for filtering and wrapping
but also
Attribute From Map SOP which will provide that for you without coding, just provide uvs
and yes, the performance is uncomparable, picni() is very slow
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
7865 posts
Joined: Sept. 2011
Online
tamte
you can also use texture() call which has variadic arguments for filtering and wrapping
but also
Attribute From Map SOP which will provide that for you without coding, just provide uvs
and yes, the performance is uncomparable, picni() is very slow

Man, this is what vops was made for
User Avatar
Member
59 posts
Joined: April 2006
Offline
Ah, the “wrap” keyword argument does help simplify the VEX expression somewhat:

rawcolormap("op:" + opfullpath("../artwork/OUT"), relpointbbox(0, @P).x, 1 - relpointbbox(0, @P).z, "wrap", "edge")

Thanks!

(BTW, the Attribute From Map SOP doesn't have “edge” or “clamp” type wrapping options, so I'll be sticking with the above VEX expression in an Attribute Expression SOP.)
User Avatar
Member
8648 posts
Joined: July 2007
Offline
jrcooper
(BTW, the Attribute From Map SOP doesn't have “edge” or “clamp” type wrapping options, so I'll be sticking with the above VEX expression in an Attribute Expression SOP.)
according to help edge clamp and streak are equivalents so it does have the option you need:
https://www.sidefx.com/docs/houdini/vex/functions/colormap.html
repeat or periodic
The image map will repeat outside the range 0 to 1. Basically, the integer component of the texture coordinate is ignored. This is the default.

clamp or edge or streak
The texture coordinates will be clamped to the range 0 to 1. This causes evaluations outside the range to evaluate to the color at the closest edge of the image (the border pixels are streaked outside the range).

black or decal or color
Coordinates outside the range 0 to 1 will evaluate to the border color (rather than a color in the image). The border color is black (i.e. 0) by default.


but you can also use texture VOP as jsmack mentioned
Edited by tamte - April 30, 2020 19:36:15
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links