Academic Tutorials

English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting

Graphics Introduction
Graphics Printmaking
Graphics Photography
Graphics for Web
Computer graphics
Computer graphics II
Graphics C++, SDL
Graphics QuickCG
Graphics Light and Color
Graphics Color Model
Graphics Image
Graphics 2D Drawing
Graphics Flood Fill
Graphics Clipping
Graphics Fractals
Graphics Sierpinski
Graphics Julia
Graphics Fire Effect
Graphics Tunnel Effect
graphics Raycasting
Graphics Raycaster
Graphics Floor & Ceiling
Graphics Sprites
Graphics Filtering
Graphics Fourier Trans
Graphics FT on Images
Graphics DC Component
Graphics Texture Gen..
Graphics Random Noise
Graphics Clouds

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
Apple Script
PL/SQL Tutorial
SQL Server
.NET (dotnet)
.Net Mobile
C# : C Sharp
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Assembly Language
Forth Programming
Lisp Programming
Data Warehousing
CGI Programming
Emacs Tutorial
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Operating System
Software Testing
SAP Module
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Financial Accounting
Managerial Accounting
Network Sites

Texture Generation Using Random Noise

Previoushome Next

Texture Generation using Random Noise



In nature, everything has a random look, while mathematical formulas typically don't generate random looking results, unless you use them well. Random noise, such as Perlin noise invented by Ken Perlin, uses random numbers to generate natural looking textures.

Smooth Noise

As source for the random noise we need an array of random values, called noise[x][y]. Since our interest is generating 2D textures, a 2D array is used. The function generateNoise will fill the array with noise, and the main function is programmed to show this noise array on the screen. The noise itself is generated with the rand() function from the <cstdlib> header file, this function returns a random integer value between 0 and 32768 (as defined in the header file). It's normalized to a random real number between 0 and 1 by dividing it through 32768.0 (make sure to use floating point division).

#define noiseWidth 128
#define noiseHeight 128

double noise[noiseWidth][noiseHeight]; //the noise array

void generateNoise();

int main(int argc, char *argv[])
    screen(noiseWidth, noiseHeight, 0, "Random Noise");
    ColorRGB color;
    for(int x = 0; x < w; x++)
    for(int y = 0; y < h; y++)
        color.r = color.g = color.b = Uint8(256 * noise[x][y]);
        pset(x, y, color);
    return 0;

void generateNoise()
    for (int x = 0; x < noiseWidth; x++)
    for (int y = 0; y < noiseHeight; y++)
        noise[x][y] = (rand() % 32768) / 32768.0;

Here's the noise it generates:

This noise doesn't look very natural however, especially if you zoom in. Zoom in by dividing the x and y used to call the noise array through 8, in the pixel loop of the main function. You get something blocky:

		color.r = color.g = color.b = Uint8(256 * noise[x / 8][y / 8]);
        pset(x, y, color);

When zooming in, we want something smoother. For that, linear interpolation can be used. Currently the noise is an array and it's got only a discrete set of integer indices pointing to it's contents. By using bilinear interpolation on the fractional part, you can make it smoother. For that, a new function, smoothNoise, is introduced:

double smoothNoise(double x, double y)
   //get fractional part of x and y
   double fractX = x - int(x);
   double fractY = y - int(y);
   //wrap around
   int x1 = (int(x) + noiseWidth) % noiseWidth;
   int y1 = (int(y) + noiseHeight) % noiseHeight;
   //neighbor values
   int x2 = (x1 + noiseWidth - 1) % noiseWidth;
   int y2 = (y1 + noiseHeight - 1) % noiseHeight;

   //smooth the noise with bilinear interpolation
   double value = 0.0;
   value += fractX       * fractY       * noise[x1][y1];
   value += fractX       * (1 - fractY) * noise[x1][y2];
   value += (1 - fractX) * fractY       * noise[x2][y1];
   value += (1 - fractX) * (1 - fractY) * noise[x2][y2];

   return value;

The returned value is the weighed average of 4 neighboring pixels of the array. In the main function, now use this instead of directly calling the noise array, and use real numbers for the division:

		color.r = color.g = color.b = Uint8(256 * smoothNoise(x / 8.0, y / 8.0));
        pset(x, y, color);

This is again the result zoomed in 8 times, but now with the bilinear interpolation. If you don't zoom in you won't be able to see the interpolation:

This is quite useful for random noise, the smoothing method could be better maybe, bilinear interpolation is often used by 3D cards for smoothing textures in games as a cheap and fast technique.

Let's call this image a "noise texture".


Turbulence is what creates natural looking features out of smoothed noise. The trick is to add multiple noise textures of different zooming scales together. An example of how this represents nature can be found in a mountain range: there are very large features (the main mountains), they are very deeply zoomed in noise.

Then added to the mountains are smaller features: multiple tops, variations in the slope, ...

Then, at an even smaller scale, there are rocks on the mountains.

An even smaller layer is the grains of sand. Together, the sum of all these layers forms natural looking mountains.

In 2D, this is done by adding different sizes of the smoothed noise together.

The zooming factor started at 16 here, and is divided through two each time. Keep doing this until the zooming factor is 1. The small features in the mountain example weren't only smaller in the width, but also in the height. To achieve this in 2D textures, make the images with a smaller zoom darker, so adding them will have less effect:

By adding these 5 images together, and dividing the result through 5 to get the average, you get a turbulence texture:

Here's a function that'll automaticly do all this for a single pixel. The parameter "size" is the initial zoom factor, which was 16 in the example above. The return value is normalized so that it'll be a number between 0 and 255.

double turbulence(double x, double y, double size)
    double value = 0.0, initialSize = size;
    while(size >= 1)
        value += smoothNoise(x / size, y / size) * size;
        size /= 2.0;
    return(128.0 * value / initialSize);

To use the turbulence function, change the small part of the code in the loop that goes through every pixel by the following:

        color.r = color.g = color.b = Uint8(turbulence(x, y, 64));
        pset(x, y, color);

The size is set to 64 there, and the result looks like this:

If you set the initial size to 256 instead, the result is much bigger and smoother:

And here's a very small initial size of only 8:

The textures here have some obvious horizontal and vertical lines because of the bilinear filter smooth function. The Clouds filter in Photoshop generates a texture similar to the ones above, but with a nicer smooth function. Nicer smooth functions are beyond the scope of this article though.

If you use no smooth function at all, it looks like this:

© Lode Vandevenne. Reproduced with permission.

Be the first one to comment on this page.

  Graphics eBooks
More Links » »
 Graphics FAQs
More Links » »
 Graphics Interview Questions
More Links » »
 Graphics Articles
More Links » »
 Graphics News
More Links » »
 Graphics Jobs
More Links » »

Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: Texture Generation using Random Noise, Graphics, Graphics, Graphics tutorial, Graphics tutorial pdf, history of Graphics, learn Graphics

HTML Quizzes
CSS Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
XML Quizzes
XML Quiz
XSL Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright ? 2008. Academic All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World | Important Websites
Copyright ? 2003-2022 Vyom Technosoft Pvt. Ltd., All Rights Reserved.