# Pragmatic VEX

Pragmatic VEX series is aimed to increase the technical capacity of the artists and TDs which will allow them to tackle more complex production shots with complete control and ease by acquiring a deeper technical understanding of how things work in Houdini at the lowest level with a strong applied focus on high-end feature film visual effects production.

##### 10 Tutorials 0:00:00

### Tutorials

**Pragmatic VEX 1 | Gradient Ascent & Descent | Planar Geometry**

Gradient descent is an optimization algorithm used to minimize some function by iteratively moving in the direction of steepest descent as defined by the negative of the gradient.

**Pragmatic VEX 1 | Gradient Ascent & Descent | 3D Geometry**

We have implemented gradient ascent and descent on planar geometry, much like a terrain where we used the gradient of the height.
For an arbitrary geometry, what can we use as the cost attribute? One thing we can use is depth.

**Pragmatic VEX 1 | Gradient Ascent & Descent | Contour Lines**

Now that we know about gradients, there is another concept that's related to them that can be acquired quite easily, and that concept is contour lines.
A contour line (also isoline) of a function of two variables is a curve along which the function has a constant value, so that the curve joins points of equal value. There are very interesting relationships between the gradients and the contour lines.

**Pragmatic VEX 1 | Gradient Ascent, Descent & Contour Lines | Heightfields**

We have already seen how to apply gradient ascent, descent and contour lines to heightfield like planar geometry. The same concept can be applied to heightfields.
Because heightfields are volumes, getting the gradient is very easy by using the volumegradient function. The normal of a heightfield is (0, 1, 0) if the heightfield is an XZ volume, meaning facing up. Getting the cross product of both of these vectors will give you the contour lines.

**Pragmatic VEX 1 | Implementing Catmull-Clark Subdivision | Introduction & Rules**

Subdivision surfaces are piecewise parametric surfaces defined over meshes of arbitrary topology.
It's an algorithm that maps from a surface to another more refined surface, where the surface is described as a set of points and a set of polygons with vertices at those points. The resulting surface will always consist of a mesh of quadrilaterals.

**Pragmatic VEX 1 | Limit Surface Sampling | Introduction & OpenSubdiv Patches**

To generate interpolating surfaces for other subdivision schemes we need a method of determining the position and the normal at a set of points on the limit surface. Because the surface is the result of repeated application of a subdivision step, we can analyze the behavior of a small neighborhood of points as they converge to the limit surface in order to determine the surface properties at the point of convergence.

**Pragmatic VEX 1 | Limit Surface Sampling | Moving Points to the Subdivision Limit Surface**

There is a very practical use of the limit surface to figure out where a point is on the subdivision limit surface.
Imagine a character head like the one we were using, and you add a lot of detail to it, just like what we did before using adaptive subdivision.
That sounds all good in action, but what we are missing is the future projection of the same geometry, by additional subdivision, either as a post operation before exporting out the geometry, or as a render time operation.
In any case, this will result in the areas where there is added detail, to be flatter than before, even though it's not the case without adaptive subdivision.
Because if you recall, we were using Catmull-Clark subdivision algorithm, which will keep the original geometry nice and smooth.
But in other cases where you might have additional detail using algorithms such as Bricker, it might result in the areas where there is added detail to be flatter than before.
But we don't necessarily want this. What we want is to create detail without disturbing the future subdivided shape of the geometry.
So how can we do this?
Evaluating attributes at the subdivision limit surface gives us a way out.

**Pragmatic VEX 1 | Limit Surface Sampling | Scattering & Generating Points on the Subdivision Limit Surface**

If you have access to the subdivision limit surface by patch IDs and the patch UVs, then surely you can scatter points on the limit subdivision limit surface just like you scatter points on a polygonal surface.
And this is exactly what we are gonna do in this chapter.

**Pragmatic VEX 1 | Limit Surface Sampling | Creating Isolines on the Subdivision Limit Surface**

There is a useful modeling concept that's available in many 3d apps including Houdini where you see the original geometry projected onto the subdivision limit surface that allows you to see the flow of the geometry without cluttering the view with the newly added geometric detail.
And that's what we will create in this lesson.

**Pragmatic VEX 1 | Limit Surface Sampling | Pre-Generating a Point Cloud on the Subdivision Limit Surface**

When we are talking about creating a lot of points, we can not avoid pre-generating them for maximum performance. It might not always be applicable but when it is, the performance gains can be quite significant.

Category: VEX