Showing posts with label Computer Graphics. Show all posts
Showing posts with label Computer Graphics. Show all posts

Saturday, June 19, 2010

Water shader

    Up until a month ago I had been from time to time wondering how the great effects are done, especially the water. Thanks to the indie game group I joined, I finally had a reason to implement that myself. So the code was based on Riemer's XNA Tutorial, which has lots of resources regrading shader programming. The initial goal is to generate ripples on the water surface where the ship passes.



    However the organizer decided to have our prototype redone in an open source XNA game engine, for a more reliable environment of content creation, so the development is paused temporarily (i.e. summer vacation :p).

Friday, June 18, 2010

Wide-angle image straightening

This is by far the trickiest energy-based optimization I have ever implemented. The idea is quite similar to the spectral conformal parameterization algorithm I have used for the model viewer, however, it requires more energy terms and hence more tune-ups to work properly. The main purpose of the paper is to let the user identify straight lines that are bent by the wide-angle photography, especially fish-eye lens, to preserve certain content. It makes some good use of stereographic projection to help converge to the final result, and especially the smoothing terms that prevent distortion. Let's look at a few examples:

Original images:

Straightened images(user specified lines in purple):


   As you could probably tell either I didn't pick the right pictures or I had not idea which parts to straighten, so this method works best if the user knows what he is doing.

Seamless blending


   When it comes to blending of 2 images, the simplest way is to construct a Laplacian pyramid, and then choose an alpha ratio to sum the images at all the levels. But the resulting image would have color disparity and unnatural boundaries. However by introducing the Laplace operator and a linear system to solve for the desired image, the artifacts are much reduced.

Image to paste to:


Image to cut from:



After computation:

Mor results:

Tuesday, June 8, 2010

Simple model viewer with automatic UV unwrapping

   Years ago while I was struggling with Maya, having to do UV mapping myself, which I hated to, I was thinking perhaps there would be a less dumb approach to tackling this problem. Then years later when I took a geometric modeling course at NYU, one of the assigned readings happened to be addressing this specific topic, namely, 3D/2D parametrization. Simply put, if we have a 3D mesh, we want to find a way to explain where a particular vertex's 2D position is(texturing) by only looking at the 3D data itself. 
Enough talk, let's look at a simple case:

And its corresponding 2D parametrization(UV mapping), which is done quite well:

The goal here is to preserve the shapes of the triangles as much as possible(regardless of the sizes). 
So you could expect a situation when it doesn't work quite as well:


And its UV map, which doesn't look quite good:


Now you can get a sense that although the shapes are well-preserved, the sizes could go crazy. So it's really a problem of striking the balance between the size and shape of each triangle, and the subjective view of the artists who have to paint it. I would say that if the future hardware supports per-polygon texturing, people won't need to find a good explanation for 3D to 2D anymore(there will never be one).