Monday, June 4, 2012

Navier-Stokes Equation

Here is a summarized note I took after reading some material relevant to fluid effect.



This is the compact version of Navier-Stokes Equation excerpted from Jos Stam's paper. For simulation in Computer Graphics, physical accuracy isn't the primary but the appearance and performance is. In order to get a faster simulation and realistic at the same time, here it assumes constant density, which means the fluid is incompressible. Basically, fluid effect in CG is mostly based on this assumption.

The first equation is the condition of incompressibility. With constant density, the net flow in and out of a region should sum to zero, which means the divergence of velocity should be zero, no sinks or sources.

The second equation is based on Newton's second law F=ma. Before going further, I spent some time trying to understand 2 different descriptions for fluid mechanics, Eulerian and Lagrangian respectively. I recommend the following video on YouTube, which does a great job on explaining these 2 ideas. It also provides a clear demonstration about how to deduce material derivative, which is quite important to help understand the second equation here.

http://www.youtube.com/watch?v=mdN8OOkx2ko&feature=related

It's obvious to see that the left hand side of the assignment, combining with the first term on the right hand side is the material derivative. It says that the change of a point moving within a velocity field is the sum of the change at the fixed position and the one due to the movement.  The first term on the right hand side is what we call "Advection" (imaging if we drip a pigment drop into a moving liquid, how the pigment will move within it).
OK. Back to F=ma. 


Here we represent the mass as density since unit size is used; then expand the material derivative to get the following:


Well... divide each side by density, we get equation 2 :)
It's apparent that the sum of (F)orces corresponds to the rest 3 terms in equation 2:  pressure, viscosity and other external forces.

Pressure is used for enforcing incompressibility. Since the gradient points to the greatest rate of increase and fluid should flow from high pressure to low, negative sign is used for reversing.
Viscosity is used for simulating viscous fluid. Laplace operator is used here for getting smoothing result. External forces are something like gravity, buoyancy, etc.

So lots of research are around solving this equation, leading to various algorithms, such as SPH (Smoothed Particle Hydrodynamics), PIC/FLIP (Particles in Cell / Fluid Implicit Particle). It's kind of complicated and better has separate articles for these.


Monday, May 21, 2012

SIGGRAPH 2012 Technical Papers Preview

SIGGRAPH just uploaded the Technical Papers Preview Trailer for 2012. Fluid effect seems the primary topic this year, with totally 8 related papers accepted.

All technical papers:



Wednesday, May 9, 2012

Thursday, April 26, 2012

[RenderMan] Ri Filters

The following is a snippet of code I wrote to test with Ri Filters. The goal is to simply replace any polygonal geometry with RiSphere, then replace any RiSphere with RiCone before the final RIB being passed to the renderer.

First filter plugin:
RifPlugin *RifPluginManufacture(int argc, char **argv)
{  
    return new myRifPlugin();
}
myRifPlugin::myRifPlugin()
{
    myRifFilter.PointsGeneralPolygonsV = pointsGeneralPolygons_to_RiSphere;
    myRifFilter.Filtering = RifFilter::k_Continue;
}
RifFilter &myRifPlugin::GetFilter()
{  
    return myRifFilter;
}
The second filter plugin is almost like the first one, except the registered callback needs to be changed to "myRifFilter.SphereV = riSphere_to_RiCone". With riSphere_to_RiCone defined as follow:
RtVoid myRifPlugin2::riSphere_to_RiCone(RtFloat radius, RtFloat zmin, 
      RtFloat zmax, RtFloat tmax, RtInt, RtToken[], RtPointer[])
{
    RiCone(0.5, 0.5, 360, RI_NULL);
}
Now it's about to render! If rendering with RMS (RenderMan Studio), it's better to check the Full Paths box in the Render Settings. Besides, set all the necessary Ri Filters (just new 2 Rif in this case ) and provide the paths toward 2 Plugins. Within command prompt,
render -r rman xxx.ma [ render the image with RMS]
render -r rib xxx.ma [export the rib after replacing]

If using RPS (RenderMan Pro Server),
prman -rif myRifPlugin -rif myRifPlugin2 xxx.rib [ render the image with PRMan]
catrib -o filtered.rib -rif myRifPlugin -rif myRifPlugin2 xxx.rib [export the rib after replacing]
Right, if using RPS, you need to generate rib first for filter processing. RMS accepts .ma for filtering but RPS only accepts .rib.

If everything runs correctly, all the polygonal geometries (lets say if we create 3 cubes in Maya) should be rendered as 3 cones in the final image. Cheers!!

Friday, April 13, 2012

The Walking Dead S1&S2: Behind the Scene

The Walking Dead S2 just ended. It's one of my favorite US TV series. Initially I thought it's another version of "Dawn of the Dead" or "Resident Evil", another cliche or something. I was wrong. It completely held my attention from the very first episode. Well...of course it couldn't avoid having some cliche material from those plot we've been familiar with. It still have lots of fresh stuff that the preceding didn't explore that much. The story is more on the humanity side. The visual effects, compositing, and zombie makeup are best of all. AND it's also the first zombie-related TV series. Here embedded 2 Vimeo videos from Stargate Studios which handled the visual effects of it. They really did an amazing job!!




The following link are 2 articles from fxguide, giving a quick look over what's going on behind the scene. Worthing reading!! 
http://www.fxguide.com/featured/stargate_studios_walking_the_dead/
http://www.fxguide.com/featured/the-walking-dead-season-2-walk-harder/