1 /* -------------------------------------------------------------------------------
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
6 This file is part of GtkRadiant.
8 GtkRadiant is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 GtkRadiant is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GtkRadiant; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 ----------------------------------------------------------------------------------
24 This code has been altered significantly from its original form, to support
25 several games based on the Quake III Arena engine, in the form of "Q3Map2."
27 ------------------------------------------------------------------------------- */
43 routines for dealing with vertex color/alpha modification
46 void ColorMod( colorMod_t *cm, int numVerts, bspDrawVert_t *drawVerts ){
55 if ( cm == NULL || numVerts < 1 || drawVerts == NULL ) {
60 /* walk vertex list */
61 for ( i = 0; i < numVerts; i++ )
66 /* walk colorMod list */
67 for ( cm2 = cm; cm2 != NULL; cm2 = cm2->next )
70 VectorSet( mult, 1.0f, 1.0f, 1.0f );
72 VectorSet( add, 0.0f, 0.0f, 0.0f );
80 VectorScale( cm2->data, 255.0f, add );
85 add[ 3 ] = cm2->data[ 0 ] * 255.0f;
89 VectorCopy( cm2->data, mult );
93 mult[ 3 ] = cm2->data[ 0 ];
96 case CM_COLOR_DOT_PRODUCT:
97 c = DotProduct( dv->normal, cm2->data );
98 VectorSet( mult, c, c, c );
101 case CM_ALPHA_DOT_PRODUCT:
102 mult[ 3 ] = DotProduct( dv->normal, cm2->data );
105 case CM_COLOR_DOT_PRODUCT_2:
106 c = DotProduct( dv->normal, cm2->data );
108 VectorSet( mult, c, c, c );
111 case CM_ALPHA_DOT_PRODUCT_2:
112 mult[ 3 ] = DotProduct( dv->normal, cm2->data );
113 mult[ 3 ] *= mult[ 3 ];
121 for ( j = 0; j < MAX_LIGHTMAPS; j++ )
123 for ( k = 0; k < 4; k++ )
125 c = ( mult[ k ] * dv->color[ j ][ k ] ) + add[ k ];
129 else if ( c > 255 ) {
132 dv->color[ j ][ k ] = c;
143 routines for dealing with a 3x3 texture mod matrix
146 void TCMod( tcMod_t mod, float st[ 2 ] ){
152 st[ 0 ] = ( mod[ 0 ][ 0 ] * old[ 0 ] ) + ( mod[ 0 ][ 1 ] * old[ 1 ] ) + mod[ 0 ][ 2 ];
153 st[ 1 ] = ( mod[ 1 ][ 0 ] * old[ 0 ] ) + ( mod[ 1 ][ 1 ] * old[ 1 ] ) + mod[ 1 ][ 2 ];
157 void TCModIdentity( tcMod_t mod ){
158 mod[ 0 ][ 0 ] = 1.0f; mod[ 0 ][ 1 ] = 0.0f; mod[ 0 ][ 2 ] = 0.0f;
159 mod[ 1 ][ 0 ] = 0.0f; mod[ 1 ][ 1 ] = 1.0f; mod[ 1 ][ 2 ] = 0.0f;
160 mod[ 2 ][ 0 ] = 0.0f; mod[ 2 ][ 1 ] = 0.0f; mod[ 2 ][ 2 ] = 1.0f; /* this row is only used for multiples, not transformation */
164 void TCModMultiply( tcMod_t a, tcMod_t b, tcMod_t out ){
168 for ( i = 0; i < 3; i++ )
170 out[ i ][ 0 ] = ( a[ i ][ 0 ] * b[ 0 ][ 0 ] ) + ( a[ i ][ 1 ] * b[ 1 ][ 0 ] ) + ( a[ i ][ 2 ] * b[ 2 ][ 0 ] );
171 out[ i ][ 1 ] = ( a[ i ][ 0 ] * b[ 0 ][ 1 ] ) + ( a[ i ][ 1 ] * b[ 1 ][ 1 ] ) + ( a[ i ][ 2 ] * b[ 2 ][ 1 ] );
172 out[ i ][ 2 ] = ( a[ i ][ 0 ] * b[ 0 ][ 2 ] ) + ( a[ i ][ 1 ] * b[ 1 ][ 2 ] ) + ( a[ i ][ 2 ] * b[ 2 ][ 2 ] );
177 void TCModTranslate( tcMod_t mod, float s, float t ){
183 void TCModScale( tcMod_t mod, float s, float t ){
189 void TCModRotate( tcMod_t mod, float euler ){
191 float radians, sinv, cosv;
194 memcpy( old, mod, sizeof( tcMod_t ) );
195 TCModIdentity( temp );
197 radians = euler / 180 * Q_PI;
198 sinv = sin( radians );
199 cosv = cos( radians );
201 temp[ 0 ][ 0 ] = cosv; temp[ 0 ][ 1 ] = -sinv;
202 temp[ 1 ][ 0 ] = sinv; temp[ 1 ][ 1 ] = cosv;
204 TCModMultiply( old, temp, mod );
210 ApplySurfaceParm() - ydnar
211 applies a named surfaceparm to the supplied flags
214 qboolean ApplySurfaceParm( char *name, int *contentFlags, int *surfaceFlags, int *compileFlags ){
220 if ( name == NULL ) {
223 if ( contentFlags == NULL ) {
224 contentFlags = &fake;
226 if ( surfaceFlags == NULL ) {
227 surfaceFlags = &fake;
229 if ( compileFlags == NULL ) {
230 compileFlags = &fake;
233 /* walk the current game's surfaceparms */
234 sp = game->surfaceParms;
235 while ( sp->name != NULL )
238 if ( !Q_stricmp( name, sp->name ) ) {
239 /* clear and set flags */
240 *contentFlags &= ~( sp->contentFlagsClear );
241 *contentFlags |= sp->contentFlags;
242 *surfaceFlags &= ~( sp->surfaceFlagsClear );
243 *surfaceFlags |= sp->surfaceFlags;
244 *compileFlags &= ~( sp->compileFlagsClear );
245 *compileFlags |= sp->compileFlags;
255 /* check custom info parms */
256 for ( i = 0; i < numCustSurfaceParms; i++ )
258 /* get surfaceparm */
259 sp = &custSurfaceParms[ i ];
262 if ( !Q_stricmp( name, sp->name ) ) {
263 /* clear and set flags */
264 *contentFlags &= ~( sp->contentFlagsClear );
265 *contentFlags |= sp->contentFlags;
266 *surfaceFlags &= ~( sp->surfaceFlagsClear );
267 *surfaceFlags |= sp->surfaceFlags;
268 *compileFlags &= ~( sp->compileFlagsClear );
269 *compileFlags |= sp->compileFlags;
276 /* no matching surfaceparm found */
283 BeginMapShaderFile() - ydnar
284 erases and starts a new map shader script
287 void BeginMapShaderFile( const char *mapFile ){
294 mapShaderFile[ 0 ] = '\0';
295 if ( mapFile == NULL || mapFile[ 0 ] == '\0' ) {
300 strcpy( base, mapFile );
301 StripExtension( base );
303 /* extract map name */
304 len = strlen( base ) - 1;
305 while ( len > 0 && base[ len ] != '/' && base[ len ] != '\\' )
307 strcpy( mapName, &base[ len + 1 ] );
313 /* append ../scripts/q3map2_<mapname>.shader */
314 sprintf( mapShaderFile, "%s/../%s/q3map2_%s.shader", base, game->shaderPath, mapName );
315 Sys_FPrintf( SYS_VRB, "Map has shader script %s\n", mapShaderFile );
318 remove( mapShaderFile );
320 /* stop making warnings about missing images */
327 WriteMapShaderFile() - ydnar
328 writes a shader to the map shader script
331 void WriteMapShaderFile( void ){
338 if ( mapShaderFile[ 0 ] == '\0' ) {
342 /* are there any custom shaders? */
343 for ( i = 0, num = 0; i < numShaderInfo; i++ )
345 if ( shaderInfo[ i ].custom ) {
349 if ( i == numShaderInfo ) {
354 Sys_FPrintf( SYS_VRB, "--- WriteMapShaderFile ---\n" );
355 Sys_FPrintf( SYS_VRB, "Writing %s", mapShaderFile );
357 /* open shader file */
358 file = fopen( mapShaderFile, "w" );
359 if ( file == NULL ) {
360 Sys_Printf( "WARNING: Unable to open map shader file %s for writing\n", mapShaderFile );
366 "// Custom shader file for %s.bsp\n"
367 "// Generated by Q3Map2 (ydnar)\n"
368 "// Do not edit! This file is overwritten on recompiles.\n\n",
371 /* walk the shader list */
372 for ( i = 0, num = 0; i < numShaderInfo; i++ )
374 /* get the shader and print it */
375 si = &shaderInfo[ i ];
376 if ( si->custom == qfalse || si->shaderText == NULL || si->shaderText[ 0 ] == '\0' ) {
381 /* print it to the file */
382 fprintf( file, "%s%s\n", si->shader, si->shaderText );
383 //Sys_Printf( "%s%s\n", si->shader, si->shaderText ); /* FIXME: remove debugging code */
385 Sys_FPrintf( SYS_VRB, "." );
388 /* close the shader */
392 Sys_FPrintf( SYS_VRB, "\n" );
394 /* print some stats */
395 Sys_Printf( "%9d custom shaders emitted\n", num );
401 CustomShader() - ydnar
402 sets up a custom map shader
405 shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){
407 char shader[ MAX_QPATH ];
412 char *srcShaderText, temp[ 8192 ], shaderText[ 8192 ]; /* ydnar: fixme (make this bigger?) */
417 return ShaderInfoForShader( "default" );
420 /* default shader text source */
421 srcShaderText = si->shaderText;
423 /* et: implicitMap */
424 if ( si->implicitMap == IM_OPAQUE ) {
425 srcShaderText = temp;
427 "{ // Q3Map2 defaulted (implicitMap)\n"
429 "\t\tmap $lightmap\n"
430 "\t\trgbGen identity\n"
432 "\tq3map_styleMarker\n"
435 "\t\tblendFunc GL_DST_COLOR GL_ZERO\n"
436 "\t\trgbGen identity\n"
439 si->implicitImagePath );
442 /* et: implicitMask */
443 else if ( si->implicitMap == IM_MASKED ) {
444 srcShaderText = temp;
446 "{ // Q3Map2 defaulted (implicitMask)\n"
450 "\t\talphaFunc GE128\n"
454 "\t\tmap $lightmap\n"
455 "\t\trgbGen identity\n"
456 "\t\tdepthFunc equal\n"
458 "\tq3map_styleMarker\n"
461 "\t\tblendFunc GL_DST_COLOR GL_ZERO\n"
462 "\t\tdepthFunc equal\n"
463 "\t\trgbGen identity\n"
466 si->implicitImagePath,
467 si->implicitImagePath );
470 /* et: implicitBlend */
471 else if ( si->implicitMap == IM_BLEND ) {
472 srcShaderText = temp;
474 "{ // Q3Map2 defaulted (implicitBlend)\n"
478 "\t\tblendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA\n"
481 "\t\tmap $lightmap\n"
482 "\t\trgbGen identity\n"
483 "\t\tblendFunc GL_DST_COLOR GL_ZERO\n"
485 "\tq3map_styleMarker\n"
487 si->implicitImagePath );
490 /* default shader text */
491 else if ( srcShaderText == NULL ) {
492 srcShaderText = temp;
494 "{ // Q3Map2 defaulted\n"
496 "\t\tmap $lightmap\n"
497 "\t\trgbGen identity\n"
499 "\tq3map_styleMarker\n"
502 "\t\tblendFunc GL_DST_COLOR GL_ZERO\n"
503 "\t\trgbGen identity\n"
510 if ( ( strlen( mapName ) + 1 + 32 ) > MAX_QPATH ) {
511 Error( "Custom shader name length (%d) exceeded. Shorten your map name.\n", MAX_QPATH );
514 /* do some bad find-replace */
515 s = strstr( srcShaderText, find );
517 //% strcpy( shaderText, srcShaderText );
518 return si; /* testing just using the existing shader if this fails */
522 /* substitute 'find' with 'replace' */
523 loc = s - srcShaderText;
524 strcpy( shaderText, srcShaderText );
525 shaderText[ loc ] = '\0';
526 strcat( shaderText, replace );
527 strcat( shaderText, &srcShaderText[ loc + strlen( find ) ] );
530 /* make md5 hash of the shader text */
532 md5_append( &mh, shaderText, strlen( shaderText ) );
533 md5_finish( &mh, digest );
535 /* mangle hash into a shader name */
536 sprintf( shader, "%s/%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", mapName,
537 digest[ 0 ], digest[ 1 ], digest[ 2 ], digest[ 3 ], digest[ 4 ], digest[ 5 ], digest[ 6 ], digest[ 7 ],
538 digest[ 8 ], digest[ 9 ], digest[ 10 ], digest[ 11 ], digest[ 12 ], digest[ 13 ], digest[ 14 ], digest[ 15 ] );
541 csi = ShaderInfoForShader( shader );
543 /* might be a preexisting shader */
548 /* clone the existing shader and rename */
549 memcpy( csi, si, sizeof( shaderInfo_t ) );
550 strcpy( csi->shader, shader );
553 /* store new shader text */
554 csi->shaderText = safe_malloc( strlen( shaderText ) + 1 );
555 strcpy( csi->shaderText, shaderText ); /* LEAK! */
564 EmitVertexRemapShader()
565 adds a vertexremapshader key/value pair to worldspawn
568 void EmitVertexRemapShader( char *from, char *to ){
571 char key[ 64 ], value[ 256 ];
575 if ( from == NULL || from[ 0 ] == '\0' ||
576 to == NULL || to[ 0 ] == '\0' ) {
581 sprintf( value, "%s;%s", from, to );
585 md5_append( &mh, value, strlen( value ) );
586 md5_finish( &mh, digest );
588 /* make key (this is annoying, as vertexremapshader is precisely 17 characters,
589 which is one too long, so we leave off the last byte of the md5 digest) */
590 sprintf( key, "vertexremapshader%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
591 digest[ 0 ], digest[ 1 ], digest[ 2 ], digest[ 3 ], digest[ 4 ], digest[ 5 ], digest[ 6 ], digest[ 7 ],
592 digest[ 8 ], digest[ 9 ], digest[ 10 ], digest[ 11 ], digest[ 12 ], digest[ 13 ], digest[ 14 ] ); /* no: digest[ 15 ] */
594 /* add key/value pair to worldspawn */
595 SetKeyValue( &entities[ 0 ], key, value );
602 allocates and initializes a new shader
605 static shaderInfo_t *AllocShaderInfo( void ){
610 if ( shaderInfo == NULL ) {
611 shaderInfo = safe_malloc( sizeof( shaderInfo_t ) * MAX_SHADER_INFO );
616 if ( numShaderInfo == MAX_SHADER_INFO ) {
617 Error( "MAX_SHADER_INFO exceeded. Remove some PK3 files or shader scripts from shaderlist.txt and try again." );
619 si = &shaderInfo[ numShaderInfo ];
622 /* ydnar: clear to 0 first */
623 memset( si, 0, sizeof( shaderInfo_t ) );
626 ApplySurfaceParm( "default", &si->contentFlags, &si->surfaceFlags, &si->compileFlags );
628 si->backsplashFraction = DEF_BACKSPLASH_FRACTION;
629 si->backsplashDistance = DEF_BACKSPLASH_DISTANCE;
631 si->bounceScale = DEF_RADIOSITY_BOUNCE;
633 si->lightStyle = LS_NORMAL;
635 si->polygonOffset = qfalse;
637 si->shadeAngleDegrees = 0.0f;
638 si->lightmapSampleSize = 0;
639 si->lightmapSampleOffset = DEFAULT_LIGHTMAP_SAMPLE_OFFSET;
640 si->patchShadows = qfalse;
641 si->vertexShadows = qtrue; /* ydnar: changed default behavior */
642 si->forceSunlight = qfalse;
643 si->vertexScale = 1.0;
644 si->notjunc = qfalse;
646 /* ydnar: set texture coordinate transform matrix to identity */
647 TCModIdentity( si->mod );
649 /* ydnar: lightmaps can now be > 128x128 in certain games or an externally generated tga */
650 si->lmCustomWidth = lmCustomSize;
651 si->lmCustomHeight = lmCustomSize;
653 /* return to sender */
660 FinishShader() - ydnar
661 sets a shader's width and height among other things
664 void FinishShader( shaderInfo_t *si ){
666 float st[ 2 ], o[ 2 ], dist, bestDist;
667 vec4_t color, bestColor, delta;
670 /* don't double-dip */
671 if ( si->finished ) {
675 /* if they're explicitly set, copy from image size */
676 if ( si->shaderWidth == 0 && si->shaderHeight == 0 ) {
677 si->shaderWidth = si->shaderImage->width;
678 si->shaderHeight = si->shaderImage->height;
681 /* legacy terrain has explicit image-sized texture projection */
682 if ( si->legacyTerrain && si->tcGen == qfalse ) {
683 /* set xy texture projection */
685 VectorSet( si->vecs[ 0 ], ( 1.0f / ( si->shaderWidth * 0.5f ) ), 0, 0 );
686 VectorSet( si->vecs[ 1 ], 0, ( 1.0f / ( si->shaderHeight * 0.5f ) ), 0 );
689 /* find pixel coordinates best matching the average color of the image */
691 o[ 0 ] = 1.0f / si->shaderImage->width;
692 o[ 1 ] = 1.0f / si->shaderImage->height;
693 for ( y = 0, st[ 1 ] = 0.0f; y < si->shaderImage->height; y++, st[ 1 ] += o[ 1 ] )
695 for ( x = 0, st[ 0 ] = 0.0f; x < si->shaderImage->width; x++, st[ 0 ] += o[ 0 ] )
697 /* sample the shader image */
698 RadSampleImage( si->shaderImage->pixels, si->shaderImage->width, si->shaderImage->height, st, color );
700 /* determine error squared */
701 VectorSubtract( color, si->averageColor, delta );
702 delta[ 3 ] = color[ 3 ] - si->averageColor[ 3 ];
703 dist = delta[ 0 ] * delta[ 0 ] + delta[ 1 ] * delta[ 1 ] + delta[ 2 ] * delta[ 2 ] + delta[ 3 ] * delta[ 3 ];
704 if ( dist < bestDist ) {
705 VectorCopy( color, bestColor );
706 bestColor[ 3 ] = color[ 3 ];
707 si->stFlat[ 0 ] = st[ 0 ];
708 si->stFlat[ 1 ] = st[ 1 ];
713 /* set to finished */
714 si->finished = qtrue;
721 loads a shader's images
722 ydnar: image.c made this a bit simpler
725 static void LoadShaderImages( shaderInfo_t *si ){
730 /* nodraw shaders don't need images */
731 if ( si->compileFlags & C_NODRAW ) {
732 si->shaderImage = ImageLoad( DEFAULT_IMAGE );
736 /* try to load editor image first */
737 si->shaderImage = ImageLoad( si->editorImagePath );
739 /* then try shadername */
740 if ( si->shaderImage == NULL ) {
741 si->shaderImage = ImageLoad( si->shader );
744 /* then try implicit image path (note: new behavior!) */
745 if ( si->shaderImage == NULL ) {
746 si->shaderImage = ImageLoad( si->implicitImagePath );
749 /* then try lightimage (note: new behavior!) */
750 if ( si->shaderImage == NULL ) {
751 si->shaderImage = ImageLoad( si->lightImagePath );
754 /* otherwise, use default image */
755 if ( si->shaderImage == NULL ) {
756 si->shaderImage = ImageLoad( DEFAULT_IMAGE );
757 if ( warnImage && strcmp( si->shader, "noshader" ) ) {
758 Sys_Printf( "WARNING: Couldn't find image for shader %s\n", si->shader );
762 /* load light image */
763 si->lightImage = ImageLoad( si->lightImagePath );
765 /* load normalmap image (ok if this is NULL) */
766 si->normalImage = ImageLoad( si->normalImagePath );
767 if ( si->normalImage != NULL ) {
768 Sys_FPrintf( SYS_VRB, "Shader %s has\n"
769 " NM %s\n", si->shader, si->normalImagePath );
773 /* if no light image, use shader image */
774 if ( si->lightImage == NULL ) {
775 si->lightImage = ImageLoad( si->shaderImage->name );
778 /* create default and average colors */
779 count = si->lightImage->width * si->lightImage->height;
780 VectorClear( color );
782 for ( i = 0; i < count; i++ )
784 color[ 0 ] += si->lightImage->pixels[ i * 4 + 0 ];
785 color[ 1 ] += si->lightImage->pixels[ i * 4 + 1 ];
786 color[ 2 ] += si->lightImage->pixels[ i * 4 + 2 ];
787 color[ 3 ] += si->lightImage->pixels[ i * 4 + 3 ];
790 if ( VectorLength( si->color ) <= 0.0f ) {
791 ColorNormalize( color, si->color );
793 VectorScale( color, ( 1.0f / count ), si->averageColor );
799 ShaderInfoForShader()
800 finds a shaderinfo for a named shader
803 shaderInfo_t *ShaderInfoForShader( const char *shaderName ){
806 char shader[ MAX_QPATH ];
810 if ( shaderName == NULL || shaderName[ 0 ] == '\0' ) {
811 Sys_Printf( "WARNING: Null or empty shader name\n" );
812 shaderName = "missing";
815 /* strip off extension */
816 strcpy( shader, shaderName );
817 StripExtension( shader );
820 for ( i = 0; i < numShaderInfo; i++ )
822 si = &shaderInfo[ i ];
823 if ( !Q_stricmp( shader, si->shader ) ) {
824 /* load image if necessary */
825 if ( si->finished == qfalse ) {
826 LoadShaderImages( si );
835 /* allocate a default shader */
836 si = AllocShaderInfo();
837 strcpy( si->shader, shader );
838 LoadShaderImages( si );
848 GetTokenAppend() - ydnar
849 gets a token and appends its text to the specified buffer
852 static int oldScriptLine = 0;
853 static int tabDepth = 0;
855 qboolean GetTokenAppend( char *buffer, qboolean crossline ){
861 r = GetToken( crossline );
862 if ( r == qfalse || buffer == NULL || token[ 0 ] == '\0' ) {
867 if ( token[ 0 ] == '}' ) {
872 if ( oldScriptLine != scriptline ) {
873 strcat( buffer, "\n" );
874 for ( i = 0; i < tabDepth; i++ )
875 strcat( buffer, "\t" );
878 strcat( buffer, " " );
880 oldScriptLine = scriptline;
881 strcat( buffer, token );
884 if ( token[ 0 ] == '{' ) {
893 void Parse1DMatrixAppend( char *buffer, int x, vec_t *m ){
897 if ( !GetTokenAppend( buffer, qtrue ) || strcmp( token, "(" ) ) {
898 Error( "Parse1DMatrixAppend(): line %d: ( not found!", scriptline );
900 for ( i = 0; i < x; i++ )
902 if ( !GetTokenAppend( buffer, qfalse ) ) {
903 Error( "Parse1DMatrixAppend(): line %d: Number not found!", scriptline );
905 m[ i ] = atof( token );
907 if ( !GetTokenAppend( buffer, qtrue ) || strcmp( token, ")" ) ) {
908 Error( "Parse1DMatrixAppend(): line %d: ) not found!", scriptline );
917 parses a shader file into discrete shaderInfo_t
920 static void ParseShaderFile( const char *filename ){
923 char *suffix, temp[ 1024 ];
924 char shaderText[ 8192 ]; /* ydnar: fixme (make this bigger?) */
929 shaderText[ 0 ] = '\0';
931 /* load the shader */
932 LoadScriptFile( filename, 0 );
937 /* copy shader text to the shaderinfo */
938 if ( si != NULL && shaderText[ 0 ] != '\0' ) {
939 strcat( shaderText, "\n" );
940 si->shaderText = safe_malloc( strlen( shaderText ) + 1 );
941 strcpy( si->shaderText, shaderText );
942 //% if( VectorLength( si->vecs[ 0 ] ) )
943 //% Sys_Printf( "%s\n", shaderText );
946 /* ydnar: clear shader text buffer */
947 shaderText[ 0 ] = '\0';
949 /* test for end of file */
950 if ( !GetToken( qtrue ) ) {
954 /* shader name is initial token */
955 si = AllocShaderInfo();
956 strcpy( si->shader, token );
958 /* ignore ":q3map" suffix */
959 suffix = strstr( si->shader, ":q3map" );
960 if ( suffix != NULL ) {
964 /* handle { } section */
965 if ( !GetTokenAppend( shaderText, qtrue ) ) {
968 if ( strcmp( token, "{" ) ) {
970 Error( "ParseShaderFile(): %s, line %d: { not found!\nFound instead: %s\nLast known shader: %s",
971 filename, scriptline, token, si->shader );
974 Error( "ParseShaderFile(): %s, line %d: { not found!\nFound instead: %s",
975 filename, scriptline, token );
981 /* get the next token */
982 if ( !GetTokenAppend( shaderText, qtrue ) ) {
985 if ( !strcmp( token, "}" ) ) {
990 /* -----------------------------------------------------------------
991 shader stages (passes)
992 ----------------------------------------------------------------- */
994 /* parse stage directives */
995 if ( !strcmp( token, "{" ) ) {
996 si->hasPasses = qtrue;
999 if ( !GetTokenAppend( shaderText, qtrue ) ) {
1002 if ( !strcmp( token, "}" ) ) {
1006 /* only care about images if we don't have a editor/light image */
1007 if ( si->editorImagePath[ 0 ] == '\0' && si->lightImagePath[ 0 ] == '\0' && si->implicitImagePath[ 0 ] == '\0' ) {
1008 /* digest any images */
1009 if ( !Q_stricmp( token, "map" ) ||
1010 !Q_stricmp( token, "clampMap" ) ||
1011 !Q_stricmp( token, "animMap" ) ||
1012 !Q_stricmp( token, "clampAnimMap" ) ||
1013 !Q_stricmp( token, "clampMap" ) ||
1014 !Q_stricmp( token, "mapComp" ) ||
1015 !Q_stricmp( token, "mapNoComp" ) ) {
1016 /* skip one token for animated stages */
1017 if ( !Q_stricmp( token, "animMap" ) || !Q_stricmp( token, "clampAnimMap" ) ) {
1018 GetTokenAppend( shaderText, qfalse );
1022 GetTokenAppend( shaderText, qfalse );
1023 if ( token[ 0 ] != '*' && token[ 0 ] != '$' ) {
1024 strcpy( si->lightImagePath, token );
1025 DefaultExtension( si->lightImagePath, ".tga" );
1028 //% Sys_FPrintf( SYS_VRB, "Deduced shader image: %s\n", si->lightImagePath );
1036 /* -----------------------------------------------------------------
1037 surfaceparm * directives
1038 ----------------------------------------------------------------- */
1040 /* match surfaceparm */
1041 else if ( !Q_stricmp( token, "surfaceparm" ) ) {
1042 GetTokenAppend( shaderText, qfalse );
1043 if ( ApplySurfaceParm( token, &si->contentFlags, &si->surfaceFlags, &si->compileFlags ) == qfalse ) {
1044 Sys_Printf( "WARNING: Unknown surfaceparm: \"%s\"\n", token );
1049 /* -----------------------------------------------------------------
1050 game-related shader directives
1051 ----------------------------------------------------------------- */
1053 /* ydnar: fogparms (for determining fog volumes) */
1054 else if ( !Q_stricmp( token, "fogparms" ) ) {
1055 si->fogParms = qtrue;
1058 /* ydnar: polygonoffset (for no culling) */
1059 else if ( !Q_stricmp( token, "polygonoffset" ) ) {
1060 si->polygonOffset = qtrue;
1063 /* tesssize is used to force liquid surfaces to subdivide */
1064 else if ( !Q_stricmp( token, "tessSize" ) || !Q_stricmp( token, "q3map_tessSize" ) /* sof2 */ ) {
1065 GetTokenAppend( shaderText, qfalse );
1066 si->subdivisions = atof( token );
1069 /* cull none will set twoSided (ydnar: added disable too) */
1070 else if ( !Q_stricmp( token, "cull" ) ) {
1071 GetTokenAppend( shaderText, qfalse );
1072 if ( !Q_stricmp( token, "none" ) || !Q_stricmp( token, "disable" ) || !Q_stricmp( token, "twosided" ) ) {
1073 si->twoSided = qtrue;
1077 /* deformVertexes autosprite[ 2 ]
1078 we catch this so autosprited surfaces become point
1079 lights instead of area lights */
1080 else if ( !Q_stricmp( token, "deformVertexes" ) ) {
1081 GetTokenAppend( shaderText, qfalse );
1083 /* deformVertexes autosprite(2) */
1084 if ( !Q_strncasecmp( token, "autosprite", 10 ) ) {
1085 /* set it as autosprite and detail */
1086 si->autosprite = qtrue;
1087 ApplySurfaceParm( "detail", &si->contentFlags, &si->surfaceFlags, &si->compileFlags );
1089 /* ydnar: gs mods: added these useful things */
1091 si->notjunc = qtrue;
1094 /* deformVertexes move <x> <y> <z> <func> <base> <amplitude> <phase> <freq> (ydnar: for particle studio support) */
1095 if ( !Q_stricmp( token, "move" ) ) {
1096 vec3_t amt, mins, maxs;
1100 /* get move amount */
1101 GetTokenAppend( shaderText, qfalse ); amt[ 0 ] = atof( token );
1102 GetTokenAppend( shaderText, qfalse ); amt[ 1 ] = atof( token );
1103 GetTokenAppend( shaderText, qfalse ); amt[ 2 ] = atof( token );
1106 GetTokenAppend( shaderText, qfalse );
1108 /* get base and amplitude */
1109 GetTokenAppend( shaderText, qfalse ); base = atof( token );
1110 GetTokenAppend( shaderText, qfalse ); amp = atof( token );
1113 VectorScale( amt, base, mins );
1114 VectorMA( mins, amp, amt, maxs );
1115 VectorAdd( si->mins, mins, si->mins );
1116 VectorAdd( si->maxs, maxs, si->maxs );
1120 /* light <value> (old-style flare specification) */
1121 else if ( !Q_stricmp( token, "light" ) ) {
1122 GetTokenAppend( shaderText, qfalse );
1123 si->flareShader = game->flareShader;
1126 /* ydnar: damageShader <shader> <health> (sof2 mods) */
1127 else if ( !Q_stricmp( token, "damageShader" ) ) {
1128 GetTokenAppend( shaderText, qfalse );
1129 if ( token[ 0 ] != '\0' ) {
1130 si->damageShader = safe_malloc( strlen( token ) + 1 );
1131 strcpy( si->damageShader, token );
1133 GetTokenAppend( shaderText, qfalse ); /* don't do anything with health */
1136 /* ydnar: enemy territory implicit shaders */
1137 else if ( !Q_stricmp( token, "implicitMap" ) ) {
1138 si->implicitMap = IM_OPAQUE;
1139 GetTokenAppend( shaderText, qfalse );
1140 if ( token[ 0 ] == '-' && token[ 1 ] == '\0' ) {
1141 sprintf( si->implicitImagePath, "%s.tga", si->shader );
1144 strcpy( si->implicitImagePath, token );
1148 else if ( !Q_stricmp( token, "implicitMask" ) ) {
1149 si->implicitMap = IM_MASKED;
1150 GetTokenAppend( shaderText, qfalse );
1151 if ( token[ 0 ] == '-' && token[ 1 ] == '\0' ) {
1152 sprintf( si->implicitImagePath, "%s.tga", si->shader );
1155 strcpy( si->implicitImagePath, token );
1159 else if ( !Q_stricmp( token, "implicitBlend" ) ) {
1160 si->implicitMap = IM_MASKED;
1161 GetTokenAppend( shaderText, qfalse );
1162 if ( token[ 0 ] == '-' && token[ 1 ] == '\0' ) {
1163 sprintf( si->implicitImagePath, "%s.tga", si->shader );
1166 strcpy( si->implicitImagePath, token );
1171 /* -----------------------------------------------------------------
1173 ----------------------------------------------------------------- */
1175 /* qer_editorimage <image> */
1176 else if ( !Q_stricmp( token, "qer_editorImage" ) ) {
1177 GetTokenAppend( shaderText, qfalse );
1178 strcpy( si->editorImagePath, token );
1179 DefaultExtension( si->editorImagePath, ".tga" );
1182 /* ydnar: q3map_normalimage <image> (bumpmapping normal map) */
1183 else if ( !Q_stricmp( token, "q3map_normalImage" ) ) {
1184 GetTokenAppend( shaderText, qfalse );
1185 strcpy( si->normalImagePath, token );
1186 DefaultExtension( si->normalImagePath, ".tga" );
1189 /* q3map_lightimage <image> */
1190 else if ( !Q_stricmp( token, "q3map_lightImage" ) ) {
1191 GetTokenAppend( shaderText, qfalse );
1192 strcpy( si->lightImagePath, token );
1193 DefaultExtension( si->lightImagePath, ".tga" );
1196 /* ydnar: skyparms <outer image> <cloud height> <inner image> */
1197 else if ( !Q_stricmp( token, "skyParms" ) ) {
1198 /* get image base */
1199 GetTokenAppend( shaderText, qfalse );
1201 /* ignore bogus paths */
1202 if ( Q_stricmp( token, "-" ) && Q_stricmp( token, "full" ) ) {
1203 strcpy( si->skyParmsImageBase, token );
1205 /* use top image as sky light image */
1206 if ( si->lightImagePath[ 0 ] == '\0' ) {
1207 sprintf( si->lightImagePath, "%s_up.tga", si->skyParmsImageBase );
1211 /* skip rest of line */
1212 GetTokenAppend( shaderText, qfalse );
1213 GetTokenAppend( shaderText, qfalse );
1216 /* -----------------------------------------------------------------
1218 ----------------------------------------------------------------- */
1220 /* q3map_sun <red> <green> <blue> <intensity> <degrees> <elevation>
1221 color will be normalized, so it doesn't matter what range you use
1222 intensity falls off with angle but not distance 100 is a fairly bright sun
1223 degree of 0 = from the east, 90 = north, etc. altitude of 0 = sunrise/set, 90 = noon
1224 ydnar: sof2map has bareword 'sun' token, so we support that as well */
1225 else if ( !Q_stricmp( token, "sun" ) /* sof2 */ || !Q_stricmp( token, "q3map_sun" ) || !Q_stricmp( token, "q3map_sunExt" ) ) {
1231 /* ydnar: extended sun directive? */
1232 if ( !Q_stricmp( token, "q3map_sunext" ) ) {
1237 sun = safe_malloc( sizeof( *sun ) );
1238 memset( sun, 0, sizeof( *sun ) );
1241 sun->style = si->lightStyle;
1244 GetTokenAppend( shaderText, qfalse );
1245 sun->color[ 0 ] = atof( token );
1246 GetTokenAppend( shaderText, qfalse );
1247 sun->color[ 1 ] = atof( token );
1248 GetTokenAppend( shaderText, qfalse );
1249 sun->color[ 2 ] = atof( token );
1252 VectorNormalize( sun->color, sun->color );
1254 /* scale color by brightness */
1255 GetTokenAppend( shaderText, qfalse );
1256 sun->photons = atof( token );
1258 /* get sun angle/elevation */
1259 GetTokenAppend( shaderText, qfalse );
1261 a = a / 180.0f * Q_PI;
1263 GetTokenAppend( shaderText, qfalse );
1265 b = b / 180.0f * Q_PI;
1267 sun->direction[ 0 ] = cos( a ) * cos( b );
1268 sun->direction[ 1 ] = sin( a ) * cos( b );
1269 sun->direction[ 2 ] = sin( b );
1271 /* get filter radius from shader */
1272 sun->filterRadius = si->lightFilterRadius;
1274 /* ydnar: get sun angular deviance/samples */
1275 if ( ext && TokenAvailable() ) {
1276 GetTokenAppend( shaderText, qfalse );
1277 sun->deviance = atof( token );
1278 sun->deviance = sun->deviance / 180.0f * Q_PI;
1280 GetTokenAppend( shaderText, qfalse );
1281 sun->numSamples = atoi( token );
1285 sun->next = si->sun;
1288 /* apply sky surfaceparm */
1289 ApplySurfaceParm( "sky", &si->contentFlags, &si->surfaceFlags, &si->compileFlags );
1291 /* don't process any more tokens on this line */
1296 else if ( !Q_strncasecmp( token, "q3map_", 6 ) ) {
1297 /* ydnar: q3map_baseShader <shader> (inherit this shader's parameters) */
1298 if ( !Q_stricmp( token, "q3map_baseShader" ) ) {
1300 qboolean oldWarnImage;
1304 GetTokenAppend( shaderText, qfalse );
1305 //% Sys_FPrintf( SYS_VRB, "Shader %s has base shader %s\n", si->shader, token );
1306 oldWarnImage = warnImage;
1308 si2 = ShaderInfoForShader( token );
1309 warnImage = oldWarnImage;
1312 if ( si2 != NULL ) {
1314 strcpy( temp, si->shader );
1317 memcpy( si, si2, sizeof( *si ) );
1319 /* restore name and set to unfinished */
1320 strcpy( si->shader, temp );
1321 si->shaderWidth = 0;
1322 si->shaderHeight = 0;
1323 si->finished = qfalse;
1327 /* ydnar: q3map_surfacemodel <path to model> <density> <min scale> <max scale> <min angle> <max angle> <oriented (0 or 1)> */
1328 else if ( !Q_stricmp( token, "q3map_surfacemodel" ) ) {
1329 surfaceModel_t *model;
1332 /* allocate new model and attach it */
1333 model = safe_malloc( sizeof( *model ) );
1334 memset( model, 0, sizeof( *model ) );
1335 model->next = si->surfaceModel;
1336 si->surfaceModel = model;
1338 /* get parameters */
1339 GetTokenAppend( shaderText, qfalse );
1340 strcpy( model->model, token );
1342 GetTokenAppend( shaderText, qfalse );
1343 model->density = atof( token );
1344 GetTokenAppend( shaderText, qfalse );
1345 model->odds = atof( token );
1347 GetTokenAppend( shaderText, qfalse );
1348 model->minScale = atof( token );
1349 GetTokenAppend( shaderText, qfalse );
1350 model->maxScale = atof( token );
1352 GetTokenAppend( shaderText, qfalse );
1353 model->minAngle = atof( token );
1354 GetTokenAppend( shaderText, qfalse );
1355 model->maxAngle = atof( token );
1357 GetTokenAppend( shaderText, qfalse );
1358 model->oriented = ( token[ 0 ] == '1' ? qtrue : qfalse );
1361 /* ydnar/sd: q3map_foliage <path to model> <scale> <density> <odds> <invert alpha (1 or 0)> */
1362 else if ( !Q_stricmp( token, "q3map_foliage" ) ) {
1366 /* allocate new foliage struct and attach it */
1367 foliage = safe_malloc( sizeof( *foliage ) );
1368 memset( foliage, 0, sizeof( *foliage ) );
1369 foliage->next = si->foliage;
1370 si->foliage = foliage;
1372 /* get parameters */
1373 GetTokenAppend( shaderText, qfalse );
1374 strcpy( foliage->model, token );
1376 GetTokenAppend( shaderText, qfalse );
1377 foliage->scale = atof( token );
1378 GetTokenAppend( shaderText, qfalse );
1379 foliage->density = atof( token );
1380 GetTokenAppend( shaderText, qfalse );
1381 foliage->odds = atof( token );
1382 GetTokenAppend( shaderText, qfalse );
1383 foliage->inverseAlpha = atoi( token );
1386 /* ydnar: q3map_bounce <value> (fraction of light to re-emit during radiosity passes) */
1387 else if ( !Q_stricmp( token, "q3map_bounce" ) || !Q_stricmp( token, "q3map_bounceScale" ) ) {
1388 GetTokenAppend( shaderText, qfalse );
1389 si->bounceScale = atof( token );
1392 /* ydnar/splashdamage: q3map_skyLight <value> <iterations> */
1393 else if ( !Q_stricmp( token, "q3map_skyLight" ) ) {
1394 GetTokenAppend( shaderText, qfalse );
1395 si->skyLightValue = atof( token );
1396 GetTokenAppend( shaderText, qfalse );
1397 si->skyLightIterations = atoi( token );
1400 if ( si->skyLightValue < 0.0f ) {
1401 si->skyLightValue = 0.0f;
1403 if ( si->skyLightIterations < 2 ) {
1404 si->skyLightIterations = 2;
1408 /* q3map_surfacelight <value> */
1409 else if ( !Q_stricmp( token, "q3map_surfacelight" ) ) {
1410 GetTokenAppend( shaderText, qfalse );
1411 si->value = atof( token );
1414 /* q3map_lightStyle (sof2/jk2 lightstyle) */
1415 else if ( !Q_stricmp( token, "q3map_lightStyle" ) ) {
1416 GetTokenAppend( shaderText, qfalse );
1417 val = atoi( token );
1421 else if ( val > LS_NONE ) {
1424 si->lightStyle = val;
1427 /* wolf: q3map_lightRGB <red> <green> <blue> */
1428 else if ( !Q_stricmp( token, "q3map_lightRGB" ) ) {
1429 VectorClear( si->color );
1430 GetTokenAppend( shaderText, qfalse );
1431 si->color[ 0 ] = atof( token );
1432 GetTokenAppend( shaderText, qfalse );
1433 si->color[ 1 ] = atof( token );
1434 GetTokenAppend( shaderText, qfalse );
1435 si->color[ 2 ] = atof( token );
1436 ColorNormalize( si->color, si->color );
1439 /* q3map_lightSubdivide <value> */
1440 else if ( !Q_stricmp( token, "q3map_lightSubdivide" ) ) {
1441 GetTokenAppend( shaderText, qfalse );
1442 si->lightSubdivide = atoi( token );
1445 /* q3map_backsplash <percent> <distance> */
1446 else if ( !Q_stricmp( token, "q3map_backsplash" ) ) {
1447 GetTokenAppend( shaderText, qfalse );
1448 si->backsplashFraction = atof( token ) * 0.01f;
1449 GetTokenAppend( shaderText, qfalse );
1450 si->backsplashDistance = atof( token );
1453 /* q3map_lightmapSampleSize <value> */
1454 else if ( !Q_stricmp( token, "q3map_lightmapSampleSize" ) ) {
1455 GetTokenAppend( shaderText, qfalse );
1456 si->lightmapSampleSize = atoi( token );
1459 /* q3map_lightmapSampleSffset <value> */
1460 else if ( !Q_stricmp( token, "q3map_lightmapSampleOffset" ) ) {
1461 GetTokenAppend( shaderText, qfalse );
1462 si->lightmapSampleOffset = atof( token );
1465 /* ydnar: q3map_lightmapFilterRadius <self> <other> */
1466 else if ( !Q_stricmp( token, "q3map_lightmapFilterRadius" ) ) {
1467 GetTokenAppend( shaderText, qfalse );
1468 si->lmFilterRadius = atof( token );
1469 GetTokenAppend( shaderText, qfalse );
1470 si->lightFilterRadius = atof( token );
1473 /* ydnar: q3map_lightmapAxis [xyz] */
1474 else if ( !Q_stricmp( token, "q3map_lightmapAxis" ) ) {
1475 GetTokenAppend( shaderText, qfalse );
1476 if ( !Q_stricmp( token, "x" ) ) {
1477 VectorSet( si->lightmapAxis, 1, 0, 0 );
1479 else if ( !Q_stricmp( token, "y" ) ) {
1480 VectorSet( si->lightmapAxis, 0, 1, 0 );
1482 else if ( !Q_stricmp( token, "z" ) ) {
1483 VectorSet( si->lightmapAxis, 0, 0, 1 );
1487 Sys_Printf( "WARNING: Unknown value for lightmap axis: %s\n", token );
1488 VectorClear( si->lightmapAxis );
1492 /* ydnar: q3map_lightmapSize <width> <height> (for autogenerated shaders + external tga lightmaps) */
1493 else if ( !Q_stricmp( token, "q3map_lightmapSize" ) ) {
1494 GetTokenAppend( shaderText, qfalse );
1495 si->lmCustomWidth = atoi( token );
1496 GetTokenAppend( shaderText, qfalse );
1497 si->lmCustomHeight = atoi( token );
1499 /* must be a power of 2 */
1500 if ( ( ( si->lmCustomWidth - 1 ) & si->lmCustomWidth ) ||
1501 ( ( si->lmCustomHeight - 1 ) & si->lmCustomHeight ) ) {
1502 Sys_Printf( "WARNING: Non power-of-two lightmap size specified (%d, %d)\n",
1503 si->lmCustomWidth, si->lmCustomHeight );
1504 si->lmCustomWidth = lmCustomSize;
1505 si->lmCustomHeight = lmCustomSize;
1509 /* ydnar: q3map_lightmapBrightness N (for autogenerated shaders + external tga lightmaps) */
1510 else if ( !Q_stricmp( token, "q3map_lightmapBrightness" ) || !Q_stricmp( token, "q3map_lightmapGamma" ) ) {
1511 GetTokenAppend( shaderText, qfalse );
1512 si->lmBrightness = atof( token );
1513 if ( si->lmBrightness < 0 ) {
1514 si->lmBrightness = 1.0;
1518 /* q3map_vertexScale (scale vertex lighting by this fraction) */
1519 else if ( !Q_stricmp( token, "q3map_vertexScale" ) ) {
1520 GetTokenAppend( shaderText, qfalse );
1521 si->vertexScale = atof( token );
1524 /* q3map_noVertexLight */
1525 else if ( !Q_stricmp( token, "q3map_noVertexLight" ) ) {
1526 si->noVertexLight = qtrue;
1529 /* q3map_flare[Shader] <shader> */
1530 else if ( !Q_stricmp( token, "q3map_flare" ) || !Q_stricmp( token, "q3map_flareShader" ) ) {
1531 GetTokenAppend( shaderText, qfalse );
1532 if ( token[ 0 ] != '\0' ) {
1533 si->flareShader = safe_malloc( strlen( token ) + 1 );
1534 strcpy( si->flareShader, token );
1538 /* q3map_backShader <shader> */
1539 else if ( !Q_stricmp( token, "q3map_backShader" ) ) {
1540 GetTokenAppend( shaderText, qfalse );
1541 if ( token[ 0 ] != '\0' ) {
1542 si->backShader = safe_malloc( strlen( token ) + 1 );
1543 strcpy( si->backShader, token );
1547 /* ydnar: q3map_cloneShader <shader> */
1548 else if ( !Q_stricmp( token, "q3map_cloneShader" ) ) {
1549 GetTokenAppend( shaderText, qfalse );
1550 if ( token[ 0 ] != '\0' ) {
1551 si->cloneShader = safe_malloc( strlen( token ) + 1 );
1552 strcpy( si->cloneShader, token );
1556 /* q3map_remapShader <shader> */
1557 else if ( !Q_stricmp( token, "q3map_remapShader" ) ) {
1558 GetTokenAppend( shaderText, qfalse );
1559 if ( token[ 0 ] != '\0' ) {
1560 si->remapShader = safe_malloc( strlen( token ) + 1 );
1561 strcpy( si->remapShader, token );
1565 /* ydnar: q3map_offset <value> */
1566 else if ( !Q_stricmp( token, "q3map_offset" ) ) {
1567 GetTokenAppend( shaderText, qfalse );
1568 si->offset = atof( token );
1571 /* ydnar: q3map_textureSize <width> <height> (substitute for q3map_lightimage derivation for terrain) */
1572 else if ( !Q_stricmp( token, "q3map_fur" ) ) {
1573 GetTokenAppend( shaderText, qfalse );
1574 si->furNumLayers = atoi( token );
1575 GetTokenAppend( shaderText, qfalse );
1576 si->furOffset = atof( token );
1577 GetTokenAppend( shaderText, qfalse );
1578 si->furFade = atof( token );
1581 /* ydnar: gs mods: legacy support for terrain/terrain2 shaders */
1582 else if ( !Q_stricmp( token, "q3map_terrain" ) ) {
1583 /* team arena terrain is assumed to be nonplanar, with full normal averaging,
1584 passed through the metatriangle surface pipeline, with a lightmap axis on z */
1585 si->legacyTerrain = qtrue;
1587 si->notjunc = qtrue;
1588 si->indexed = qtrue;
1589 si->nonplanar = qtrue;
1590 si->forceMeta = qtrue;
1591 si->shadeAngleDegrees = 179.0f;
1592 //% VectorSet( si->lightmapAxis, 0, 0, 1 ); /* ydnar 2002-09-21: turning this off for better lightmapping of cliff faces */
1595 /* ydnar: picomodel: q3map_forceMeta (forces brush faces and/or triangle models to go through the metasurface pipeline) */
1596 else if ( !Q_stricmp( token, "q3map_forceMeta" ) ) {
1597 si->forceMeta = qtrue;
1600 /* ydnar: gs mods: q3map_shadeAngle <degrees> */
1601 else if ( !Q_stricmp( token, "q3map_shadeAngle" ) ) {
1602 GetTokenAppend( shaderText, qfalse );
1603 si->shadeAngleDegrees = atof( token );
1606 /* ydnar: q3map_textureSize <width> <height> (substitute for q3map_lightimage derivation for terrain) */
1607 else if ( !Q_stricmp( token, "q3map_textureSize" ) ) {
1608 GetTokenAppend( shaderText, qfalse );
1609 si->shaderWidth = atoi( token );
1610 GetTokenAppend( shaderText, qfalse );
1611 si->shaderHeight = atoi( token );
1614 /* ydnar: gs mods: q3map_tcGen <style> <parameters> */
1615 else if ( !Q_stricmp( token, "q3map_tcGen" ) ) {
1617 GetTokenAppend( shaderText, qfalse );
1619 /* q3map_tcGen vector <s vector> <t vector> */
1620 if ( !Q_stricmp( token, "vector" ) ) {
1621 Parse1DMatrixAppend( shaderText, 3, si->vecs[ 0 ] );
1622 Parse1DMatrixAppend( shaderText, 3, si->vecs[ 1 ] );
1625 /* q3map_tcGen ivector <1.0/s vector> <1.0/t vector> (inverse vector, easier for mappers to understand) */
1626 else if ( !Q_stricmp( token, "ivector" ) ) {
1627 Parse1DMatrixAppend( shaderText, 3, si->vecs[ 0 ] );
1628 Parse1DMatrixAppend( shaderText, 3, si->vecs[ 1 ] );
1629 for ( i = 0; i < 3; i++ )
1631 si->vecs[ 0 ][ i ] = si->vecs[ 0 ][ i ] ? 1.0 / si->vecs[ 0 ][ i ] : 0;
1632 si->vecs[ 1 ][ i ] = si->vecs[ 1 ][ i ] ? 1.0 / si->vecs[ 1 ][ i ] : 0;
1637 Sys_Printf( "WARNING: Unknown q3map_tcGen method: %s\n", token );
1638 VectorClear( si->vecs[ 0 ] );
1639 VectorClear( si->vecs[ 1 ] );
1643 /* ydnar: gs mods: q3map_[color|rgb|alpha][Gen|Mod] <style> <parameters> */
1644 else if ( !Q_stricmp( token, "q3map_colorGen" ) || !Q_stricmp( token, "q3map_colorMod" ) ||
1645 !Q_stricmp( token, "q3map_rgbGen" ) || !Q_stricmp( token, "q3map_rgbMod" ) ||
1646 !Q_stricmp( token, "q3map_alphaGen" ) || !Q_stricmp( token, "q3map_alphaMod" ) ) {
1647 colorMod_t *cm, *cm2;
1651 /* alphamods are colormod + 1 */
1652 alpha = ( !Q_stricmp( token, "q3map_alphaGen" ) || !Q_stricmp( token, "q3map_alphaMod" ) ) ? 1 : 0;
1654 /* allocate new colormod */
1655 cm = safe_malloc( sizeof( *cm ) );
1656 memset( cm, 0, sizeof( *cm ) );
1658 /* attach to shader */
1659 if ( si->colorMod == NULL ) {
1664 for ( cm2 = si->colorMod; cm2 != NULL; cm2 = cm2->next )
1666 if ( cm2->next == NULL ) {
1674 GetTokenAppend( shaderText, qfalse );
1676 /* alpha set|const A */
1677 if ( alpha && ( !Q_stricmp( token, "set" ) || !Q_stricmp( token, "const" ) ) ) {
1678 cm->type = CM_ALPHA_SET;
1679 GetTokenAppend( shaderText, qfalse );
1680 cm->data[ 0 ] = atof( token );
1683 /* color|rgb set|const ( X Y Z ) */
1684 else if ( !Q_stricmp( token, "set" ) || !Q_stricmp( token, "const" ) ) {
1685 cm->type = CM_COLOR_SET;
1686 Parse1DMatrixAppend( shaderText, 3, cm->data );
1690 else if ( alpha && !Q_stricmp( token, "scale" ) ) {
1691 cm->type = CM_ALPHA_SCALE;
1692 GetTokenAppend( shaderText, qfalse );
1693 cm->data[ 0 ] = atof( token );
1696 /* color|rgb scale ( X Y Z ) */
1697 else if ( !Q_stricmp( token, "scale" ) ) {
1698 cm->type = CM_COLOR_SCALE;
1699 Parse1DMatrixAppend( shaderText, 3, cm->data );
1702 /* dotProduct ( X Y Z ) */
1703 else if ( !Q_stricmp( token, "dotProduct" ) ) {
1704 cm->type = CM_COLOR_DOT_PRODUCT + alpha;
1705 Parse1DMatrixAppend( shaderText, 3, cm->data );
1708 /* dotProduct2 ( X Y Z ) */
1709 else if ( !Q_stricmp( token, "dotProduct2" ) ) {
1710 cm->type = CM_COLOR_DOT_PRODUCT_2 + alpha;
1711 Parse1DMatrixAppend( shaderText, 3, cm->data );
1715 else if ( !Q_stricmp( token, "volume" ) ) {
1716 /* special stub mode for flagging volume brushes */
1717 cm->type = CM_VOLUME;
1722 Sys_Printf( "WARNING: Unknown colorMod method: %s\n", token );
1726 /* ydnar: gs mods: q3map_tcMod <style> <parameters> */
1727 else if ( !Q_stricmp( token, "q3map_tcMod" ) ) {
1731 GetTokenAppend( shaderText, qfalse );
1733 /* q3map_tcMod [translate | shift | offset] <s> <t> */
1734 if ( !Q_stricmp( token, "translate" ) || !Q_stricmp( token, "shift" ) || !Q_stricmp( token, "offset" ) ) {
1735 GetTokenAppend( shaderText, qfalse );
1737 GetTokenAppend( shaderText, qfalse );
1740 TCModTranslate( si->mod, a, b );
1743 /* q3map_tcMod scale <s> <t> */
1744 else if ( !Q_stricmp( token, "scale" ) ) {
1745 GetTokenAppend( shaderText, qfalse );
1747 GetTokenAppend( shaderText, qfalse );
1750 TCModScale( si->mod, a, b );
1753 /* q3map_tcMod rotate <s> <t> (fixme: make this communitive) */
1754 else if ( !Q_stricmp( token, "rotate" ) ) {
1755 GetTokenAppend( shaderText, qfalse );
1757 TCModRotate( si->mod, a );
1760 Sys_Printf( "WARNING: Unknown q3map_tcMod method: %s\n", token );
1764 /* q3map_fogDir (direction a fog shader fades from transparent to opaque) */
1765 else if ( !Q_stricmp( token, "q3map_fogDir" ) ) {
1766 Parse1DMatrixAppend( shaderText, 3, si->fogDir );
1767 VectorNormalize( si->fogDir, si->fogDir );
1770 /* q3map_globaltexture */
1771 else if ( !Q_stricmp( token, "q3map_globaltexture" ) ) {
1772 si->globalTexture = qtrue;
1775 /* ydnar: gs mods: q3map_nonplanar (make it a nonplanar merge candidate for meta surfaces) */
1776 else if ( !Q_stricmp( token, "q3map_nonplanar" ) ) {
1777 si->nonplanar = qtrue;
1780 /* ydnar: gs mods: q3map_noclip (preserve original face winding, don't clip by bsp tree) */
1781 else if ( !Q_stricmp( token, "q3map_noclip" ) ) {
1786 else if ( !Q_stricmp( token, "q3map_notjunc" ) ) {
1787 si->notjunc = qtrue;
1791 else if ( !Q_stricmp( token, "q3map_nofog" ) ) {
1795 /* ydnar: gs mods: q3map_indexed (for explicit terrain-style indexed mapping) */
1796 else if ( !Q_stricmp( token, "q3map_indexed" ) ) {
1797 si->indexed = qtrue;
1800 /* ydnar: q3map_invert (inverts a drawsurface's facing) */
1801 else if ( !Q_stricmp( token, "q3map_invert" ) ) {
1805 /* ydnar: gs mods: q3map_lightmapMergable (ok to merge non-planar */
1806 else if ( !Q_stricmp( token, "q3map_lightmapMergable" ) ) {
1807 si->lmMergable = qtrue;
1810 /* ydnar: q3map_nofast */
1811 else if ( !Q_stricmp( token, "q3map_noFast" ) ) {
1815 /* q3map_patchshadows */
1816 else if ( !Q_stricmp( token, "q3map_patchShadows" ) ) {
1817 si->patchShadows = qtrue;
1820 /* q3map_vertexshadows */
1821 else if ( !Q_stricmp( token, "q3map_vertexShadows" ) ) {
1822 si->vertexShadows = qtrue; /* ydnar */
1825 /* q3map_novertexshadows */
1826 else if ( !Q_stricmp( token, "q3map_noVertexShadows" ) ) {
1827 si->vertexShadows = qfalse; /* ydnar */
1830 /* q3map_splotchfix (filter dark lightmap luxels on lightmapped models) */
1831 else if ( !Q_stricmp( token, "q3map_splotchfix" ) ) {
1832 si->splotchFix = qtrue; /* ydnar */
1835 /* q3map_forcesunlight */
1836 else if ( !Q_stricmp( token, "q3map_forceSunlight" ) ) {
1837 si->forceSunlight = qtrue;
1840 /* q3map_onlyvertexlighting (sof2) */
1841 else if ( !Q_stricmp( token, "q3map_onlyVertexLighting" ) ) {
1842 ApplySurfaceParm( "pointlight", &si->contentFlags, &si->surfaceFlags, &si->compileFlags );
1845 /* q3map_material (sof2) */
1846 else if ( !Q_stricmp( token, "q3map_material" ) ) {
1847 GetTokenAppend( shaderText, qfalse );
1848 sprintf( temp, "*mat_%s", token );
1849 if ( ApplySurfaceParm( temp, &si->contentFlags, &si->surfaceFlags, &si->compileFlags ) == qfalse ) {
1850 Sys_Printf( "WARNING: Unknown material \"%s\"\n", token );
1854 /* ydnar: q3map_clipmodel (autogenerate clip brushes for model triangles using this shader) */
1855 else if ( !Q_stricmp( token, "q3map_clipmodel" ) ) {
1856 si->clipModel = qtrue;
1859 /* ydnar: q3map_styleMarker[2] */
1860 else if ( !Q_stricmp( token, "q3map_styleMarker" ) ) {
1861 si->styleMarker = 1;
1863 else if ( !Q_stricmp( token, "q3map_styleMarker2" ) ) { /* uses depthFunc equal */
1864 si->styleMarker = 2;
1867 /* ydnar: default to searching for q3map_<surfaceparm> */
1870 //% Sys_FPrintf( SYS_VRB, "Attempting to match %s with a known surfaceparm\n", token );
1871 if ( ApplySurfaceParm( &token[ 6 ], &si->contentFlags, &si->surfaceFlags, &si->compileFlags ) == qfalse ) {
1872 ; //% Sys_Printf( "WARNING: Unknown q3map_* directive \"%s\"\n", token );
1878 /* -----------------------------------------------------------------
1880 ----------------------------------------------------------------- */
1882 /* ignore all other tokens on the line */
1883 while ( TokenAvailable() && GetTokenAppend( shaderText, qfalse ) ) ;
1891 ParseCustomInfoParms() - rr2do2
1892 loads custom info parms file for mods
1895 static void ParseCustomInfoParms( void ){
1896 qboolean parsedContent, parsedSurface;
1900 if ( vfsGetFileCount( "scripts/custinfoparms.txt" ) == 0 ) {
1905 LoadScriptFile( "scripts/custinfoparms.txt", 0 );
1907 /* clear the array */
1908 memset( custSurfaceParms, 0, sizeof( custSurfaceParms ) );
1909 numCustSurfaceParms = 0;
1910 parsedContent = parsedSurface = qfalse;
1912 /* parse custom contentflags */
1916 if ( !GetToken( qtrue ) ) {
1920 if ( !strcmp( token, "}" ) ) {
1921 parsedContent = qtrue;
1925 custSurfaceParms[ numCustSurfaceParms ].name = safe_malloc( MAX_OS_PATH );
1926 strcpy( custSurfaceParms[ numCustSurfaceParms ].name, token );
1928 sscanf( token, "%x", &custSurfaceParms[ numCustSurfaceParms ].contentFlags );
1929 numCustSurfaceParms++;
1933 if ( !parsedContent ) {
1934 Sys_Printf( "WARNING: Couldn't find valid custom contentsflag section\n" );
1938 /* parse custom surfaceflags */
1942 if ( !GetToken( qtrue ) ) {
1946 if ( !strcmp( token, "}" ) ) {
1947 parsedSurface = qtrue;
1951 custSurfaceParms[ numCustSurfaceParms ].name = safe_malloc( MAX_OS_PATH );
1952 strcpy( custSurfaceParms[ numCustSurfaceParms ].name, token );
1954 sscanf( token, "%x", &custSurfaceParms[ numCustSurfaceParms ].surfaceFlags );
1955 numCustSurfaceParms++;
1959 if ( !parsedContent ) {
1960 Sys_Printf( "WARNING: Couldn't find valid custom surfaceflag section\n" );
1968 the shaders are parsed out of shaderlist.txt from a main directory
1969 that is, if using -fs_game we ignore the shader scripts that might be in baseq3/
1970 on linux there's an additional twist, we actually merge the stuff from ~/.q3a/ and from the base dir
1973 #define MAX_SHADER_FILES 1024
1975 void LoadShaderInfo( void ){
1976 int i, j, numShaderFiles, count;
1977 char filename[ 1024 ];
1978 char *shaderFiles[ MAX_SHADER_FILES ];
1981 /* rr2do2: parse custom infoparms first */
1982 if ( useCustomInfoParms ) {
1983 ParseCustomInfoParms();
1986 /* start with zero */
1989 /* we can pile up several shader files, the one in baseq3 and ones in the mod dir or other spots */
1990 sprintf( filename, "%s/shaderlist.txt", game->shaderPath );
1991 count = vfsGetFileCount( filename );
1994 for ( i = 0; i < count; i++ )
1996 /* load shader list */
1997 sprintf( filename, "%s/shaderlist.txt", game->shaderPath );
1998 LoadScriptFile( filename, i );
2001 while ( GetToken( qtrue ) )
2003 /* check for duplicate entries */
2004 for ( j = 0; j < numShaderFiles; j++ )
2005 if ( !strcmp( shaderFiles[ j ], token ) ) {
2010 if ( j >= MAX_SHADER_FILES ) {
2011 Error( "MAX_SHADER_FILES (%d) reached, trim your shaderlist.txt!", (int) MAX_SHADER_FILES );
2014 /* new shader file */
2015 if ( j == numShaderFiles ) {
2016 shaderFiles[ numShaderFiles ] = safe_malloc( MAX_OS_PATH );
2017 strcpy( shaderFiles[ numShaderFiles ], token );
2023 /* parse the shader files */
2024 for ( i = 0; i < numShaderFiles; i++ )
2026 sprintf( filename, "%s/%s.shader", game->shaderPath, shaderFiles[ i ] );
2027 ParseShaderFile( filename );
2028 free( shaderFiles[ i ] );
2031 /* emit some statistics */
2032 Sys_FPrintf( SYS_VRB, "%9d shaderInfo\n", numShaderInfo );