Oddlabs Forum

It is currently Thu May 23, 2013 11:53 am

All times are UTC + 1 hour




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Perturbation filter for non-book-owners?
PostPosted: Thu Jan 18, 2007 11:16 pm 
Offline

Joined: Thu Jan 18, 2007 11:05 pm
Posts: 3
Location: Braunschweig / Germany
Hi there,
I've been reading your publication about procedural terrain generation for days now and went very inspired by it. Due to educational issues, I used to re-construct all the topics inside your document and got everything working - except the perturbation filter you applied. Stressing google ended up with nothing and the book you were refering to ("Texturing and Modeling: A Procedural Approach") in foot-note no. 6 is not in stores anymore. Therefore I'm asking if there is a way to get some more information about this perturbation filter? I'm looking forward to your replies! :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 19, 2007 10:59 am 
Offline
User avatar

Joined: Fri Sep 26, 2003 6:34 pm
Posts: 71
The book doesn't really offer much of an explanation either, but the idea of perturbation is to use a continuous function to displace the pixels of an image somehow.

In pseudo code, this could look like:

Code:
loop x {
    loop y {
        offset_x = someFunction1(x, y)
        offset_y = someFunction2(x, y)
        value = getPixelInterpolated(original_image, x + offset_x, y + offset_y)
        putPixel(new_image, x, y, value)
   }
}


As the pixel offset values will be floating point numbers, it's very important to interpolate between the pixel values of the original image - simple linear interpolation will usually do.

Here is how it was done in TT:

Code:
public final Channel perturbation(Channel perturb, float magnitude) {
    Channel channel = new Channel(width, height);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            float p = magnitude*(perturb.getPixel(x, y) - 0.5f);
            float x_coord = x + width*p;
            int x_coord_lo = (int)x_coord;
            int x_coord_hi = x_coord_lo + 1;
            float x_frac = x_coord - x_coord_lo;
            float y_coord = y + height*p;
            int y_coord_lo = (int)y_coord;
            int y_coord_hi = y_coord_lo + 1;
            float y_frac = y_coord - y_coord_lo;
            float val1 = Tools.interpolateLinear(getPixelWrap(x_coord_lo, y_coord_lo), getPixelWrap(x_coord_hi, y_coord_lo), x_frac);
            float val2 = Tools.interpolateLinear(getPixelWrap(x_coord_lo, y_coord_hi), getPixelWrap(x_coord_hi, y_coord_hi), x_frac);
            channel.putPixel(x, y, Tools.interpolateLinear(val1, val2, y_frac));
        }
    }
    pixels = channel.getPixels();
    return this;
}


A Channel object is basically just a greyscale image using float values between 0 and 1. Instead of a function, another greyscale image ("perturb") is used as an offset map, giving both x and y coordinates the same offset for each pixel (this is a simplified way to do it, but works well enough for terrains).

Someday I'm going to release all the "procedural stuff" code as open source, but right now I simply don't have the time to clean it up and document it.

Hope this gave you a few useful hints!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 19, 2007 11:27 am 
Offline

Joined: Thu Jan 18, 2007 11:05 pm
Posts: 3
Location: Braunschweig / Germany
Thanks! I didn't expect such a good answer so soon :) The basic idea behind seems to be the same, expect I was using perlin noise maps for random offsets. My results we're not as that good, but I'm on it.

Here is how it actually looks like:

Image

I gonna post some more results when I have the time to get this thingy done. Thanks again!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 19, 2007 3:12 pm 
Offline

Joined: Thu Jan 18, 2007 11:05 pm
Posts: 3
Location: Braunschweig / Germany
I was wondering what the method (?) getPixelWrap() does. I guess it does not have to do with modulating the coordinate with the textures maxima, does it?

EDIT: After a bit of guessing and some coffee, I've realized, that logically the getPixelWrap() method will return the color value (0.0f - 1.0f) of the member channel "pixels" with wrapping the xy-coordinates. I hope I'm right :?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 20, 2009 8:41 pm 
Offline

Joined: Fri Nov 20, 2009 8:36 pm
Posts: 1
Location: Nili Fossae, Mars
What does the image look like if omitting the linear interpolation steps? I'm wondering if the performance gains would justify the change in appearance of the height-map image overall.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group