View Full Version : how to add texture to a ray tracer
11-02-2008, 11:15 PM
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.
11-03-2008, 06:46 AM
If you need procedural textures you can use libnoise (http://libnoise.sourceforge.net/).
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
11-03-2008, 11:26 AM
Thank you dude where can i get "noise" from perlins fn???and M_PI.Hi if i want to add texture of a checker board to my plane how can i create it??
11-03-2008, 11:35 AM
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 (http://www.csee.umbc.edu/~olano/papers/) made a Perlin noise generator with source code available.
Reedit: Stefan Gustavson paper about Perlin simplex noise (http://webstaff.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf) is also interesting.
11-03-2008, 11:42 AM
if i want to add texture of a checker board to my plane how can i create it??
11-03-2008, 11:45 AM
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;
color = white;
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.