How to do that? 1. Load and image from file and use it as texture 2. Generate a texture (and/or a surface) § texture = 2D array of colors § surface = 2D array of altitudes
Noise Parameters • Amplitude A: power of noise effect A * noise(i, j) • Frequency fa, fb, fc: coarse vs fine detail A * noise(fa * i, fb * j) • Phase pa , pb , pc: location of noise peaks A * noise(i * fa + pa, j * fb + pb)
Create a texture using a noise function // calculate texture pixel by pixel texture (i, j)= colorMap( scale( PerlinNoise (i * 5, j * 5) // -2 to 2 ) ); // scale [-2,2] range to [0,1] float scale(float x) { return (x + 2) / 4; } // interpolates two colors Vec3f colorMap(float a) { Vec3f white = Vec3f(1, 1, 1); Vec3f color = Vec3f(1, 0, 0); return ((1 - a) * white + a * color); }
Multi-scale Function Adding Noise over diverse frequencies and amplitudes )) * , * , * ( * ) , , ( 1 r scale t scale s scale noise amplitude r t s f i i i bands i i å = - =
Sum of Absolute Values Adding Noise over absolute values is Good for fire )) , , ( ( ) , , ( 1 r scale t scale s scale noise amplitude r t s f i i i bands i i å = - =
Marble Example § MarbleMap is from black to white § Scale scales [min, max] to [0,1] § u and v are in range [0,1] § Does not look that great, maybe a more complex color ramp is needed )) ) 5 . 11 , * 2 * 5 , * 2 * 5 ( * 2 * 6 * 20 sin ( ( ) , ( 4 1 ÷ ø ö ç è æ + = å = - v u PNoise u Scale MarbleMap v u Texture i i i i
Example Marble //scale scales from [min, max] to [0,1]; //u and v are in the range [0, 1] double perlinMarble(float x, float y) { double total = 0; double scale = 0.005; double p = 2.0; //0.1; //persistence double n = 4.0; // number of octaves double frequency, amplitude; for (int i = 0; i<n; i++) { frequency = pow(2, (double)i); amplitude = pow(p, (double)-i) * 2; total = total + noise(scale*frequency* x, scale*frequency* y, 11.5) * amplitude; } return sin( 2 * (x*scale) + total ); }
Height Field - Multiscale § Multi-scale Noise § Multiple bands are added together § Start with the highest amplitude and lowest frequency § Amplitude decreases and frequency increases for subsequent bands
• Low Quality • Bad parameter settings • Medium Quality • Better parameter settings • Note the two valleys from the sine function Height Field - Marble