shadow caching

SPECIAL NOTE: highly suggest https://github.com/GarageGames/Torque3D/pull/1441 or a variation thereof to prevent debug spew and false-postives for occlusion results.

With significant research, development and prototyping assistance from both @andr3wmac (shaders and partial hook work), and @LuisAntonRebollo (additional culling)

System operates as follows:
1) materials are given an additional castDynamicShadows boolean entry. (Default at time of writing is true by request. Personal usage at time of writing defaults to false. value is default-initialized in materialDefinition.cpp. script/gui exposed)
2) lights are given a staticRefreshFreq and dynamicRefreshFreq (in milliseconds). script/gui exposed
3) materials are (effectively) sorted into dynamic and static shadowmap render lists based on flag. (see shadowMapPass.cpp)
4) initial shadowmaps are generated for each light and 'list'.
5) as each refreshFreq times out, the relevant shadowmap for a given light is refreshed.

Special notes:
dynamicRefreshFreq for all lights is set to a (script exposed) 8MS refresh timer.
StaticRefreshFreq for the lions share of lights defaults to 250 MS (1/4 of a second)
scattersky's embedded light, which is intended to operate in a mobile manner, defaults to 8
to reiterate, these are all customizable per-light via script/inspector gui in the case of alternate project needs.
This commit is contained in:
Azaezel 2015-10-13 18:12:19 -05:00
parent 2044b2691e
commit 2753f562e8
54 changed files with 1477 additions and 464 deletions

View file

@ -1845,4 +1845,55 @@ U32 extrudePolygonEdgesFromPoint( const Point3F* vertices, U32 numVertices, cons
return numPlanes;
}
//-----------------------------------------------------------------------------
void MathUtils::mBuildHull2D(const Vector<Point2F> _inPoints, Vector<Point2F> &hullPoints)
{
/// Andrew's monotone chain convex hull algorithm implementation
struct Util
{
//compare by x and then by y
static int CompareLexicographic( const Point2F *a, const Point2F *b)
{
return a->x < b->x || (a->x == b->x && a->y < b->y);
}
};
hullPoints.clear();
hullPoints.setSize( _inPoints.size()*2 );
// sort in points by x and then by y
Vector<Point2F> inSortedPoints = _inPoints;
inSortedPoints.sort( &Util::CompareLexicographic );
Point2F* lowerHullPtr = hullPoints.address();
U32 lowerHullIdx = 0;
//lower part of hull
for( int i = 0; i < inSortedPoints.size(); ++i )
{
while( lowerHullIdx >= 2 && mCross( lowerHullPtr[ lowerHullIdx - 2], lowerHullPtr[lowerHullIdx - 1], inSortedPoints[i] ) <= 0 )
--lowerHullIdx;
lowerHullPtr[lowerHullIdx++] = inSortedPoints[i];
}
--lowerHullIdx; // last point are the same as first in upperHullPtr
Point2F* upperHullPtr = hullPoints.address() + lowerHullIdx;
U32 upperHullIdx = 0;
//upper part of hull
for( int i = inSortedPoints.size()-1; i >= 0; --i )
{
while( upperHullIdx >= 2 && mCross( upperHullPtr[ upperHullIdx - 2], upperHullPtr[upperHullIdx - 1], inSortedPoints[i] ) <= 0 )
--upperHullIdx;
upperHullPtr[upperHullIdx++] = inSortedPoints[i];
}
hullPoints.setSize( lowerHullIdx + upperHullIdx );
}
} // namespace MathUtils