Skip to content

Commit ff6cd8d

Browse files
committed
Shadow cache fixes. SHADOW_TOLERANCE vs SMALL_TOLERANCE cleanup.
SHADOW_TOLERANCE not used for cached results leading to artifacts though sometimes hiding others. Shadow cache not invalidated on misses causing sometimes significant performance hit. SMALL_TOLERANCE being used instead of SHADOW_TOLERANCE in some trace shadow related comparisons. Values had long (25+ years) been cleaned up ahead of SMALL_TOLERANCE removal. Note! This the last commit where SMALL_TOLERANCE will exist
1 parent 4ea0c37 commit ff6cd8d

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

source/core/configcore.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@
182182
/// @def SMALL_TOLERANCE
183183
/// Minimum distance that qualifies as ray-object intersection.
184184
///
185-
/// @note
186-
/// Some algorithms use @ref MIN_ISECT_DEPTH instead.
187-
///
188185
#define SMALL_TOLERANCE 0.001
189186

190187
/// @def MAX_DISTANCE

source/core/math/polynomialsolver.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,11 @@ class RenderStatistics;
5959
/// Maximum supported polynomial order.
6060
///
6161
/// @todo
62-
/// This currently carries a large, fixed per polysolve() call
63-
/// memory allocation on the stack. Size is on the order of
64-
/// (MAX_ORDER+1)*int + PRECISE_FLOAT * (MAX_ORDER+1)^2
65-
/// which impacts performance and performance stability especially
66-
/// for threads > cores. Allocation based on current equation order
67-
/// would be better. My C++ attempts at this all badly slower. C itself
68-
/// supports a struct "flexible array member" feature, however this
69-
/// not a C++11 standard though some C++ compilers support it.
62+
/// This currently carries a large, fixed, per polysolve() call memory allocation
63+
/// on the stack. Size is on the order of (MAX_ORDER+1)*int + PRECISE_FLOAT *
64+
/// (MAX_ORDER+1)^2 which impacts performance and performance stability
65+
/// especially for threads > physical cores. Allocation based on current
66+
/// equation order would be better.
7067
///
7168
#define MAX_ORDER 35
7269

source/core/render/trace.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,7 @@ struct NoShadowFlagRayObjectCondition : public RayObjectCondition
19341934

19351935
struct SmallToleranceRayObjectCondition : public RayObjectCondition
19361936
{
1937-
virtual bool operator()(const Ray&, ConstObjectPtr, double dist) const { return dist > SMALL_TOLERANCE; }
1937+
virtual bool operator()(const Ray&, ConstObjectPtr, double dist) const { return dist > SHADOW_TOLERANCE; }
19381938
};
19391939

19401940
void Trace::TracePointLightShadowRay(const LightSource &lightsource, double& lightsourcedepth, Ray& lightsourceray, MathColour& lightcolour)
@@ -1954,7 +1954,7 @@ void Trace::TracePointLightShadowRay(const LightSource &lightsource, double& lig
19541954
if(FindIntersection(lightsource.Projected_Through_Object, tempIntersection, lightsourceray))
19551955
{
19561956
if((tempIntersection.Depth - lightsourcedepth) < 0.0)
1957-
projectedDepth = lightsourcedepth - fabs(tempIntersection.Depth) + SMALL_TOLERANCE;
1957+
projectedDepth = lightsourcedepth - fabs(tempIntersection.Depth) + SHADOW_TOLERANCE;
19581958
else
19591959
{
19601960
lightcolour.Clear();
@@ -1978,7 +1978,7 @@ void Trace::TracePointLightShadowRay(const LightSource &lightsource, double& lig
19781978

19791979
// check for object in the light source shadow cache (object that fully shadowed during last test) first
19801980

1981-
if(lightsource.lightGroupLight == false) // we don't cache for light groups
1981+
if (lightsource.lightGroupLight == false) // we don't cache for light groups
19821982
{
19831983
if ((lightsourceray.GetTicket().traceLevel == 2) && (lightSourceLevel1ShadowCache[lightsource.index] != nullptr))
19841984
cacheObject = lightSourceLevel1ShadowCache[lightsource.index];
@@ -1988,7 +1988,8 @@ void Trace::TracePointLightShadowRay(const LightSource &lightsource, double& lig
19881988
// if there was an object in the light source shadow cache, check that first
19891989
if (cacheObject != nullptr)
19901990
{
1991-
if(FindIntersection(cacheObject, boundedIntersection, lightsourceray, lightsourcedepth - projectedDepth) == true)
1991+
if (FindIntersection(cacheObject, boundedIntersection, lightsourceray,
1992+
postcond, lightsourcedepth - projectedDepth) == true)
19921993
{
19931994
if(!Test_Flag(boundedIntersection.Object, NO_SHADOW_FLAG))
19941995
{
@@ -2007,7 +2008,16 @@ void Trace::TracePointLightShadowRay(const LightSource &lightsource, double& lig
20072008
cacheObject = nullptr;
20082009
}
20092010
else
2010-
cacheObject = nullptr;
2011+
{
2012+
if (lightsourceray.GetTicket().traceLevel == 2)
2013+
{
2014+
lightSourceLevel1ShadowCache[lightsource.index] = nullptr;
2015+
}
2016+
else
2017+
{
2018+
lightSourceOtherShadowCache[lightsource.index] = nullptr;
2019+
}
2020+
}
20112021
}
20122022
}
20132023

0 commit comments

Comments
 (0)