Add fix for lighting bug, enabled by lighting-fix-tentative user default

This commit is contained in:
Kevin Anthoney 2015-05-20 20:54:40 +01:00
parent c73c881bab
commit 2d21a4df97

View File

@ -1662,6 +1662,7 @@ shaderBindingTarget:(id<OOWeakReferenceSupport>)target
- (void) generateFaceTangents
{
OOJS_PROFILE_ENTER
BOOL lighting_fix = [[NSUserDefaults standardUserDefaults] boolForKey: @"lighting-fix-tentative"];
OOMeshFaceCount i;
for (i = 0; i < faceCount; i++)
@ -1687,14 +1688,28 @@ shaderBindingTarget:(id<OOWeakReferenceSupport>)target
GLfloat dtAB = face->t[1] - face->t[0];
GLfloat dtAC = face->t[2] - face->t[0];
if (dsAC * dtAB > dsAB * dtAC)
if (lighting_fix)
{
dsAB = -dsAB;
dsAC = -dsAC;
if (dsAC * dtAB > dsAB * dtAC)
{
face->tangent = vector_subtract(vector_multiply_scalar(vProjAC, dtAB), vector_multiply_scalar(vProjAB, dtAC));
}
else
{
face->tangent = vector_subtract(vector_multiply_scalar(vProjAB, dtAC), vector_multiply_scalar(vProjAC, dtAB));
}
}
else
{
if (dsAC * dtAB > dsAB * dtAC)
{
dsAB = -dsAB;
dsAC = -dsAC;
}
Vector tangent = vector_subtract(vector_multiply_scalar(vProjAB, dsAC), vector_multiply_scalar(vProjAC, dsAB));
face->tangent = cross_product(nA, tangent); // Rotate 90 degrees. Done this way because I'm too lazy to grok the code above.
}
Vector tangent = vector_subtract(vector_multiply_scalar(vProjAB, dsAC), vector_multiply_scalar(vProjAC, dsAB));
face->tangent = cross_product(nA, tangent); // Rotate 90 degrees. Done this way because I'm too lazy to grok the code above.
}
OOJS_PROFILE_EXIT_VOID