=================== R_AddNormalMaps =================== */
| 193 | =================== |
| 194 | */ |
| 195 | static void R_AddNormalMaps( byte *data1, int width1, int height1, byte *data2, int width2, int height2 ) { |
| 196 | int i, j; |
| 197 | byte *newMap; |
| 198 | |
| 199 | // resample pic2 to the same size as pic1 |
| 200 | if ( width2 != width1 || height2 != height1 ) { |
| 201 | newMap = R_Dropsample( data2, width2, height2, width1, height1 ); |
| 202 | data2 = newMap; |
| 203 | } else { |
| 204 | newMap = NULL; |
| 205 | } |
| 206 | |
| 207 | // add the normal change from the second and renormalize |
| 208 | for ( i = 0 ; i < height1 ; i++ ) { |
| 209 | for ( j = 0 ; j < width1 ; j++ ) { |
| 210 | byte *d1, *d2; |
| 211 | idVec3 n; |
| 212 | float len; |
| 213 | |
| 214 | d1 = data1 + ( i * width1 + j ) * 4; |
| 215 | d2 = data2 + ( i * width1 + j ) * 4; |
| 216 | |
| 217 | n[0] = ( d1[0] - 128 ) / 127.0; |
| 218 | n[1] = ( d1[1] - 128 ) / 127.0; |
| 219 | n[2] = ( d1[2] - 128 ) / 127.0; |
| 220 | |
| 221 | // There are some normal maps that blend to 0,0,0 at the edges |
| 222 | // this screws up compression, so we try to correct that here by instead fading it to 0,0,1 |
| 223 | len = n.LengthFast(); |
| 224 | if ( len < 1.0f ) { |
| 225 | n[2] = idMath::Sqrt(1.0 - (n[0]*n[0]) - (n[1]*n[1])); |
| 226 | } |
| 227 | |
| 228 | n[0] += ( d2[0] - 128 ) / 127.0; |
| 229 | n[1] += ( d2[1] - 128 ) / 127.0; |
| 230 | n.Normalize(); |
| 231 | |
| 232 | d1[0] = (byte)(n[0] * 127 + 128); |
| 233 | d1[1] = (byte)(n[1] * 127 + 128); |
| 234 | d1[2] = (byte)(n[2] * 127 + 128); |
| 235 | d1[3] = 255; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | if ( newMap ) { |
| 240 | R_StaticFree( newMap ); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | /* |
| 245 | ================ |
no test coverage detected