Krakatoa
RSS< Twitter< etc

Mapping By Velocity Length in Krakatoa MY

Last Edited on 2014/05/23 @ 12:10 PM PST

Introduction

In the previous tutorial we mentioned the ability of the Krakatoa Modifiers to copy any existing channel available in the particle stream to the Color channel in order to visualize the values in the viewport or in the renderer.

In this tutorial, we will bring this one step further by using the Velocity vector's Length either directly as Color, or indirectly as UVW Coordinates to produce a color that can be used in the final rendering and not just for data visualization purposes.

The Scene Setup

Let's use the exactly same scene as in the previous tutorial. We will simply remove all modifiers from the PRT Loader using the Krakatoa Modifiers Editor dialog, and start adding new ones.

Copying The Velocity As Grayscale Color

In the first step, we will convert the Velocity to a Grayscale value and use directly as the particle Color channel. 

  • In the Krakatoa Modifiers Editor, click the +Copy Channel button to add a new modifier.
  • In the new tab of the PRT Loader, select Velocity from the Source Selection list. 
  • Select Color from the Destination Selection list.
  • Check the Copy As Vector Lenght checkbox.

RESULT: The Length (also know as Vector Magnitude) of the Velocity vector will be calculated and the resulting positive Floating point value will be set in the X,Y and Z (think R,G and B) components of the Color channel. The viewport will show mostly white particles because the Velocity Length is largely greater than 1.0, and the viewport can only reliably display colors between 0.0 and 1.0. 

  • Click the +Scale Channel button in the Krakatoa Modifiers Editor.
  • Select Color from the Channel Selection list.
  • Enter 0.1 in the Channel Scale value field. 

RESULT: The Length of the Velocity vector copied into the Color channel will be scaled down 10 times (equivalent to dividing by 10.0) and the viewport will now show grayscale values that represent how fast each particle is moving.

The best Scale value depends on the maximum velocity found in the PRT sequence. You can play with the value until you find a suitable value. In this scene, the best scaling factor is around 0.07, so let's set it to that.

Mapping Velocity To A Ramp Gradient

In applications like RealFlow or Naiad, the Velocity of particles is typically represented as a color gradient where blue stands for slow and white stands for fast.

We can achieve the same effect in Maya by using the Velocity Length as UVW Coordinates in a Ramp texture. 

  • In both modifiers that we added in the previous steps, change Color to Mapping by typing into the Channel Name field.

Note that "Mapping" is a USER-DEFINED channel name. Krakatoa itself has a short list of pre-defined names used for its own rendering operations, including Color, Velocity, Normal, Density etc - see the Memory Channels panel in the Render Settings dialog for the full list. But you can create your own channels to store intermediate values or as in this case, define a new UVW channel. In other words, you can create ARBITRARY channels, and name them yourself. In the above case, you could use the name "MyMap" instead and the setup would still work!

  • Click the +Apply Texture button in the Krakatoa Modifiers Editor dialog. 
  • Enter Mapping in the UVW Name field.
  • Click the mapping button to the right of the Texture attribute and select Ramp from the list of 2D Textures.

RESULT: Since the default Ramp uses "V Ramp" as its Type, and both U and V of our custom Mapping channel are set to the same value, the Ramp displays correctly in the viewports with blue representing very fast motion and red being very slow, with green in between: 

We can now modify the Ramp gradient flags to use the typical colors familiar from other applications:

And here is the result in the viewports:

We can switch to display the Velocities as lines - the color of the particle will correspond to the length of the line. Shorter lines will be deep blue, long lines will be brighter blue to white:

We could add a Repopulate modifier to produce more particles from the sparse simulation data. Displaying the new particles in the viewport can take a few seconds, but gives us a better idea of the final render look:

Tweaking The Mapping

You can modify the Ramp texture as you want - add new flags, remove flags, change colors, change the Interpolation mode to produce Exponential gradients, and so on.

Here is the Interpolation set to Exponential Up and Down:

 

Simplifying The Setup

If you know that you will be performing texture mapping from the beginning, you could reduce the number of modifiers used on the PRT Loader by scaling the Mapping channel directly in the Ramp's place2dTexture node!

  • In the Krakatoa Modifiers Editor dialog, select the Scale Channel modifier and press the DELETE Modifier button - this will pass the original unscaled Velocity vector length as the V component of the Mapping channel, and you will get a lot of tiling in the viewport:

  • In the place2DTexture node, enter 0.07 in the V Tiling field.

RESULT: You will get the exactly same result as before, because the V Tiling parameter performs a Scaling of the V component of the Mapping!

Dealing With Tiling Issues

If you don't know the exact Scaling factor that would work for your particles and you want to avoid an obvious jump from white to deep blue if the Scaling value is not high enough, you can also check the Mirror V option. This way, velocities that produce a Length higher than 1.0 will gradually map to bright blue colors instead of producing a solid edge. 

  • Enter 0.1 as the V Scale - the value won't be enough to scale the velocities into the 0.0 to 1.0 range, and solid tiling borders will become obvious: 

  • Now check the Mirror V option in the place2dTexture node and values above 1.0 will slowly fade back to bright blue instead of jumping directly to dark blue:

In the above case, the colors will not represent the velocities correctly anymore, but at least will ensure there are no visible artefacts in the Ramp's gradient.