SamuZai
DavidKahlVFX
DavidKahlVFX

patreon


Quicktip#9 SOP/VOP vs VEX comparison

Hey folks,

I came up with another variant of content to have something for the people while working on the course. 

The idea is to take a general task, could be simple or a bit more complex. Something that needs at least a couple of nodes. Then I solve them leaning into SOP land as much as possible and compare it to the VEX approach right after. That way people can pick the best from both world according to their preferences. It also makes it easier to understand what the vex code does. 

These ideas are also an interesting quicktip before I can turn them into a video. So here is a first example.

Here is the premise 

The primitives of a surface should be extruded depending on their distance to a specific position. The steps for the extruded distance should be done in integer steps to achieve the blocky appearance.

There are many ways to achieve this and I invite you to share your own ideas. But this is how I solved it with in SOP/VOP land:

I create an attribute called scale (float, primitive) which gets the default value of 1. That goes into an primitive VOP that also has a single point on the 2nd Input that I can move by a transform node.

Inside the VOP I do the following. I get the Position attribute from the 2nd input and compare that with the position of the primitives position. Likewise to vex P of the primitive uses the centerpoint of that prim. For that I can use a distance vop. 

To get the integer steps I convert the float value to int and multiply the created scale attribute by that integer value. With a bind export I put the result into the outgoing scale attribute. At this point it's fair to say that you would not need to create the scale attribute. You could directly output the float to int into the bind export BUT only because we didn't need the information before - so to cover all grounds - if you need to base the operation on an existing attribute - this is the way to do it. 


This brings us to the polyextrude. Set the mode to Divide into Individual Elements, the distance to 1 and go to tab Local Control. Here you activate Distance Scale and type in your scale attribute. Now the Extrusion happens according to the position of  control point.

The counterpart to this approach in VEX is fairly simple and replaces the VOP node. (I dont count the atttribute create because you could scrap it for the VOP aswell)

And you can wrap the vop in one convenient line.

@scale = floor(distance(@P,point(1,"P",0)));

This still serves the same purpose. The distance function takes the prim position and compares that to the single point on the 2nd input. The floor function puts that to the lowest integer - e.g. 3.4 becomes 3.0

And by setting the attribute to that value it gets created at the same time.  

Let's hear your ideas!

Cheers

David

Quicktip#9 SOP/VOP vs VEX comparison

More Creators