Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: how to add texture to a ray tracer

  1. #1
    Intern Contributor
    Join Date
    Sep 2008
    Posts
    65

    how to add texture to a ray tracer

    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.

  2. #2
    Member Regular Contributor trinitrotoluene's Avatar
    Join Date
    Sep 2008
    Location
    Montérégie,Québec
    Posts
    354

    Re: how to add texture to a ray tracer

    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:

    Code :
    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

  3. #3
    Intern Contributor
    Join Date
    Sep 2008
    Posts
    65

    Re: how to add texture to a ray tracer

    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??

  4. #4
    Member Regular Contributor trinitrotoluene's Avatar
    Join Date
    Sep 2008
    Location
    Montérégie,Québec
    Posts
    354

    Re: how to add texture to a ray tracer

    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.

  5. #5
    Intern Contributor
    Join Date
    Sep 2008
    Posts
    65

    Re: how to add texture to a ray tracer

    if i want to add texture of a checker board to my plane how can i create it??

  6. #6
    Member Regular Contributor trinitrotoluene's Avatar
    Join Date
    Sep 2008
    Location
    Montérégie,Québec
    Posts
    354

    Re: how to add texture to a ray tracer

    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.

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •