+ convert modelspace deluxemaps to tangentspace
+ ----------------------------------------------------------------- */
+ /* note it */
+ if ( !bouncing ) {
+ if ( deluxemap && deluxemode == 1 ) {
+ vec3_t worldUp, myNormal, myTangent, myBinormal;
+ float dist;
+
+ Sys_Printf( "converting..." );
+
+ for ( i = 0; i < numRawLightmaps; i++ )
+ {
+ /* get lightmap */
+ lm = &rawLightmaps[ i ];
+
+ /* walk lightmap samples */
+ for ( y = 0; y < lm->sh; y++ )
+ {
+ for ( x = 0; x < lm->sw; x++ )
+ {
+ /* get normal and deluxel */
+ normal = SUPER_NORMAL( x, y );
+ cluster = SUPER_CLUSTER( x, y );
+ bspDeluxel = BSP_DELUXEL( x, y );
+ deluxel = SUPER_DELUXEL( x, y );
+
+ /* get normal */
+ VectorSet( myNormal, normal[0], normal[1], normal[2] );
+
+ /* get tangent vectors */
+ if ( myNormal[ 0 ] == 0.0f && myNormal[ 1 ] == 0.0f ) {
+ if ( myNormal[ 2 ] == 1.0f ) {
+ VectorSet( myTangent, 1.0f, 0.0f, 0.0f );
+ VectorSet( myBinormal, 0.0f, 1.0f, 0.0f );
+ }
+ else if ( myNormal[ 2 ] == -1.0f ) {
+ VectorSet( myTangent, -1.0f, 0.0f, 0.0f );
+ VectorSet( myBinormal, 0.0f, 1.0f, 0.0f );
+ }
+ }
+ else
+ {
+ VectorSet( worldUp, 0.0f, 0.0f, 1.0f );
+ CrossProduct( myNormal, worldUp, myTangent );
+ VectorNormalize( myTangent, myTangent );
+ CrossProduct( myTangent, myNormal, myBinormal );
+ VectorNormalize( myBinormal, myBinormal );
+ }
+
+ /* project onto plane */
+ dist = -DotProduct( myTangent, myNormal );
+ VectorMA( myTangent, dist, myNormal, myTangent );
+ dist = -DotProduct( myBinormal, myNormal );
+ VectorMA( myBinormal, dist, myNormal, myBinormal );
+
+ /* renormalize */
+ VectorNormalize( myTangent, myTangent );
+ VectorNormalize( myBinormal, myBinormal );
+
+ /* convert modelspace deluxel to tangentspace */
+ dirSample[0] = bspDeluxel[0];
+ dirSample[1] = bspDeluxel[1];
+ dirSample[2] = bspDeluxel[2];
+ VectorNormalize( dirSample, dirSample );
+
+ /* fix tangents to world matrix */
+ if ( myNormal[0] > 0 || myNormal[1] < 0 || myNormal[2] < 0 ) {
+ VectorNegate( myTangent, myTangent );
+ }
+
+ /* build tangentspace vectors */
+ bspDeluxel[0] = DotProduct( dirSample, myTangent );
+ bspDeluxel[1] = DotProduct( dirSample, myBinormal );
+ bspDeluxel[2] = DotProduct( dirSample, myNormal );
+ }
+ }
+ }
+ }
+ }
+
+ /* -----------------------------------------------------------------
+ blend lightmaps