Created
January 29, 2011 04:10
-
-
Save cdave1/801522 to your computer and use it in GitHub Desktop.
Dot product shadow intensity lookup table...completely broken and slow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static bool hasGeneratedLookup = false; | |
#define DOT_LOOKUP_SIZE 1024 | |
#define DOT_LOOKUP_BITMASK 1023 | |
static uint8 colorDotLookup[DOT_LOOKUP_SIZE]; | |
/* | |
* Below code - waste of time; too slow. | |
*/ | |
inline uint8 hdColorDot(float color, float normal) | |
{ | |
unsigned i; | |
float lookupColor, lookupNormal, lookupStep; | |
if (!hasGeneratedLookup) | |
{ | |
lookupStep = 1.0f / (float)DOT_LOOKUP_SIZE; | |
memset(colorDotLookup, 0, sizeof(colorDotLookup)); | |
lookupColor = lookupNormal = 0.0f; | |
for (i = 0; i < DOT_LOOKUP_SIZE; ++i) | |
{ | |
colorDotLookup[i] = (uint8)((int)(255 * lookupColor)) & DOT_LOOKUP_BITMASK; | |
lookupColor += lookupStep; | |
} | |
hasGeneratedLookup = true; | |
} | |
return colorDotLookup[((uint32)(color * normal * DOT_LOOKUP_SIZE)) & DOT_LOOKUP_BITMASK]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment