Bifrost is a procedural framework to create simulated liquid effects quickly and easily.
It also allows you to use gravity forces, colliders, and accelerators to affect the simulation,
creating splashes, pressured flow, and other related effects.
In this movie, we'll use a primitive object as both a liquid emitter and accelerator
to create a jet of water from the deluge gun on this fire truck.
Make sure to set the current project to the provided scene folder,
then open the file "01-FireTruck_spray_start.mb".
This scene features a fire truck responding to a distress call
Its animated deluge gun is assigned to an animation layer (currently muted).
And a preliminary Bifrost setup has already been created.
There are a few important things to note.
First, although Maya’s default working units are such that 1 unit equals 1 centimeter,
this scene is actually built assuming a scale of 1 unit to 1 meter.
This is the default scale of Bifrost, which ignores Maya’s working units.
It also ensures that the bifrostLiquidContainer node’s default Gravity Magnitude value of 9.8
and the emitter’s Bifrost Liquid Density value of 1000 don't need to be changed.
Also note that our current Renderer is set to Viewport 2.0,
the only renderer where Bifrost effects are visible.
Finally, the scene already contains a hidden water_spray_emitter_GEO object,
located within the deluge gun, which is emitting our Bifrost liquid.
We also added a number of kill plane objects to contain the liquid within the area of focus.
For more information on how to set up a simulation like this from scratch,
refer to the "Creating a body of water simulation using Bifrost" tutorial series.
Before we play through the simulation, go to the Animation preferences
and make sure Playback speed is set to "Play every frame",
and Max Playback Speed is set to "Free".
This ensures solving accuracy by forcing Bifrost to evaluate each and every frame,
as opposed to skipping a few in order to maintain a given frame rate.
Also, we don't want Maya to constrain the playback speed at this point,
by imposing a specific fps.
Play the simulation.
Maya begins filling the scratch cache,
which you can track the progress of by selecting the bifrost1 node.
Green denotes the frames within the cache that have already been processed,
while yellow represents frames yet to be processed by Bifrost.
If you scrub the Time Slider, you'll notice that Maya doesn’t seem to generate any particles.
Select the bifrost1 node.
In the bifrostLiquidContainer tab, the Master Voxel Size attribute
controls the base resolution for the liquid simulation.
At this scale, Master Voxel Size is much too large to be emitted by such a small emitter.
Change its value to 0.005, then rewind and play the simulation again to regenerate the cache.
This time, the voxels are small enough that the emitter can properly emit them.
However, they currently pour straight through the deluge gun like it isn't even there.
Click the Stop button in the lower right corner
to stop the rest of the scratch cache from being evaluated.
We’ll set the gun as a collider object, so the particles don’t fall through it.
Select the bifrost1 node and Shift + select the gun geometry, then go to Bifrost > Add Collider.
Rewind and play the animation.
To get a better look at our liquid, turn on X Ray shading.
The particles now accumulate inside the chamber before spilling out the nozzle.
However, instead of simply trickling out of the gun,
we want the water to actually spray with enough speed to reach the apartment buildings.
To do that, we'll set up the emitter as an accelerator as well.
Select the bifrost1 and emitter nodes and go to Bifrost > Add Accelerator.
This connects the emitter to a new shape attribute notifier node,
and adds a new Acceleration section to the emitter's shape node.
First, increase the power of the spray by setting the Direction Magnitude attribute to 250.
Based on the current Direction vector, the particles spray straight up.
We would also prefer it sprays at the same angle as the deluge gun.
The gun is currently pointing in the negative X direction and rotated 60 degrees
(as per the rotation of the emitter).
Using trigonometry, we can determine that the Y direction is 1/tan(60).
So set it to -1, 0.577, 0.
Play the simulation again.
The gun now sprays the water much further, but it appears very choppy.
This is because the simulation generates new liquid too slowly relative to the particle flow.
In the bifrostLiquidContainer tab, under the Emission section,
reduce Transport Time Scale to 0.3.
This slows down the particle flow, allowing the liquid generation to keep up.
Next, notice how condensed the spray is.
In real life we would expect the water to disperse a little more.
To fix this, we're going to break some of our particles away from the main liquid body
into droplets.
In the Emission > Artistic Attributes section,
the Droplet Threshold attribute assigns each particle a droplet score
based on its distance to its surrounding particles.
If the score is higher than the threshold, that particle is converted to a droplet.
Since we want to increase the number of droplets in our simulation, lower this value to 0.5.
Play the simulation again.
We now get a nice dispersion of particles as they break away and ballistic calculations take over.
You'll also notice that your simulation evaluates faster than before.
This is because these droplets are calculated as ballistics,
which is significantly simpler compared to liquid simulation evaluations.
To round out the effect, assign the building object as a collider so the water splashes against it.
So far our simulation works so long as the deluge gun remains stationary.
However, as we mentioned earlier, that gun is animated.
Open the Channel Box / Display Layer Editor. Go to the Anim tab and unmute deluge_gun_LYR.
Starting at frame 72, the deluge gun rotates to point to another building.
To get the emitter to follow along, we'll need to constrain our emitter to it.
Return to a frame prior to frame 72, then select the deluge gun and emitter.
In the Animation menu set, go to Constrain > Parent.
Rewind and play the simulation again.
The emitter moves along with the deluge gun,
though the water begins spraying at a crooked angle.
Recall that we set our emitter’s acceleration direction
to a vector matching the emitter’s initial rotation
However, that vector is in world space, not relative to the accelerating object.
Thus, we actually need to alter this vector as the deluge gun rotates.
Select the emitter object and open the Node Editor.
The Node Editor provides a visual representation of the DAG relationship
between objects in your scene.
We need to create a relationship between the emitter’s rotation
and its Acceleration Direction vector.
To do this, we'll use a pointMatrixMult node.
This node allows us to multiply a point by a matrix.
Rename it "water_spray_redirect_MULT".
First, we'll feed the emitter shape node's "worldMatrix" attribute
into this node's "In Matrix" attribute.
The worldMatrix attribute represents the 4 x 4 transformation matrix
of the emitter's translation and rotation in World Space.
As the emitter moves along with the gun, this vector changes accordingly.
Next, we need to multiply this vector by the emitter’s spray direction attribute,
which is in its own local space.
Remember that our starting direction vector in world space was -1, 0.577, 0.
However, relative to the emitting cylinder object, it's simply spraying straight out the top.
Thus, we'll set In Point to 0, 1, 0.
We'll also need to turn on Vector Multiply to specify that we want a vector product
rather than the scalar product.
Now you can feed the output of this into the water_spray_emitter_GEOShape's
"Bifrost Accelerator Direction" attribute.
Rewind and play through the simulation again.
This time, the water shoots straight out of the nozzle no matter what direction it's facing.
The accelerator's Direction value updates in real- time to reflect this.
Notice that the values from frames 1 to 72
aren't quite the same as the original values (-1, 0.557, 0) that we started with.
This is okay, because our new values falls along the same vector as the old values we had,
so they're considered the same in the context of direction.
Make sure to set the side building object as a collider as well.
Next, we can render our scene using the mental ray renderer.
Except the render doesn't look anything like our spray.
Instead it just looks like a pitiful little stream.
The problem is that right now Maya is actually rendering the voxelized isosurface.
This is the default behavior when particles or voxels are being displayed in the workspace.
You can double-check this by going to the bifrostShape tab
and switching the simulation display from Particles to Voxels.
Where did the spray go?
Remember that we modified the Droplet Threshold to create more droplets
which resulted in the wider spray.
But by definition, droplets are particles that have broken out of the voxel surface,
so it makes sense that they aren't displayed when showing voxels.
To see what our liquid really looks like, we'll need to look at the Bifrost mesh.
Go to the Bifrost Meshing section and click Enable.
Hide the bifrost1 node to make sure the isosurface doesn't appear in the renderer,
then render the scene again.
Now the render looks much more like we’d expect.
You can adjust the attributes in the Bifrost Meshing section
to change the look of the liquid mesh.
For example, increasing the Droplet Reveal Factor and Resolution Factor,
or decreasing the Kernel Factor, results in a sharper looking liquid
that retains more detail at the expense of longer computation time.
Adjusting the Droplet Radius changes the size of the individual droplets that make up the liquid,
while adjusting the Surface Radius determines the manner in which Bifrost makes these droplets
stick together to form the surface of your liquid.
Increasing them both results in a blobbier looking stream,
while decreasing them makes the stream appear finer.
Feel free to experiment with these attributes to get the desired look.
Here, we’ll leave these settings at their defaults.
When performing modifications to your mesh,
you may notice some performance slowdown due to the high number of calculations.
A trick to mitigate this a bit is to temporarily clip out part of the mesh using a polygon primitive.
This way, Maya only needs to calculate a small part of the stream.
Create a polygon cube and position it at the end of the gun’s barrel.
Rename the cube “spray_clip_GEO”, then hide it.
Select it and bifrost1 node and open the Node Editor.
Connect the cube’s “outMesh” attribute to the bifrostShape1 node’s
“Meshing Clip Input Mesh” attribute.
Now Maya only generates the liquid mesh that falls within the cube’s boundaries.
This allows you to adjust the Bifrost Meshing properties much more quickly.
Note that to update the clipping mask you'll first need to break the connection
between the cube and bifrost1 node first.
Then transform the primitive before reconnecting them.
Once you're happy with the look of the simulation,
you can create a User Cache and Alembic Cache to speed up the scene
and strip out the Bifrost simulation altogether.
You can refer to the "Creating a body of water simulation using Bifrost – Part 3" tutorial
for help with this.