TrueGrit – Dirt simulation
(A SnotMonster Graphics Accessory)
Release Notes:
- 0.2 : Initial implementation of vertex color
algorithm.
- 0.11 : Fixed problem where saving JPG files over
existing files of a different size caused the size change to be ignored.
Introduction
TrueGrit is a dirt simulation plugin that stores its results in a normal bitmap that can be
mapped onto your object using its existing mapping coordinates. This approach to dirt generation
has some unique advantages and disadvantages:
Advantages:
- The grit map generated is a normal bitmap that uses
the object’s existing mapping coordinates. This means it is easy to use the
grit map in a game or other real-time 3D engine (this is the main reason
TrueGrit works this way, btw).
- It is not necessary to have a high face count to generate detailed grit.
TrueGrit gets detail from map density, not face density.
Disadvantages (TrueGrit is free – so I can own up to these :) ):
- Because TrueGrit uses the mapping coordinates of
your object to store its results, those mapping coordinates have to be set
up in such a way as to provide for good results. This can be a
time-consuming process. Please see the section on mapping below for a more
detailed description of these restrictions.
- TrueGrit is subject to the same precision problems as any other
texture map (aliasing, pixelation etc.).
As of version 0.2b, TrueGrit can use the vertex color channel of your
object to store grit information instead of using a bitmap. This approach has a
different set of advantages & disadvantages. On the plus side
You don't need to set up mapping coordinates for your object in order for the
grit generation to work, but you do require sufficient face density to give
detailed results. In addition, the object must be a collapsed editable mesh.
Mapping an Object for TrueGrit
(or, How I Stopped Worrying and Learned To Love UnwrapUVW)
(NB: This section only applies to the UV algorithm. If you are using the Vertex Color algorithm you
do not need to map your object)
In order for TrueGrit to generate grit correctly for an object.
- The object must have mapping coordinates.
- The UV values of all mapping coordinates must be in
the range 0 – 1
- The mapping coordinates of faces that share the same material ID must not overlap.
Why not overlap? Well, suppose face A and face B had the same mapping coordinates but were in
very different places in the mesh. They would very likely have different amounts of grit on them.
So when TrueGrit came to save the grit for the two faces into a bitmap it would have a problem since
both faces were using the same part of the map. One face’s grit mapping would have to overwrite
the other.
There are two main approaches to avoiding mapping overlap.
- Map the object in such a way that no overlap occurs. The Unwrap UVW modifier can be very
helpful in moving mapping coordinates about. If you haven’t used it before, do the
tutorial on mapping a low-poly space fighter in the Max 3 Tutorial Manual.
- Separate overlapping faces by giving them different material IDs. You can then generate a
different grit map for each material ID and use a multi-subobject material to display them all.
Generating the Grit
TrueGrit is a utility plugin. You’ll find it in the utility panel in Max. There are a number
of controls that control the how the grit is generated:
Algorithm: TrueGrit currently supports two methods of grit generation:
- UV : The grit results are saved into a bitmap that uses the object's mapping coordinates.
- Vertex Colors: The grit results are saved into the object's vertex color channel.
This method does not require the object to have mapping coordinates set up.
- Spatial : The Spatial algorithm is not implemented yet.
Map Size: This is where you enter the x and y
dimensions (in pixels) of the grit map you want to generate. Larger bitmaps will
require more calculation time. This parameter applies only to the UV Algorithm.
Distance: This setting controls how close nearby
faces need to be before they start causing grit to accumulate on the surface of
a face. TrueGrit works by assuming that grit forms in corners, indentations,
nooks and crannies of a mesh. The greater the distance value, the more grit
you’re going to get. A good way to think about this value is to imagine the
inside of a box. The inside edges and corners of this box are going to
accumulate grit (because they are harder to clean etc.). Think how far out from
the corner you would like that grit to extend and that’s your distance value.
Changing the distance value won’t affect the calculation speed in this version
of TrueGrit but may well do in future versions (with smaller distances leading
to shorter calculation times).
Ray Spread: In order to calculate the grit at a
point on a face, TrueGrit fires a number of rays out from that point in a
hemispherical pattern and sees if they hit any other faces within the distance
value specified. The Ray Spread settings control how many rays are fired. The
number of rays fired equals (1 + Vertical * Horizontal). Increasing these values
has a significant effect on rendering time. It seems that the point of
diminishing returns is reached fairly early (about 16 rays or so), and
increasing the number above this doesn’t make things look much better. Start
small (with Vertical = 1 and Horizontal = 8) and increase the values by small
amounts if you see banding or square looking regions of grit.
Map Channel: This value controls which of Max’s 100
mapping channels TrueGrit will use when calculating the grit map. Most of the
time this value will be 1. This parameter applies only to the UV Algorithm.
Selected Faces Only: Check this box if you want
TrueGrit to only calculate grit for the currently selected set of faces in the
mesh. For large meshes it can speed things up to only calculate grit for a small
part of the mesh until you are satisfied with the settings, and only then
calculate the grit for the whole mesh.
Noise: TrueGrit can optionally add a noise effect to
the calculated grit map. This parameter applies only to the UV Algorithm.
Filter By Material ID: You can use these settings to
have TrueGrit only calculate grit for those faces with a particular material
ID. This parameter applies only to the UV Algorithm.
Generate: Pressing this button begins the grit
generation progress. TrueGrit will display a progress bar at the bottom of the
screen. The important bits of the calculation are multithreaded, and should run
nearly twice as fast on a dual CPU machine (if anyone has a Quad CPU machine and
would like TrueGrit extended to use up to 4 CPUs, send me an email). If you
are using the UV algorithm, when the
calculation has finished TrueGrit will prompt you for a name and format to save
the grit map to. If you are using the Vertex Colors algorithm, TrueGrit automatically
updates the vertex colors in your object for you (though you may need to click on the
object to get Max to refresh its display properly).
Using the Grit Map
So now you’ve got this map. How to use it?
Here are a couple of ideas – I’m sure you’ll think of others.
- Overlay the grit map onto the existing texture of the
object in Photoshop or similar.
- Use the grit map as the mask slot in a Max Blend material.
Using the Vertex Colors
Here's what I usually do:
- Assign a Blend material to your object. Put the non-dirty material in the "Material 1" slot and
the dirty material in the "Material 2" slot.
- Click on the "Mask" slot and assign a new "Mask" map type.
- In the Mask map you've just added, add a noise map to the "Map" slot, and a Vertex Color map
to the "Mask" slot.
- Check the "Invert Map" box.
That gives you a basic noisy blend between the non-grit and grit materials based on the vertex
color channel of the object. You will probably need to fiddle with the settings of the various
materials to get exactly the result you desire.
Final Points
- The Vertex Colors algorithm of TrueGrit would be more flexible if it were implemented as a
modifier instead of a utility. I'll try and find the time to do this.
- So what's this "Spatial" algorithm, then? Well, its going to be a system of grit generation that
is indepedent of both mapping coordinates and face density, but will probably not be
exportable to a game engine.
- Also on the TODO list: inter-object grit! In other words, calculating the grit on collections of
objects at a time, instead of just one object.
I’m calling this release of TrueGrit a BETA because I consider it a work in progress.
Future directions will to a certain extent be driven by user feedback,
so don’t hesitate to email me at andrewr@mpx.com.au
(or andrewr@bde.com.au) with any ideas, problems, bugs etc.
If you want to discuss TrueGrit, then the 3rd Party Plugins forum of the
Discreet Support Web-board
(http://support.discreet.com/~max) is an excellent venue.
I read it most days.
For those of you with big meshes, take heart. I have
some optimizations in mind that should greatly improve calculation times.
There are other approaches to storing grit results
rather than using a UV texture map, such as vertex colors (which would require
sufficient face density for good results). I’m aware of the limitations of the
UV-based method in the case of difficult to map meshes and I’m curious just
how much of a burden people find this. I work in the games industry, where
precise texture mapping is required anyway, so this probably colours my views
on the issue.
For the non maths-averse, the algorithm TrueGrit uses is a variation on that described in the paper Visual Simulation of Dust Accumulation, by S.C Hsu and T. T. Wong. I used to have the URL of this
paper on the web but the link appears to have gone stale. You should be able
to find it in the SIGGRAPH archives if you look hard enough.
If you do anything cool with TrueGrit or any of my plugins I’d love to hear about it! Send me links to images and animations.