2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
\r
5 This file is part of GtkRadiant.
\r
7 GtkRadiant is free software; you can redistribute it and/or modify
\r
8 it under the terms of the GNU General Public License as published by
\r
9 the Free Software Foundation; either version 2 of the License, or
\r
10 (at your option) any later version.
\r
12 GtkRadiant is distributed in the hope that it will be useful,
\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 GNU General Public License for more details.
\r
17 You should have received a copy of the GNU General Public License
\r
18 along with GtkRadiant; if not, write to the Free Software
\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\r
25 =============================================================================
\r
27 ALPHALIGHT GENERATION
\r
29 Find alphamap values that best match modulated lightmap values
\r
31 This isn't used anymore, but I'm keeping it around...
\r
32 =============================================================================
\r
35 unsigned short alphamap[32*32*32];
\r
36 unsigned char inverse16to8table[65536];
\r
39 static int FindNearestColor( unsigned int color )
\r
42 int closest_so_far = 0;
\r
43 float closest_distance_so_far = 100000000;
\r
45 float r[2], g[2], b[2];
\r
47 // incoming color is assumed to be in 0xRRGGBB format
\r
48 r[0] = ( color & 31 ) << 3;
\r
49 g[0] = ( ( color >> 5 ) & 63 ) << 2;
\r
50 b[0] = ( ( color >> 11 ) & 31 ) << 3;
\r
52 for ( i = 0; i < 256; i++ )
\r
54 r[1] = ( d_8to24table[i] >> 0 ) & 0xFF;
\r
55 g[1] = ( d_8to24table[i] >> 8 ) & 0xFF;
\r
56 b[1] = ( d_8to24table[i] >> 16 ) & 0xFF;
\r
58 d = ( r[1] - r[0] ) * ( r[1] - r[0] ) +
\r
59 ( g[1] - g[0] ) * ( g[1] - g[0] ) +
\r
60 ( b[1] - b[0] ) * ( b[1] - b[0] );
\r
62 if ( d < closest_distance_so_far )
\r
64 closest_distance_so_far = d;
\r
69 return closest_so_far;
\r
73 extern byte BestColor( int, int, int, int, int );
\r
75 void Inverse16_BuildTable( void )
\r
80 ** create the 16-to-8 table
\r
82 for ( i = 0; i < 65536; i++ )
\r
85 int g = ( i >> 5 ) & 63;
\r
86 int b = ( i >> 11 ) & 31;
\r
92 inverse16to8table[i] = BestColor( r, g, b, 0, 255 );
\r
96 void Alphalight_Thread (int i)
\r
100 float mr, mg, mb, ma;
\r
101 float distortion, bestdistortion;
\r
104 r = (i>>10) * (1.0/16);
\r
105 g = ((i>>5)&31) * (1.0/16);
\r
106 b = (i&31) * (1.0/16);
\r
108 bestdistortion = 999999;
\r
109 for (j=0 ; j<16*16*16*16 ; j++)
\r
111 mr = (j>>12) * (1.0/16);
\r
112 mg = ((j>>8)&15) * (1.0/16);
\r
113 mb = ((j>>4)&15) * (1.0/16);
\r
114 ma = (j&15) * (1.0/16);
\r
116 v = r * 0.5 - (mr*ma + 0.5*(1.0-ma));
\r
118 v = g * 0.5 - (mg*ma + 0.5*(1.0-ma));
\r
120 v = b * 0.5 - (mb*ma + 0.5*(1.0-ma));
\r
123 distortion *= 1.0 + ma*4;
\r
125 if (distortion < bestdistortion)
\r
127 bestdistortion = distortion;
\r
133 void Cmd_Alphalight (void)
\r
135 char savename[1024];
\r
137 GetScriptToken (false);
\r
141 ReleaseFile (token);
\r
145 sprintf (savename, "%s%s", gamedir, token);
\r
146 printf ("Building alphalight table...\n");
\r
148 RunThreadsOnIndividual (32*32*32, true, Alphalight_Thread);
\r
150 SaveFile (savename, (byte *)alphamap, sizeof(alphamap));
\r
154 void Cmd_Inverse16Table( void )
\r
156 char savename[1024];
\r
160 sprintf (savename, "pics/16to8.dat");
\r
161 ReleaseFile( savename );
\r
165 sprintf (savename, "%spics/16to8.dat", gamedir);
\r
166 printf ("Building inverse 16-to-8 table...\n");
\r
168 Inverse16_BuildTable();
\r
170 SaveFile( savename, (byte *) inverse16to8table, sizeof( inverse16to8table ) );
\r