Tuesday, July 31, 2012

Preliminary result about Ghost SPH

I started re-writing my SPH simulator a few days ago, and the desired new feature is ghost SPH based on Hagit and Bridson's new paper: Ghost SPH for Animating Water
http://www.cs.ubc.ca/~rbridson/docs/schechter-siggraph2012-ghostsph.pdf

A main problem about SPH lies in the density gathering.

In real world, water is almost incompressible, which means at each sample point in the water, the density should be almost the same. However, in simulation, density for each particle may vary within a wide range. This would lead to conspicuous artifacts like y-stacking.

Though generally speaking the result still looks like water, the details could not satisfy me when I pay close attention to the details. After all it's the details that matters in getting distinguished.

To eliminate the problem, there're two important things to do: correct the density gathering and re-model the pressure calculation.

1. correct density gathering. This is the core idea of the ghost sph paper. By using another layer of ghost particles, we could eliminate the density deficiency for particles near the surface. Also the paper discussed about how to initialize the particles, which is rarely seen in other SPH paper and is exactly what I need. The technique used for initialize SPH particles is Poisson Disk Sampling, which could arrange all the particles with blue noise. The sampling technique is based on Bridson's another paper: Fast Poisson Disk Sampling in Arbitrary Dimensions
http://www.cs.ubc.ca/~rbridson/docs/bridson-siggraph07-poissondisk.pdf

2. re-model the method to calculate the pressure. Using Tait equation based on the WCSPH paper (whose performance could be improved by implementing the PCISPH). The Tait equation generate a pressure proportional to (rhow/rhow0)^7, so a correct density gathering is a prerequisite, or the pressure force would be too powerful and lead the simulator to an unstable stage.

Now I've pretty much finished the sampling part. The particle sampling is consist of 4 parts: surface sample, surface relaxation, volume sample, volume relaxation.

Here're two images of the result of applying particle sample to a simple spherical level set grid.




Friday, July 27, 2012

The new SPH simulator

Recently I've been working on re-writing my SPH simulator.

There're lots of problems in the previous version that drastically slow done the simulator. For simulating 125K particles, it takes around 3 mins to get a single frame with drawing triangle meshes.

The surface reconstruction part was not done by myself so I did not know the detail. However recently I found out why the previous version is so slow and rewrite the surface reconstruction part, including marching cube and openGL utilities. The result is a 6 time's improvement in performance.

Because of the glut library is pretty old, so I choose glfw library for this new version. I also modified the neighbor searching method to support multi-thread execution. For the surface reconstruction, anisotropic kernel is calculated for each particle to better describe the density distribution.

Here're some comparing images of a water-crown scene.
1. drawing elliptic particles only.
2. drawing triangle meshes with isotropic kernel. i.e. drawing spheres to present particles.

3. drawing triangle meshes with anisotropic kernel. i.e. drawing ellipsoids to present particles.

I've tried to implement WCSPH but I found out my initialization is problematic. Based on the fact that there's few paper or blog talking about initialization of SPH, I decide to implement the Bridson's Ghost SPH paper first. After finishing that paper, WCSPH could be finished with slight changes and so is the PCISPH.

These papers have been on my "to-do list" for a few weeks, but I was too tired after work everyday so the progress is slow. I'll keep updated.

Also, considering that I'm getting more and more familiar with openGL, I'm considering re-write my path tracer and try to add something new.

Tutorial: installing boost on Visual Studio 2010

Well because of work I got started to use the boost library. It's so handy that I want to install it on my own laptop. I followed a video to install the library, and here's my experience that I'm willing to share.

1. Download the latest boost library: http://www.boost.org/users/download/

2. Unzip the file to a certain folder, which would be used later as a path in the user configuration in Visual Studio 2010. Here I'll use "D:\boost_1_50_0\" for example.

3. A large part of the library is only header file, need not to be compiled. To get a full version(due to the "geek's nature"), we need to compile the library. 

Click "Start"->"All programs"->"Microsoft Visual Studio 2010"->"Visual Studio Tools"->"Visual Studio Command Prompt (2010)"

This command window has correct environment configuration for VS2010. Now go to the place where you unzip the boost library using "cd" command. Here the location is "D:\boost_1_50_0\", so the command is "cd D:\boost_1_50_0\".

4. Run command "bootstrap". Running this could give you a executable called "bjam", which is the building system for boost.

5. Run command:
bjam toolset=msvc-10.0 variant=debug,release threading=multi link=static 
The parameters setting may vary depending on user's own interest.

Notice that the compiling process may take more than 20 minutes. So take the time to do something else.

6. Now we've finished compiling the library, and it's time to turn to setting Visual Studio. Go to "C:\Users\%USERNAME\AppData\Local\Microsoft\MSBuild\v4.0"
Open the Microsoft.Cpp.Win32.user.props file and modify it.

Under the <IncludePath> tag add the root folder where you extract the boost library. Here is "D:\boost_1_50_0;"

Unver the <LibraryPath> tag do a similar thing, but with different path, under the folder "/stage/lib". Here is "D:\boost_1_50_0\stage\lib;"

In this way you don't have to configure your every project to support boost. As long as you're logging in as this certain user, the boost library would always be found without costing your time to set project property.


Try to some example code from boost document!
Create an empty win32 console project and add these lines of code to the main.cpp and see the result.
#include <boost/regex.hpp>
#include <iostream>
#include <string>

int main()
{
    std::string line;
    boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );

    while (std::cin)
    {
        std::getline(std::cin, line);
        boost::smatch matches;
        if (boost::regex_match(line, matches, pat))
            std::cout << matches[2] << std::endl;
    }
}

I followed this video tutorial: 
Big thanks to the author and hope everyone could benefit from that.