Jump to content
• Advertisement

# Using Solid Textures (Perlin Noise) in Ray Tracing

This topic is 4780 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

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

#### Share this post

##### Share on other sites
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

#### Share this post

##### Share on other sites
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???

#### Share this post

##### Share on other sites
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

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5
• Advertisement

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013598
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!