I created a basic ray tracer using planes,triangles and spheres.I want to know how to add textures to it.can some one help me please.I need to add a noise function called perlin noise fn to it.

Thanks in advance.

If you need procedural textures you can use libnoise.

Edit: It is very easy to use Perlin noise to generate a procedural texture for a surface. Take the hit coordinates of the ray and pass it to the noise generator. A very simple procedural texture can be defined like this:

```
red = (noise.GetValue(hit.x,hit.y,hit.z)+1.0)*0.5
//Add a constant number for having a different value
green = (noise.GetValue(hit.x+M_PI,hit.y-M_PI,hit.z)+1.0)*0.5
blue = (noise.GetValue(hit.x-M_PI,hit.y+M_PI,hit.z+0.56756)+1.0)*0.5
```

M_PI come from #include <cmath> header. noise is an object of type noise::module::Perlin from libnoise.You can find other noise generator source code on the internet.

Edit: Marc Olano web site made a Perlin noise generator with source code available.

Reedit: Stefan Gustavson paper about Perlin simplex noise is also interesting.

For a plane in the xy plane => the normal = (0,0,1) you can take this algorithm:

if the sum of floor(x) + floor(y) coordinate is odd the color is black else if the sum is even the color is white.

```
if( (int(x) + int(y))%2 == 1)
{
color = black;
}
else
{
color = white;
}
```