SDF example 1: sampling and displacing the sdf using the gradient vector inside a solver (part 2/3)

Опубликовано: 24 Октябрь 2024
на канале: Peter Claes
13,431
290

PART 1: Understanding how an sdf works, sampling the sdf value and the gradient of the sdf.
   • Understanding the SDF - Signed Distan...  

PART 2: Example 1 - sampling and displacing the sdf using the gradient of the sdf. (this video)

PART 3: Example 2 - snapping particles to the surface of an object by using and sdf as a data acceleration structure.
   • SDF example 2: snapping particles to ...  

Add me on Instagram: pclaesvfx

Hipfile: http://bit.ly/sdf_hipfile

OVERVIEW:
Displacing the sdf using the gradient of the sdf and a noise mask. Initially we perform a simple displacement inwards or outwards, then later we perform that displacement inside of a sopsolver as part of a feedback system so the displacement happens over and over as the time increases. As part of the feedback sdf displacement we also make sure to take care of the active voxel region.

FIRST:
When turning objects into a vdb it is a good idea to give the object enough polygonal detail, otherwise the faceting of the polygons may get captured into the sdf. We can also specify the exterior and interior band in 'world space' units instead of expressed as voxels. This will come in handy as we are setting up the displacement amount later.

SECOND:
We can build the sdf displacement using a volume vop. We are going to sample the first primitive of the first input which represents the incoming sdf using a 'volume sample' vop. We are going to manipulate the sample position.

THIRD:
The default name for the sdf as it is created by the vdbfrompolygon is called 'surface'. The volumevop is looking for a field named 'density'. So to resolve this mismatch in the volume bindings settings on the volume vop, we can turn off 'Autobind by Name' and turn on 'Bind Each to Density'. This will force the 'surface' field to be associated to 'density' so our computations will correctly happen.

FOURTH:
Inside of the volumevop we want to manipulate the sample position by adding a bit of (vector) noise to the sample position. A high amount of displacement can cause holes to appear in the surface. These holes are caused by displacement that is trying to sample values outside of the active bands.

FIFTH:
We can fix the holes by increasing the exterior/interior bands. A convertvdb sop can be appended to the volumevop to show a polygonal representation of the sdf. Manipulating the isovalue will extract a different isocontour out of the sdf.

SIXTH:
If we only want to displace outwards or inwards, we can displace 'along the normal of the volume' - which is represented by the gradient vector of the sdf. Inside of the volumevop we can compute the gradient vector using a 'volume gradient' vop, next we normalize the gradient to get a clean direction vector. This vector points from a low value to a high value, but because we are performing a lookup, we will need to flip/negate this direction vector.

SEVENTH:
The normalized and negated gradient direction vector will then be multiplied by the absolute value of a scalar noise to vary the amount of displacement across the surface. A displacement multiplier parameter is also added to control the overall maximum displacement.

EIGHT:
If we displace too much we will get holes in the surface, so we can link the displacement multiplier from the volume vop to the 'world space exterior bands' on the vdbfrompolygons sop.

NINTH:
We can duplicate the volumevop, append it and change the frequency of the noise. This way we have a first low-frequency-high-amplitude displacement followed by a high-frequency-low-amplitude displacement operation.

TENTH:
Lowering the voxelsize will result in high detail, but it will take longer to compute. This high detail can be baked down into a normal map that can be applied as a texture on a low polygon representation of the object, using the simple baker tool as part of the Sidefx Labs tools.

ELEVENTH:
We can displace inwards using a negative displacement value and create erosion fx for things like acidity or ice melting.

TWELFTH:
Next we are going to run the sdf displacement inside of a sopsolver to create a volume that grows over time as part of a feedback system. It could also shrink over time if we specify a negative displacement value.

THIRTEENTH:
In order for the expansion to happen properly, the active region needs to expand correctly. We are going to use the vdbactivate sop in 'Reference' mode, making use of 'activate using vdbs'. This will activate the same region as is active in the second input of the vdbactivate sop. To figure out the active region, we temporarily convert the vdb to polygons, and then back to sdf.

FOURTEENTH:
The vdbrenormalize sdf will try to correct the sdf values after the displacement has taken place.

FIFTEENTH:
We can mask the growth by using another sdf of a different object to allow the growth only inside of the other sdf. Only allow growth where the other sdf values are less than zero.

For business or one-on-one visual effects consulting inquiries, you can reach me at [email protected]