Archived

This topic is now archived and is closed to further replies.

Ray Cylinder bug

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

Recommended Posts

Hello, I''m writting a ray tracer from scratch and currently I''m trying to implement Cylinders as primitives. It''s working almost perfectly. My problem is that on the edges of the Cylinder there seems to be some sort of computational rounding error. It looks like the edges has been scratched or corrided. Normalizing all Vectors gave an improovement but it''s still visible. Any ideas? Thank you, JVFF

Share on other sites
I can think of a couple possibilities... are you using any trig functions in your intersection test? That might introduce some instability at the tangental cases, so instead you can use a closest distance between rays test. Also, numerical imprecision can cause you to slightly miscalculate the point of intersection, so the rays you spawn from that point re-intersect with the cylinder.

Share on other sites
I don''t know if this will help but here''s my code:

bool Cylinder::rayTrace(Point *ray)
{
Point p1 = ray->crossProduct(direction);

float a = p1.dotProduct(p1);

Point origToCenter = orig - center;

Point p2 = origToCenter.crossProduct(direction);

float b = 2 * p2.dotProduct(p1);

float determinant = (b * b) - 4 * a * c;

if(determinant < 0.f)
return false;

return true;
}

Anyway, it seems like normalizing all vectors (p1, p2, origToCenter) gives a lower noise, as stated before, but it''s still there. Direction is the normalized vector of the cylinder''s axis. I can''t seem to figure this one out. If anyone thinks of something, please tell me. Thank you,

JVFF

Share on other sites
You need an epsilon constant. Instead of testing for < 0.0f, test for < 0.000001f or something similar; personally I use an epsilon of 1e-4 for single-precision floats, and 1e-9 for doubles.

PiQ Software - Tiny KeyCounter - Freon 2/7 Raytracing Accelerator

Share on other sites
Hello again,

It still doesn''t work. If I set EPSILON higher than 0.000001 the cylinder wouldn''t display. Lower than that it just gives an unoticable improovement. The noise still survives. But thank you for your replys.

JVFF

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• Forum Statistics

• Total Topics
633311
• Total Posts
3011313
• Who's Online (See full list)

There are no registered users currently online

×