Add uniformScale shader flag;
Used to switch to a faster version of lovrNormalMatrix, can be used
with all shader types.
@@ -8,7 +8,11 @@ const char* lovrShaderVertexPrefix = ""
"#define lovrProjection lovrProjections[lovrViewID] \n"
"#define lovrModel lovrModels[lovrDrawID] \n"
"#define lovrTransform (lovrView * lovrModel) \n"
+"#ifdef FLAG_uniformScale \n"
+"#define lovrNormalMatrix mat3(lovrModel) \n"
+"#else \n"
"#define lovrNormalMatrix mat3(transpose(inverse(lovrTransform))) \n"
+"#endif \n"
"#define lovrInstanceID (gl_InstanceID / lovrViewportCount) \n"
"#define lovrPoseMatrix ("
"lovrPose[lovrBones[0]] * lovrBoneWeights[0] +"
@@ -131,12 +135,12 @@ const char* lovrStandardVertexShader = ""
" vVertexPositionWorld = vec3(lovrModel * vertex); \n"
" vCameraPositionWorld = -lovrView[3].xyz * mat3(lovrView); \n"
"#ifdef FLAG_normalTexture \n"
-" vec3 normal = normalize(mat3(lovrModel) * lovrNormal); // TODO non-uniform scale \n"
-" vec3 tangent = normalize(mat3(lovrModel) * lovrTangent.xyz); \n"
+" vec3 normal = normalize(lovrNormalMatrix * lovrNormal); \n"
+" vec3 tangent = normalize(lovrNormalMatrix * lovrTangent.xyz); \n"
" vec3 bitangent = cross(normal, tangent) * lovrTangent.w; \n"
" vTangentMatrix = mat3(tangent, bitangent, normal); \n"
"#else \n"
-" vNormal = normalize(mat3(lovrModel) * lovrNormal); \n"
+" vNormal = normalize(lovrNormalMatrix * lovrNormal); \n"
"#endif \n"
" return projection * transform * vertex; \n"
"}";
