Using Solid Textures (Perlin Noise) in Ray Tracing

Started by
2 comments, last by timw 18 years, 5 months ago
RE: Solid Textures (Perlin Noise) Hi all, Over the last month or so I have been working hard (kind of) and in my own time on a ray tracer based upon the MIT OCW. I am up to implementing Perlin noise (aka solid texturing). Alas, I have no idea how to use Ken's code (noisemachine etc...). Here was my attempt, but all I get to see are black cubes:

class NoiseMaterial : public Material
{
public:
   NoiseMaterial(Matrix m, Material* m1, Material* m2, int oct) : matrix(m), material1(m1), material2(m2), octaves(oct)
   {

   }

   vector3f Shade(const Ray& ray, const Hit& hit, const vector3f& direction_to_light, const vector3f& light_color) const
   {
      vector3f t = hit.GetIntersectionPoint();
      matrix.Transform(t);

      float noise = 0.0f;

      for (int i = 1, j = 1; i < octaves; ++i, j = 2 * j)
      {
         noise = noise + Perlin::noise(t[x] * j, t[y] * j, t[z] * j) / j;
      }

      vector3f shade = ((0.0f + noise) * material1->Shade(ray, hit, direction_to_light, light_color)) + ((1.0f - noise) * material2->Shade(ray, hit, direction_to_light, light_color));

      return shade.Clamp();
   }

protected:
   Matrix matrix;
   Material* material1, * material2;
   int octaves;

private:
};

How would I produce marble cubes like this. I first just want to the produce the green one (lower left) and then extend it to get the marble look and feel... Web Reference: http://groups.csail.mit.edu/graphics/classes/6.837/F04/assignments/assignment6/ Any ideas, help???? Thanks in advance!!!
Advertisement
I can't tell what you're doing, but noise can be negative and often is, so I'd convert it into 0,1 range (noise + 1)/2 it's range is -1,1 but it rarely spends much time near one it's normally distributed I believe so getting value next to one is rare. it still seems odd you wouldn't see anything try multiplying it by something. the lower left I believe doesn't impliment noise, it's just a sin function. the one next to it is the same sin funcion with it's x direction points jittered by noise. also noise is defined across a 255*255*255 grid so if your object has very small dimensions like << 1 or something, then you could be cought in a dark spot of noise for quite some time within your fractal loop, by the time it gets out it's magnitude might be negligible I dont' know.

try this
for (int i = 1, j = 1; i < octaves; ++i, j = 2 * j)
{
noise = noise + Perlin::noise(100*t[x] * j, 100*t[y] * j, 100*t[z] * j) / j;
}


Tim
Nope, sorry, did not help.

Maybe I'll start with something simpler. Has anyone got a simple Perlin noise example (or a link to one), in general - complete w/ source code???
I can't believe you didn't see anything. perhaps there is a bug in the noise implimentation. is your noise ever non zero?? try implimenting just one octave of noise you should still see something.

Tim

This topic is closed to new replies.

Advertisement