Skip to content

Commit ef9538b

Browse files
committed
Mostly details completing the previous two commits.
Eliminating SMALL_TOLERANCE in addition to MIN_ISECT_DIST. This partly follows up on a question Jerome asked either in POV-Ray#358 or some related issue. Namely, why not zero or near it for the Intersect_BBox_Dir calls in object.cpp. Larger values do indeed cause artifacts with secondary rays as especially noticeable in scenes with media. It's one of many causes for media speckles. Pull POV-Ray#358 as originally submitted moved from a MIN_ISECT_DIST value of 1e-4 to SMALL_TOLERANCE of 1e-3 making the inherent problem worse. SMALL_TOLERANCE had also been adopted a few other places in the code. In those cases moved to gkDBL_epsilon or gkMinIsectDepthReturned as appropriate.
1 parent ff6cd8d commit ef9538b

File tree

6 files changed

+27
-31
lines changed

6 files changed

+27
-31
lines changed

source/core/configcore.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,6 @@
179179
#define BOUND_HUGE 2.0e+10
180180
#endif
181181

182-
/// @def SMALL_TOLERANCE
183-
/// Minimum distance that qualifies as ray-object intersection.
184-
///
185-
#define SMALL_TOLERANCE 0.001
186-
187182
/// @def MAX_DISTANCE
188183
/// Maximum distance that qualifies as ray-object intersection.
189184
///

source/core/material/media.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/// @parblock
99
///
1010
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
11-
/// Copyright 1991-2018 Persistence of Vision Raytracer Pty. Ltd.
11+
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
1212
///
1313
/// POV-Ray is free software: you can redistribute it and/or modify
1414
/// it under the terms of the GNU Affero General Public License as
@@ -714,7 +714,7 @@ void MediaFunction::ComputeOneMediaLightInterval(LightSource *light, LightSource
714714
{
715715
case CYLINDER_SOURCE:
716716
if(ComputeCylinderLightInterval(ray, light, &t1, &t2))
717-
insert = ((t1 < isect.Depth) && (t2 > SMALL_TOLERANCE));
717+
insert = ((t1 < isect.Depth) && (t2 > gkMinIsectDepthReturned));
718718
break;
719719
case POINT_SOURCE:
720720
t1 = 0.0;
@@ -723,7 +723,7 @@ void MediaFunction::ComputeOneMediaLightInterval(LightSource *light, LightSource
723723
break;
724724
case SPOT_SOURCE:
725725
if(ComputeSpotLightInterval(ray, light, &t1, &t2))
726-
insert = ((t1 < isect.Depth) && (t2 > SMALL_TOLERANCE));
726+
insert = ((t1 < isect.Depth) && (t2 > gkMinIsectDepthReturned));
727727
break;
728728
}
729729

source/core/scene/object.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -903,25 +903,25 @@ ObjectPtr CompoundObject::Invert()
903903

904904
bool ObjectBase::Intersect_BBox(BBoxDirection variant, const BBoxVector3d& origin, const BBoxVector3d& invdir, BBoxScalar maxd) const
905905
{
906-
// reverted to SMALL_TOLERANCE over v3.7 MIN_ISECT_DEPTH, for FS324 [jg] old code [trf]
906+
// gkDBL_epsilon(4.4e-16) now used over SMALL_TOLERANCE(1e-3) or v3.7 MIN_ISECT_DEPTH(1e-4).
907907
switch(variant)
908908
{
909909
case BBOX_DIR_X0Y0Z0: // 000
910-
return Intersect_BBox_Dir<0, 0, 0>(BBox, origin, invdir, SMALL_TOLERANCE, maxd);
910+
return Intersect_BBox_Dir<0, 0, 0>(BBox, origin, invdir, gkDBL_epsilon, maxd);
911911
case BBOX_DIR_X0Y0Z1: // 001
912-
return Intersect_BBox_Dir<0, 0, 1>(BBox, origin, invdir, SMALL_TOLERANCE, maxd);
912+
return Intersect_BBox_Dir<0, 0, 1>(BBox, origin, invdir, gkDBL_epsilon, maxd);
913913
case BBOX_DIR_X0Y1Z0: // 010
914-
return Intersect_BBox_Dir<0, 1, 0>(BBox, origin, invdir, SMALL_TOLERANCE, maxd);
914+
return Intersect_BBox_Dir<0, 1, 0>(BBox, origin, invdir, gkDBL_epsilon, maxd);
915915
case BBOX_DIR_X0Y1Z1: // 011
916-
return Intersect_BBox_Dir<0, 1, 1>(BBox, origin, invdir, SMALL_TOLERANCE, maxd);
916+
return Intersect_BBox_Dir<0, 1, 1>(BBox, origin, invdir, gkDBL_epsilon, maxd);
917917
case BBOX_DIR_X1Y0Z0: // 100
918-
return Intersect_BBox_Dir<1, 0, 0>(BBox, origin, invdir, SMALL_TOLERANCE, maxd);
918+
return Intersect_BBox_Dir<1, 0, 0>(BBox, origin, invdir, gkDBL_epsilon, maxd);
919919
case BBOX_DIR_X1Y0Z1: // 101
920-
return Intersect_BBox_Dir<1, 0, 1>(BBox, origin, invdir, SMALL_TOLERANCE, maxd);
920+
return Intersect_BBox_Dir<1, 0, 1>(BBox, origin, invdir, gkDBL_epsilon, maxd);
921921
case BBOX_DIR_X1Y1Z0: // 110
922-
return Intersect_BBox_Dir<1, 1, 0>(BBox, origin, invdir, SMALL_TOLERANCE, maxd);
922+
return Intersect_BBox_Dir<1, 1, 0>(BBox, origin, invdir, gkDBL_epsilon, maxd);
923923
case BBOX_DIR_X1Y1Z1: // 111
924-
return Intersect_BBox_Dir<1, 1, 1>(BBox, origin, invdir, SMALL_TOLERANCE, maxd);
924+
return Intersect_BBox_Dir<1, 1, 1>(BBox, origin, invdir, gkDBL_epsilon, maxd);
925925
}
926926

927927
return false; // unreachable

source/core/shape/blob.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ bool Blob::All_Intersections(const Ray& ray, IStack& Depth_Stack, TraceThreadDat
294294

295295
/* To avoid numerical problems we start at the first interval. */
296296

297-
if ((start_dist = intervals[0].bound) < SMALL_TOLERANCE)
297+
if ((start_dist = intervals[0].bound) < gkMinIsectDepthReturned)
298298
{
299299
start_dist = 0.0;
300300
}

source/core/shape/disc.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/// @parblock
1111
///
1212
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
13-
/// Copyright 1991-2017 Persistence of Vision Raytracer Pty. Ltd.
13+
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
1414
///
1515
/// POV-Ray is free software: you can redistribute it and/or modify
1616
/// it under the terms of the GNU Affero General Public License as
@@ -431,7 +431,7 @@ Disc::Disc() : ObjectBase(DISC_OBJECT)
431431

432432
/* Default bounds */
433433

434-
Make_BBox(BBox, -1.0, -1.0, -SMALL_TOLERANCE, 2.0, 2.0, 2.0 * SMALL_TOLERANCE);
434+
Make_BBox(BBox, -1.0, -1.0, -gkMinIsectDepthReturned, 2.0, 2.0, 2.0 * gkMinIsectDepthReturned);
435435
}
436436

437437

@@ -581,7 +581,8 @@ void Disc::Compute_BBox()
581581

582582
rad = sqrt(oradius2);
583583

584-
Make_BBox(BBox, -rad, -rad, -SMALL_TOLERANCE, 2.0*rad, 2.0*rad, 2.0*SMALL_TOLERANCE);
584+
Make_BBox(BBox, -rad, -rad, -gkMinIsectDepthReturned,
585+
2.0*rad, 2.0*rad, 2.0*gkMinIsectDepthReturned);
585586

586587
Recompute_BBox(&BBox, Trans);
587588
}

source/core/shape/polygon.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/// @parblock
1111
///
1212
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
13-
/// Copyright 1991-2018 Persistence of Vision Raytracer Pty. Ltd.
13+
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
1414
///
1515
/// POV-Ray is free software: you can redistribute it and/or modify
1616
/// it under the terms of the GNU Affero General Public License as
@@ -817,22 +817,22 @@ void Polygon::Compute_BBox()
817817

818818
Make_BBox_from_min_max(BBox, Min, Max);
819819

820-
if (fabs(BBox.size[X]) < SMALL_TOLERANCE)
820+
if (fabs(BBox.size[X]) < gkMinIsectDepthReturned)
821821
{
822-
BBox.lowerLeft[X] -= SMALL_TOLERANCE;
823-
BBox.size[X] += 2.0 * SMALL_TOLERANCE;
822+
BBox.lowerLeft[X] -= gkMinIsectDepthReturned;
823+
BBox.size[X] += 2.0 * gkMinIsectDepthReturned;
824824
}
825825

826-
if (fabs(BBox.size[Y]) < SMALL_TOLERANCE)
826+
if (fabs(BBox.size[Y]) < gkMinIsectDepthReturned)
827827
{
828-
BBox.lowerLeft[Y] -= SMALL_TOLERANCE;
829-
BBox.size[Y] += 2.0 * SMALL_TOLERANCE;
828+
BBox.lowerLeft[Y] -= gkMinIsectDepthReturned;
829+
BBox.size[Y] += 2.0 * gkMinIsectDepthReturned;
830830
}
831831

832-
if (fabs(BBox.size[Z]) < SMALL_TOLERANCE)
832+
if (fabs(BBox.size[Z]) < gkMinIsectDepthReturned)
833833
{
834-
BBox.lowerLeft[Z] -= SMALL_TOLERANCE;
835-
BBox.size[Z] += 2.0 * SMALL_TOLERANCE;
834+
BBox.lowerLeft[Z] -= gkMinIsectDepthReturned;
835+
BBox.size[Z] += 2.0 * gkMinIsectDepthReturned;
836836
}
837837
}
838838

0 commit comments

Comments
 (0)