Spherical waves

Here’s the note that i would like to share with you to make spherical waves by Houdini using vex to create a sphere from a grid and project wavy lines on to the surface.

Concept:

Make some wavy lines on a 2D Plane 🠒 Project them onto a Sphere (which is made from the 2D Plance) 🠒 Create Stripes based on the generated waves.

Make waves

  • To generate some 2d waves, we start by create a grid (in this example, i set up the grid orientation as ZX plane and connectivity as Columns).
  • Next, we keep just the first Column by Delete SOP.
  • Apply Resample Node with Maximum Segments of 13 (so we have 14 points on the line).
  • Wrangle 01 – create waves by transform the position of P.x
float overall_speed = ch("overall_speed");
float leading_wave_speed = ch("leading_wave_speed");
@P.x += @Time * overall_speed;
if (@ptnum % 3 == 2)
{
    @P.x += @Time * leading_wave_speed;
}
@P.x = clamp(@P.x,-5.0,5.0);
  • The wave is now formed but it’s sharp. Therefore, we smooth it by convert the line to Nurb.
  • Use Trail SOP to offset-clone the waves we’ve just made.
  • We project the waves on to 2D grid by using vex function intersect
vector project_dir = chv("project_dir");
vector project_points;
vector uvw;
int primid = intersect(1, @P, project_dir, project_points, uvw);

if (primid >= 0)
{
    @P = project_points;
    @N = prim(1, "N", primid);
}

v@project_prim = primid;
v@project_uv = uvw;
  • Now we convert the flat 2D Grid to sphere by writing vex code as follow:
vector relbox = relbbox(0,v@P);
float u = relbox.z;
float v = relbox.x;
float rad = ch("radius");
u *= (2*$PI);
v *= $PI;
float x = rad * sin(v) * cos(u);
float y = rad * sin(v) * sin(u);
float z = rad * cos(v);
v@P = set(x,y,z);
  • Let’s put the 2D waves into first input of the Wrangle and the Sphere into the second and project the waves into the spherical geometry:
v@P = primuv(1, "P", i@project_prim, v@project_uv);

[vex] turn grid to sphere

grid [0] – sphere [1]

apply uv for grid while sphere should be primitive or mesh (doesn’t work with polygon option)

use swizzle to re-arrange the relative bouncing box of the grid from XYZ to XZY.

use primuv to interpolate position of sphere based on attribute “P” and apply to the grid

vector toXZY = swizzle(relbbox(0,v@P),0,2,1);
vector prim_uv = primuv(1,”P”,0, toXZY);
v@P = prim_uv;

[vex] Sobol sequence

We already turn Halton sequence into vex. How about Sobol sequence? First thing first, what is Sobol sequence?

Sobol sequences are an example of quasi-random low-discrepancy sequences. They were first introduced by the Russian mathematician Ilya M. Sobol in 1967.

Ilya M. Sobol (image from Wikipedia)

In numerical analysis, the quasi-random method is a method for numerical integration and solving some other problems using low-discrepancy sequences. Another name of quasi-random is Quasi-Monte Carlo (QMC) that we usually see in rendering adaptive sampling method.

If you want to know more, there’s a detail explanation about these sequences at this link: https://math.stackexchange.com/questions/888490/understanding-sobol-sequences

How to make Sobol in vex?

It’s great to know we don’t need to code it out. It’s already there thanks to SideFX guys. We have a function called random_sobol (yeah! awesome).

random_sobol function offers a lot of ways for input and output (float, vector, vector4). For now, I go with a simple vector to scatter created points.

Same as the way we did with Halton Sequence, create an Attribule Wrangle and do the code like this:

vector zero = {0,0,0};
vector pos;
vector randS;
for (int i = 0; i < chi(“totalnum”); i++){
randS = random_sobol(zero+i,1);
pos = set(randS.x *
2,randS.y,1e-07i);
addpoint(0,pos);
}

And that’s it! For each point we create, the wrangle will push it in Sobol sequence method.

snapshot of sobol sequence by vex

[vex] Halton Sequence

Today i saw a post on Houdini Artist Group asking about halton sequence in vex. So I think it’s good to give it a try since wikipedia has good information about the algorithm.

What is Halton Sequence?

A Halton sequence is a sequence of points within a unit n-cube which have low discrepancy (that is, they appear to be randomish but cover the domain uniformly), while being deterministic, fast to compute, and easy to understand and implement. They generalize the 1-dimensional Van der Corput sequences.

The Halton sequence is constructed according to a deterministic method that uses coprime numbers as its bases. As a simple example, let’s take one dimension of the Halton sequence to be based on 2 and the other on 3. To generate the sequence for 2, we start by dividing the interval (0,1) in half, then in fourths, eighths, etc., which generates ​12, ​14, ​34, ​18, ​58, ​38, ​78, ​116, ​916,…

Halton Sequence pseudocode

Halton Sequence in Vex

Alright! Above is some knowledge about Halton Sequence from Wikipedia. It’s quite complicated to me honestly. But we have pseudocode and our task is turning it into vex, see how it looks in Houdini.

  • Create an attribute wrangle and set it run in detail mode.
  • Write the vex code like the image below
  • Randomize the color (Cd)
  • Copy a circle to the points created by Halton Sequence wrangle.
halton sequence vex code
halton sequence node network