OK Patrice,
This hotfix seems to eliminate glitches in
RamJet,
Millenium_Falcon, and your latest
bug.obj.
Around
line 187 in
shaders.h, use the following code:
........
} else if (pResourceId == SHADER_NORMAL) { // 12-11-2015 ML: multilight
vs =
"varying mat3 tbnMatrix;\n"
"varying vec4 position;\n"
"varying vec3 lNormal;\n"
"varying vec3 vertex;\n"
"void main() {\n"
"gl_TexCoord[0] = gl_MultiTexCoord0;\n"
"vertex = gl_Vertex.xyz;\n"
//"gl_Position = ftransform();\n" // ML: better for OpenGL normal maps
"gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" // ML: better for DirectX normal maps
"// Transform the normal into eye space and normalize the result.\n"
"position = gl_ModelViewMatrix * gl_Vertex;\n"
"lNormal = normalize(gl_NormalMatrix * gl_Normal);\n"
"// Setup stuff for normal maps\n"
//"vec3 t = normalize(gl_NormalMatrix * gl_MultiTexCoord1.xyz);\n"
"vec3 t = gl_NormalMatrix * gl_MultiTexCoord1.xyz;\n" // fighting RamJet artifacts
"vec3 b = cross(lNormal, t) * gl_MultiTexCoord1.w;\n"
"tbnMatrix = mat3(t, b, lNormal);\n"
"}";
........The bitangent cross product determines the tangent-space normals' orientation (if they face front or back), and in some cases simple renormalization of tangent before taking its cross product with the normal may cause the unexpected and incorrect flipping of the latter. Some Internet resources do normalize tangents and some others don't. So I omitted the normalization and it seems to have done the trick.
Theoretically the non-normalized tangents could make the normals (and consequently, the specular highlights) somewhat sharper. However the latest models with good metal surface detalization and AO maps (e.g. DreadRoamer, Teal'c, Knight, Nyra, and especially Unreal) look simply excellent with this fix. I don't think we will have to change anything in the existing material files.
Please let me know how the fix works for you, my friend.