#include <string.h>
#include <math.h>
#include "cmdlib.h"
#include "mathlib.h"
#include "imagelib.h"
#include "scriplib.h"
#include "../code/qcommon/qfiles.h"
#include "../code/game/surfaceflags.h"
#include "shaders.h"
Include dependency graph for shaders.c:

Go to the source code of this file.
Data Structures | |
| struct | infoParm_t |
Defines | |
| #define | DEFAULT_BACKSPLASH_DISTANCE 24 |
| #define | DEFAULT_BACKSPLASH_FRACTION 0.05 |
| #define | MAX_SHADER_FILES 64 |
| #define | MAX_SURFACE_INFO 4096 |
Functions | |
| shaderInfo_t * | AllocShaderInfo (void) |
| byte * | LoadImageFile (char *filename, qboolean *bTGA) |
| void | LoadShaderImage (shaderInfo_t *si) |
| void | LoadShaderInfo (void) |
| void | ParseShaderFile (const char *filename) |
| shaderInfo_t * | ShaderInfoForShader (const char *shaderName) |
Variables | |
| shaderInfo_t | defaultInfo |
| infoParm_t | infoParms [] |
| int | numShaderInfo |
| shaderInfo_t | shaderInfo [MAX_SURFACE_INFO] |
|
|
|
|
|
|
|
|
|
|
|
|
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 121 of file shaders.c. References buffer, byte, FileExists(), LoadFileBlock(), PakLoadAnyFile(), and strlen(). Referenced by LoadShaderImage(). 00122 {
00123 byte *buffer = NULL;
00124 int nLen = 0;
00125 *bTGA = qtrue;
00126 if (FileExists(filename))
00127 {
00128 LoadFileBlock(filename, &buffer);
00129 }
00130 #ifdef _WIN32
00131 else
00132 {
00133 PakLoadAnyFile(filename, &buffer);
00134 }
00135 #endif
00136 if ( buffer == NULL)
00137 {
00138 nLen = strlen(filename);
00139 filename[nLen-3] = 'j';
00140 filename[nLen-2] = 'p';
00141 filename[nLen-1] = 'g';
00142 if (FileExists(filename))
00143 {
00144 LoadFileBlock(filename, &buffer);
00145 }
00146 #ifdef _WIN32
00147 else
00148 {
00149 PakLoadAnyFile(filename, &buffer);
00150 }
00151 #endif
00152 if ( buffer )
00153 {
00154 *bTGA = qfalse;
00155 }
00156 }
00157 return buffer;
00158 }
|
Here is the call graph for this function:

|
|
Definition at line 165 of file shaders.c. References _printf(), shaderInfo_s::averageColor, buffer, byte, shaderInfo_s::color, ColorNormalize(), count, DefaultExtension(), shaderInfo_s::editorimage, free(), gamedir, shaderInfo_s::height, i, shaderInfo_s::lightimage, LoadImageFile(), LoadJPGBuff(), LoadTGABuffer(), malloc(), memset(), shaderInfo_s::pixels, qboolean, shaderInfo_s::shader, shaderInfo_t, sprintf(), VectorClear, VectorScale, and shaderInfo_s::width. Referenced by ShaderInfoForShader(). 00165 {
00166 char filename[1024];
00167 int i, count;
00168 float color[4];
00169 byte *buffer;
00170 qboolean bTGA = qtrue;
00171
00172 // look for the lightimage if it is specified
00173 if ( si->lightimage[0] ) {
00174 sprintf( filename, "%s%s", gamedir, si->lightimage );
00175 DefaultExtension( filename, ".tga" );
00176 buffer = LoadImageFile(filename, &bTGA);
00177 if ( buffer != NULL) {
00178 goto loadTga;
00179 }
00180 }
00181
00182 // look for the editorimage if it is specified
00183 if ( si->editorimage[0] ) {
00184 sprintf( filename, "%s%s", gamedir, si->editorimage );
00185 DefaultExtension( filename, ".tga" );
00186 buffer = LoadImageFile(filename, &bTGA);
00187 if ( buffer != NULL) {
00188 goto loadTga;
00189 }
00190 }
00191
00192 // just try the shader name with a .tga
00193 // on unix, we have case sensitivity problems...
00194 sprintf( filename, "%s%s.tga", gamedir, si->shader );
00195 buffer = LoadImageFile(filename, &bTGA);
00196 if ( buffer != NULL) {
00197 goto loadTga;
00198 }
00199
00200 sprintf( filename, "%s%s.TGA", gamedir, si->shader );
00201 buffer = LoadImageFile(filename, &bTGA);
00202 if ( buffer != NULL) {
00203 goto loadTga;
00204 }
00205
00206 // couldn't load anything
00207 _printf("WARNING: Couldn't find image for shader %s\n", si->shader );
00208
00209 si->color[0] = 1;
00210 si->color[1] = 1;
00211 si->color[2] = 1;
00212 si->width = 64;
00213 si->height = 64;
00214 si->pixels = malloc( si->width * si->height * 4 );
00215 memset ( si->pixels, 255, si->width * si->height * 4 );
00216 return;
00217
00218 // load the image to get dimensions and color
00219 loadTga:
00220 if ( bTGA) {
00221 LoadTGABuffer( buffer, &si->pixels, &si->width, &si->height );
00222 }
00223 else {
00224 #ifdef _WIN32
00225 LoadJPGBuff(buffer, &si->pixels, &si->width, &si->height );
00226 #endif
00227 }
00228
00229 free(buffer);
00230
00231 count = si->width * si->height;
00232
00233 VectorClear( color );
00234 color[ 3 ] = 0;
00235 for ( i = 0 ; i < count ; i++ ) {
00236 color[0] += si->pixels[ i * 4 + 0 ];
00237 color[1] += si->pixels[ i * 4 + 1 ];
00238 color[2] += si->pixels[ i * 4 + 2 ];
00239 color[3] += si->pixels[ i * 4 + 3 ];
00240 }
00241 ColorNormalize( color, si->color );
00242 VectorScale( color, 1.0/count, si->averageColor );
00243 }
|
Here is the call graph for this function:

|
|
Definition at line 581 of file shaders.c. References free(), gamedir, GetToken(), i, LoadScriptFile(), malloc(), MAX_OS_PATH, numShaderInfo, ParseShaderFile(), qprintf(), qtrue, sprintf(), and strcpy(). Referenced by LightMain(), main(), VLightMain(), and VSoundMain(). 00581 {
00582 char filename[1024];
00583 int i;
00584 char *shaderFiles[MAX_SHADER_FILES];
00585 int numShaderFiles;
00586
00587 sprintf( filename, "%sscripts/shaderlist.txt", gamedir );
00588 LoadScriptFile( filename );
00589
00590 numShaderFiles = 0;
00591 while ( 1 ) {
00592 if ( !GetToken( qtrue ) ) {
00593 break;
00594 }
00595 shaderFiles[numShaderFiles] = malloc(MAX_OS_PATH);
00596 strcpy( shaderFiles[ numShaderFiles ], token );
00597 numShaderFiles++;
00598 }
00599
00600 for ( i = 0 ; i < numShaderFiles ; i++ ) {
00601 sprintf( filename, "%sscripts/%s.shader", gamedir, shaderFiles[i] );
00602 ParseShaderFile( filename );
00603 free(shaderFiles[i]);
00604 }
00605
00606 qprintf( "%5i shaderInfo\n", numShaderInfo);
00607 }
|
Here is the call graph for this function:

|
|
Definition at line 317 of file shaders.c. References _printf(), a, AllocShaderInfo(), atof(), atoi, shaderInfo_s::autosprite, b, shaderInfo_s::backShader, shaderInfo_s::backsplashDistance, shaderInfo_s::backsplashFraction, infoParm_t::clearSolid, infoParm_t::contents, shaderInfo_s::contents, cos(), DefaultExtension(), shaderInfo_s::editorimage, shaderInfo_s::flareShader, shaderInfo_s::forceSunLight, shaderInfo_s::forceTraceLight, shaderInfo_s::forceVLight, GetToken(), shaderInfo_s::globalTexture, shaderInfo_s::hasPasses, i, infoParms, shaderInfo_s::lightimage, shaderInfo_s::lightmapSampleSize, shaderInfo_s::lightSubdivide, LoadScriptFile(), MatchToken(), name, shaderInfo_s::notjunc, shaderInfo_s::noVertexShadows, shaderInfo_s::patchShadows, Q_stricmp(), Q_strncasecmp(), qfalse, qtrue, shaderInfo_s::shader, shaderInfo_t, sin(), strcmp(), strcpy(), shaderInfo_s::subdivisions, shaderInfo_s::sunDirection, shaderInfo_s::sunLight, infoParm_t::surfaceFlags, shaderInfo_s::surfaceFlags, TokenAvailable(), shaderInfo_s::twoSided, shaderInfo_s::value, VectorNormalize(), VectorScale, shaderInfo_s::vertexScale, and shaderInfo_s::vertexShadows. Referenced by LoadShaderInfo(). 00317 {
00318 int i;
00319 int numInfoParms = sizeof(infoParms) / sizeof(infoParms[0]);
00320 shaderInfo_t *si;
00321
00322 // qprintf( "shaderFile: %s\n", filename );
00323 LoadScriptFile( filename );
00324 while ( 1 ) {
00325 if ( !GetToken( qtrue ) ) {
00326 break;
00327 }
00328
00329 si = AllocShaderInfo();
00330 strcpy( si->shader, token );
00331 MatchToken( "{" );
00332 while ( 1 ) {
00333 if ( !GetToken( qtrue ) ) {
00334 break;
00335 }
00336 if ( !strcmp( token, "}" ) ) {
00337 break;
00338 }
00339
00340 // skip internal braced sections
00341 if ( !strcmp( token, "{" ) ) {
00342 si->hasPasses = qtrue;
00343 while ( 1 ) {
00344 if ( !GetToken( qtrue ) ) {
00345 break;
00346 }
00347 if ( !strcmp( token, "}" ) ) {
00348 break;
00349 }
00350 }
00351 continue;
00352 }
00353
00354 if ( !Q_stricmp( token, "surfaceparm" ) ) {
00355 GetToken( qfalse );
00356 for ( i = 0 ; i < numInfoParms ; i++ ) {
00357 if ( !Q_stricmp( token, infoParms[i].name ) ) {
00358 si->surfaceFlags |= infoParms[i].surfaceFlags;
00359 si->contents |= infoParms[i].contents;
00360 if ( infoParms[i].clearSolid ) {
00361 si->contents &= ~CONTENTS_SOLID;
00362 }
00363 break;
00364 }
00365 }
00366 if ( i == numInfoParms ) {
00367 // we will silently ignore all tokens beginning with qer,
00368 // which are QuakeEdRadient parameters
00369 if ( Q_strncasecmp( token, "qer", 3 ) ) {
00370 _printf( "Unknown surfaceparm: \"%s\"\n", token );
00371 }
00372 }
00373 continue;
00374 }
00375
00376
00377 // qer_editorimage <image>
00378 if ( !Q_stricmp( token, "qer_editorimage" ) ) {
00379 GetToken( qfalse );
00380 strcpy( si->editorimage, token );
00381 DefaultExtension( si->editorimage, ".tga" );
00382 continue;
00383 }
00384
00385 // q3map_lightimage <image>
00386 if ( !Q_stricmp( token, "q3map_lightimage" ) ) {
00387 GetToken( qfalse );
00388 strcpy( si->lightimage, token );
00389 DefaultExtension( si->lightimage, ".tga" );
00390 continue;
00391 }
00392
00393 // q3map_surfacelight <value>
00394 if ( !Q_stricmp( token, "q3map_surfacelight" ) ) {
00395 GetToken( qfalse );
00396 si->value = atoi( token );
00397 continue;
00398 }
00399
00400 // q3map_lightsubdivide <value>
00401 if ( !Q_stricmp( token, "q3map_lightsubdivide" ) ) {
00402 GetToken( qfalse );
00403 si->lightSubdivide = atoi( token );
00404 continue;
00405 }
00406
00407 // q3map_lightmapsamplesize <value>
00408 if ( !Q_stricmp( token, "q3map_lightmapsamplesize" ) ) {
00409 GetToken( qfalse );
00410 si->lightmapSampleSize = atoi( token );
00411 continue;
00412 }
00413
00414 // q3map_tracelight
00415 if ( !Q_stricmp( token, "q3map_tracelight" ) ) {
00416 si->forceTraceLight = qtrue;
00417 continue;
00418 }
00419
00420 // q3map_vlight
00421 if ( !Q_stricmp( token, "q3map_vlight" ) ) {
00422 si->forceVLight = qtrue;
00423 continue;
00424 }
00425
00426 // q3map_patchshadows
00427 if ( !Q_stricmp( token, "q3map_patchshadows" ) ) {
00428 si->patchShadows = qtrue;
00429 continue;
00430 }
00431
00432 // q3map_vertexshadows
00433 if ( !Q_stricmp( token, "q3map_vertexshadows" ) ) {
00434 si->vertexShadows = qtrue;
00435 continue;
00436 }
00437
00438 // q3map_novertexshadows
00439 if ( !Q_stricmp( token, "q3map_novertexshadows" ) ) {
00440 si->noVertexShadows = qtrue;
00441 continue;
00442 }
00443
00444 // q3map_forcesunlight
00445 if ( !Q_stricmp( token, "q3map_forcesunlight" ) ) {
00446 si->forceSunLight = qtrue;
00447 continue;
00448 }
00449
00450 // q3map_vertexscale
00451 if ( !Q_stricmp( token, "q3map_vertexscale" ) ) {
00452 GetToken( qfalse );
00453 si->vertexScale = atof(token);
00454 continue;
00455 }
00456
00457 // q3map_notjunc
00458 if ( !Q_stricmp( token, "q3map_notjunc" ) ) {
00459 si->notjunc = qtrue;
00460 continue;
00461 }
00462
00463 // q3map_globaltexture
00464 if ( !Q_stricmp( token, "q3map_globaltexture" ) ) {
00465 si->globalTexture = qtrue;
00466 continue;
00467 }
00468
00469 // q3map_backsplash <percent> <distance>
00470 if ( !Q_stricmp( token, "q3map_backsplash" ) ) {
00471 GetToken( qfalse );
00472 si->backsplashFraction = atof( token ) * 0.01;
00473 GetToken( qfalse );
00474 si->backsplashDistance = atof( token );
00475 continue;
00476 }
00477
00478 // q3map_backshader <shader>
00479 if ( !Q_stricmp( token, "q3map_backshader" ) ) {
00480 GetToken( qfalse );
00481 strcpy( si->backShader, token );
00482 continue;
00483 }
00484
00485 // q3map_flare <shader>
00486 if ( !Q_stricmp( token, "q3map_flare" ) ) {
00487 GetToken( qfalse );
00488 strcpy( si->flareShader, token );
00489 continue;
00490 }
00491
00492 // light <value>
00493 // old style flare specification
00494 if ( !Q_stricmp( token, "light" ) ) {
00495 GetToken( qfalse );
00496 strcpy( si->flareShader, "flareshader" );
00497 continue;
00498 }
00499
00500 // q3map_sun <red> <green> <blue> <intensity> <degrees> <elivation>
00501 // color will be normalized, so it doesn't matter what range you use
00502 // intensity falls off with angle but not distance 100 is a fairly bright sun
00503 // degree of 0 = from the east, 90 = north, etc. altitude of 0 = sunrise/set, 90 = noon
00504 if ( !Q_stricmp( token, "q3map_sun" ) ) {
00505 float a, b;
00506
00507 GetToken( qfalse );
00508 si->sunLight[0] = atof( token );
00509 GetToken( qfalse );
00510 si->sunLight[1] = atof( token );
00511 GetToken( qfalse );
00512 si->sunLight[2] = atof( token );
00513
00514 VectorNormalize( si->sunLight, si->sunLight);
00515
00516 GetToken( qfalse );
00517 a = atof( token );
00518 VectorScale( si->sunLight, a, si->sunLight);
00519
00520 GetToken( qfalse );
00521 a = atof( token );
00522 a = a / 180 * Q_PI;
00523
00524 GetToken( qfalse );
00525 b = atof( token );
00526 b = b / 180 * Q_PI;
00527
00528 si->sunDirection[0] = cos( a ) * cos( b );
00529 si->sunDirection[1] = sin( a ) * cos( b );
00530 si->sunDirection[2] = sin( b );
00531
00532 si->surfaceFlags |= SURF_SKY;
00533 continue;
00534 }
00535
00536 // tesssize is used to force liquid surfaces to subdivide
00537 if ( !Q_stricmp( token, "tesssize" ) ) {
00538 GetToken( qfalse );
00539 si->subdivisions = atof( token );
00540 continue;
00541 }
00542
00543 // cull none will set twoSided
00544 if ( !Q_stricmp( token, "cull" ) ) {
00545 GetToken( qfalse );
00546 if ( !Q_stricmp( token, "none" ) ) {
00547 si->twoSided = qtrue;
00548 }
00549 continue;
00550 }
00551
00552
00553 // deformVertexes autosprite[2]
00554 // we catch this so autosprited surfaces become point
00555 // lights instead of area lights
00556 if ( !Q_stricmp( token, "deformVertexes" ) ) {
00557 GetToken( qfalse );
00558 if ( !Q_strncasecmp( token, "autosprite", 10 ) ) {
00559 si->autosprite = qtrue;
00560 si->contents = CONTENTS_DETAIL;
00561 }
00562 continue;
00563 }
00564
00565
00566 // ignore all other tokens on the line
00567
00568 while ( TokenAvailable() ) {
00569 GetToken( qfalse );
00570 }
00571 }
00572 }
00573 }
|
Here is the call graph for this function:

|
Here is the call graph for this function:

|
|
|
|
|
Initial value: {
{"water", 1, 0, CONTENTS_WATER },
{"slime", 1, 0, CONTENTS_SLIME },
{"lava", 1, 0, CONTENTS_LAVA },
{"playerclip", 1, 0, CONTENTS_PLAYERCLIP },
{"monsterclip", 1, 0, CONTENTS_MONSTERCLIP },
{"nodrop", 1, 0, CONTENTS_NODROP },
{"nonsolid", 1, SURF_NONSOLID, 0},
{"origin", 1, 0, CONTENTS_ORIGIN },
{"trans", 0, 0, CONTENTS_TRANSLUCENT },
{"detail", 0, 0, CONTENTS_DETAIL },
{"structural", 0, 0, CONTENTS_STRUCTURAL },
{"areaportal", 1, 0, CONTENTS_AREAPORTAL },
{"clusterportal",1, 0, CONTENTS_CLUSTERPORTAL },
{"donotenter", 1, 0, CONTENTS_DONOTENTER },
{"botclip", 1, 0, CONTENTS_BOTCLIP },
{"nobotclip", 0, 0, CONTENTS_NOBOTCLIP },
{"fog", 1, 0, CONTENTS_FOG},
{"sky", 0, SURF_SKY, 0 },
{"lightfilter", 0, SURF_LIGHTFILTER, 0 },
{"alphashadow", 0, SURF_ALPHASHADOW, 0 },
{"hint", 0, SURF_HINT, 0 },
{"slick", 0, SURF_SLICK, 0 },
{"noimpact", 0, SURF_NOIMPACT, 0 },
{"nomarks", 0, SURF_NOMARKS, 0 },
{"ladder", 0, SURF_LADDER, 0 },
{"nodamage", 0, SURF_NODAMAGE, 0 },
{"metalsteps", 0, SURF_METALSTEPS,0 },
{"flesh", 0, SURF_FLESH, 0 },
{"nosteps", 0, SURF_NOSTEPS, 0 },
{"nodraw", 0, SURF_NODRAW, 0 },
{"pointlight", 0, SURF_POINTLIGHT, 0 },
{"nolightmap", 0, SURF_NOLIGHTMAP,0 },
{"nodlight", 0, SURF_NODLIGHT, 0 },
{"dust", 0, SURF_DUST, 0}
}
|
|
|
Definition at line 61 of file shaders.c. Referenced by AllocShaderInfo(), and LoadShaderInfo(). |
|
|
Definition at line 60 of file shaders.c. Referenced by AllocShaderInfo(), and ShaderInfoForShader(). |
1.3.9.1