Created
January 22, 2013 02:08
-
-
Save zeux/4591438 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Vector3 getLightContributionZ1(float x, float y) | |
{ | |
float wedgeVolumeX = x / 2; | |
float wedgeVolumeY = y / 2; | |
float cornerVolume = x * y / 6; | |
float contribX = wedgeVolumeX - cornerVolume; | |
float contribY = wedgeVolumeY - cornerVolume; | |
return Vector3(contribX, contribY, 1 - contribX - contribY); | |
} | |
Vector3int32 getLightContribution(const Vector3& direction) | |
{ | |
float x = fabsf(direction.x); | |
float y = fabsf(direction.y); | |
float z = fabsf(direction.z); | |
if (z > y && z > x) | |
{ | |
Vector3 result = getLightContributionZ1(x / z, y / z); | |
return convertToFixedPoint16(result.x, result.y, result.z); | |
} | |
else if (y > z && y > x) | |
{ | |
Vector3 result = getLightContributionZ1(x / y, z / y); | |
return convertToFixedPoint16(result.x, result.z, result.y); | |
} | |
else | |
{ | |
Vector3 result = getLightContributionZ1(y / x, z / x); | |
return convertToFixedPoint16(result.z, result.x, result.y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment