📄 tr_shader.c
字号:
tmi->type = TMOD_STRETCH;
}
//
// transform
//
else if ( !Q_stricmp( token, "transform" ) )
{
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 )
{
ri.Printf( PRINT_WARNING, "WARNING: missing transform parms in shader '%s'\n", shader.name );
return;
}
tmi->matrix[0][0] = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 )
{
ri.Printf( PRINT_WARNING, "WARNING: missing transform parms in shader '%s'\n", shader.name );
return;
}
tmi->matrix[0][1] = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 )
{
ri.Printf( PRINT_WARNING, "WARNING: missing transform parms in shader '%s'\n", shader.name );
return;
}
tmi->matrix[1][0] = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 )
{
ri.Printf( PRINT_WARNING, "WARNING: missing transform parms in shader '%s'\n", shader.name );
return;
}
tmi->matrix[1][1] = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 )
{
ri.Printf( PRINT_WARNING, "WARNING: missing transform parms in shader '%s'\n", shader.name );
return;
}
tmi->translate[0] = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 )
{
ri.Printf( PRINT_WARNING, "WARNING: missing transform parms in shader '%s'\n", shader.name );
return;
}
tmi->translate[1] = atof( token );
tmi->type = TMOD_TRANSFORM;
}
//
// rotate
//
else if ( !Q_stricmp( token, "rotate" ) )
{
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 )
{
ri.Printf( PRINT_WARNING, "WARNING: missing tcMod rotate parms in shader '%s'\n", shader.name );
return;
}
tmi->rotateSpeed = atof( token );
tmi->type = TMOD_ROTATE;
}
//
// entityTranslate
//
else if ( !Q_stricmp( token, "entityTranslate" ) )
{
tmi->type = TMOD_ENTITY_TRANSLATE;
}
else
{
ri.Printf( PRINT_WARNING, "WARNING: unknown tcMod '%s' in shader '%s'\n", token, shader.name );
}
}
/*
===================
ParseStage
===================
*/
static qboolean ParseStage( shaderStage_t *stage, char **text )
{
char *token;
int depthMaskBits = GLS_DEPTHMASK_TRUE, blendSrcBits = 0, blendDstBits = 0, atestBits = 0, depthFuncBits = 0;
qboolean depthMaskExplicit = qfalse;
stage->active = qtrue;
while ( 1 )
{
token = COM_ParseExt( text, qtrue );
if ( !token[0] )
{
ri.Printf( PRINT_WARNING, "WARNING: no matching '}' found\n" );
return qfalse;
}
if ( token[0] == '}' )
{
break;
}
//
// map <name>
//
else if ( !Q_stricmp( token, "map" ) )
{
token = COM_ParseExt( text, qfalse );
if ( !token[0] )
{
ri.Printf( PRINT_WARNING, "WARNING: missing parameter for 'map' keyword in shader '%s'\n", shader.name );
return qfalse;
}
if ( !Q_stricmp( token, "$whiteimage" ) )
{
stage->bundle[0].image[0] = tr.whiteImage;
continue;
}
else if ( !Q_stricmp( token, "$lightmap" ) )
{
stage->bundle[0].isLightmap = qtrue;
if ( shader.lightmapIndex < 0 ) {
stage->bundle[0].image[0] = tr.whiteImage;
} else {
stage->bundle[0].image[0] = tr.lightmaps[shader.lightmapIndex];
}
continue;
}
else
{
stage->bundle[0].image[0] = R_FindImageFile( token, !shader.noMipMaps, !shader.noPicMip, GL_REPEAT );
if ( !stage->bundle[0].image[0] )
{
ri.Printf( PRINT_WARNING, "WARNING: R_FindImageFile could not find '%s' in shader '%s'\n", token, shader.name );
return qfalse;
}
}
}
//
// clampmap <name>
//
else if ( !Q_stricmp( token, "clampmap" ) )
{
token = COM_ParseExt( text, qfalse );
if ( !token[0] )
{
ri.Printf( PRINT_WARNING, "WARNING: missing parameter for 'clampmap' keyword in shader '%s'\n", shader.name );
return qfalse;
}
stage->bundle[0].image[0] = R_FindImageFile( token, !shader.noMipMaps, !shader.noPicMip, GL_CLAMP );
if ( !stage->bundle[0].image[0] )
{
ri.Printf( PRINT_WARNING, "WARNING: R_FindImageFile could not find '%s' in shader '%s'\n", token, shader.name );
return qfalse;
}
}
//
// animMap <frequency> <image1> .... <imageN>
//
else if ( !Q_stricmp( token, "animMap" ) )
{
token = COM_ParseExt( text, qfalse );
if ( !token[0] )
{
ri.Printf( PRINT_WARNING, "WARNING: missing parameter for 'animMmap' keyword in shader '%s'\n", shader.name );
return qfalse;
}
stage->bundle[0].imageAnimationSpeed = atof( token );
// parse up to MAX_IMAGE_ANIMATIONS animations
while ( 1 ) {
int num;
token = COM_ParseExt( text, qfalse );
if ( !token[0] ) {
break;
}
num = stage->bundle[0].numImageAnimations;
if ( num < MAX_IMAGE_ANIMATIONS ) {
stage->bundle[0].image[num] = R_FindImageFile( token, !shader.noMipMaps, !shader.noPicMip, GL_REPEAT );
if ( !stage->bundle[0].image[num] )
{
ri.Printf( PRINT_WARNING, "WARNING: R_FindImageFile could not find '%s' in shader '%s'\n", token, shader.name );
return qfalse;
}
stage->bundle[0].numImageAnimations++;
}
}
}
else if ( !Q_stricmp( token, "videoMap" ) )
{
token = COM_ParseExt( text, qfalse );
if ( !token[0] )
{
ri.Printf( PRINT_WARNING, "WARNING: missing parameter for 'videoMmap' keyword in shader '%s'\n", shader.name );
return qfalse;
}
stage->bundle[0].videoMapHandle = ri.CIN_PlayCinematic( token, 0, 0, 256, 256, (CIN_loop | CIN_silent | CIN_shader));
if (stage->bundle[0].videoMapHandle != -1) {
stage->bundle[0].isVideoMap = qtrue;
stage->bundle[0].image[0] = tr.scratchImage[stage->bundle[0].videoMapHandle];
}
}
//
// alphafunc <func>
//
else if ( !Q_stricmp( token, "alphaFunc" ) )
{
token = COM_ParseExt( text, qfalse );
if ( !token[0] )
{
ri.Printf( PRINT_WARNING, "WARNING: missing parameter for 'alphaFunc' keyword in shader '%s'\n", shader.name );
return qfalse;
}
atestBits = NameToAFunc( token );
}
//
// depthFunc <func>
//
else if ( !Q_stricmp( token, "depthfunc" ) )
{
token = COM_ParseExt( text, qfalse );
if ( !token[0] )
{
ri.Printf( PRINT_WARNING, "WARNING: missing parameter for 'depthfunc' keyword in shader '%s'\n", shader.name );
return qfalse;
}
if ( !Q_stricmp( token, "lequal" ) )
{
depthFuncBits = 0;
}
else if ( !Q_stricmp( token, "equal" ) )
{
depthFuncBits = GLS_DEPTHFUNC_EQUAL;
}
else
{
ri.Printf( PRINT_WARNING, "WARNING: unknown depthfunc '%s' in shader '%s'\n", token, shader.name );
continue;
}
}
//
// detail
//
else if ( !Q_stricmp( token, "detail" ) )
{
stage->isDetail = qtrue;
}
//
// blendfunc <srcFactor> <dstFactor>
// or blendfunc <add|filter|blend>
//
else if ( !Q_stricmp( token, "blendfunc" ) )
{
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 )
{
ri.Printf( PRINT_WARNING, "WARNING: missing parm for blendFunc in shader '%s'\n", shader.name );
continue;
}
// check for "simple" blends first
if ( !Q_stricmp( token, "add" ) ) {
blendSrcBits = GLS_SRCBLEND_ONE;
blendDstBits = GLS_DSTBLEND_ONE;
} else if ( !Q_stricmp( token, "filter" ) ) {
blendSrcBits = GLS_SRCBLEND_DST_COLOR;
blendDstBits = GLS_DSTBLEND_ZERO;
} else if ( !Q_stricmp( token, "blend" ) ) {
blendSrcBits = GLS_SRCBLEND_SRC_ALPHA;
blendDstBits = GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA;
} else {
// complex double blends
blendSrcBits = NameToSrcBlendMode( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 )
{
ri.Printf( PRINT_WARNING, "WARNING: missing parm for blendFunc in shader '%s'\n", shader.name );
continue;
}
blendDstBits = NameToDstBlendMode( token );
}
// clear depth mask for blended surfaces
if ( !depthMaskExplicit )
{
depthMaskBits = 0;
}
}
//
// rgbGen
//
else if ( !Q_stricmp( token, "rgbGen" ) )
{
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 )
{
ri.Printf( PRINT_WARNING, "WARNING: missing parameters for rgbGen in shader '%s'\n", shader.name );
continue;
}
if ( !Q_stricmp( token, "wave" ) )
{
ParseWaveForm( text, &stage->rgbWave );
stage->rgbGen = CGEN_WAVEFORM;
}
else if ( !Q_stricmp( token, "const" ) )
{
vec3_t color;
ParseVector( text, 3, color );
stage->constantColor[0] = 255 * color[0];
stage->constantColor[1] = 255 * color[1];
stage->constantColor[2] = 255 * color[2];
stage->rgbGen = CGEN_CONST;
}
else if ( !Q_stricmp( token, "identity" ) )
{
stage->rgbGen = CGEN_IDENTITY;
}
else if ( !Q_stricmp( token, "identityLighting" ) )
{
stage->rgbGen = CGEN_IDENTITY_LIGHTING;
}
else if ( !Q_stricmp( token, "entity" ) )
{
stage->rgbGen = CGEN_ENTITY;
}
else if ( !Q_stricmp( token, "oneMinusEntity" ) )
{
stage->rgbGen = CGEN_ONE_MINUS_ENTITY;
}
else if ( !Q_stricmp( token, "vertex" ) )
{
stage->rgbGen = CGEN_VERTEX;
if ( stage->alphaGen == 0 ) {
stage->alphaGen = AGEN_VERTEX;
}
}
else if ( !Q_stricmp( token, "exactVertex" ) )
{
stage->rgbGen = CGEN_EXACT_VERTEX;
}
else if ( !Q_stricmp( token, "lightingDiffuse" ) )
{
stage->rgbGen = CGEN_LIGHTING_DIFFUSE;
}
else if ( !Q_stricmp( token, "oneMinusVertex" ) )
{
stage->rgbGen = CGEN_ONE_MINUS_VERTEX;
}
else
{
ri.Printf( PRINT_WARNING, "WARNING: unknown rgbGen parameter '%s' in shader '%s'\n", token, shader.name );
continue;
}
}
//
// alphaGen
//
else if ( !Q_stricmp( token, "alphaGen" ) )
{
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 )
{
ri.Printf( PRINT_WARNING, "WARNING: missing parameters for alphaGen in shader '%s'\n", shader.name );
continue;
}
if ( !Q_stricmp( token, "wave" ) )
{
ParseWaveForm( text, &stage->alphaWave );
stage->alphaGen = AGEN_WAVEFORM;
}
else if ( !Q_stricmp( token, "const" ) )
{
token = COM_ParseExt( text, qfalse );
stage->constantColor[3] = 255 * atof( token );
stage->alphaGen = AGEN_CONST;
}
else if ( !Q_stricmp( token, "identity" ) )
{
stage->alphaGen = AGEN_IDENTITY;
}
else if ( !Q_stricmp( token, "entity" ) )
{
stage->alphaGen = AGEN_ENTITY;
}
else if ( !Q_stricmp( token, "oneMinusEntity" ) )
{
stage->alphaGen = AGEN_ONE_MINUS_ENTITY;
}
else if ( !Q_stricmp( token, "vertex" ) )
{
stage->alphaGen = AGEN_VERTEX;
}
else if ( !Q_stricmp( token, "lightingSpecular" ) )
{
stage->alphaGen = AGEN_LIGHTING_SPECULAR;
}
else if ( !Q_stricmp( token, "oneMinusVertex" ) )
{
stage->alphaGen = AGEN_ONE_MINUS_VERTEX;
}
else if ( !Q_stricmp( token, "portal" ) )
{
stage->alphaGen = AGEN_PORTAL;
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 )
{
shader.portalRange = 256;
ri.Printf( PRINT_WARNING, "WARNING: missing range parameter for alphaGen portal in shader '%s', defaulting to 256\n", shader.name );
}
else
{
shader.portalRange = atof( token );
}
}
else
{
ri.Printf( PRINT_WARNING, "WARNING: unknown alphaGen parameter '%s' in shader '%s'\n", token, shader.name );
continue;
}
}
//
// tcGen <function>
//
else if ( !Q_stricmp(token, "texgen") || !Q_stricmp( token, "tcGen" ) )
{
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 )
{
ri.Printf( PRINT_WARNING, "WARNING: missing texgen parm in shader '%s'\n", shader.name );
continue;
}
if ( !Q_stricmp( token, "environment" ) )
{
stage->bundle[0].tcGen = TCGEN_ENVIRONMENT_MAPPED;
}
else if ( !Q_stricmp( token, "lightmap" ) )
{
stage->bundle[0].tcGen = TCGEN_LIGHTMAP;
}
else if ( !Q_stricmp( token, "texture" ) || !Q_stricmp( token, "base" ) )
{
stage->bundle[0].tcGen = TCGEN_TEXTURE;
}
else if ( !Q_stricmp( token, "vector" ) )
{
ParseVector( text, 3, stage->bundle[0].tcGenVectors[0] );
ParseVector( text, 3, stage->bundle[0].tcGenVectors[1] );
stage->bundle[0].tcGen = TCGEN_VECTOR;
}
else
{
ri.Printf( PRINT_WARNING, "WARNING: unknown texgen parm in shader '%s'\n", shader.name );
}
}
//
// tcMod <type> <...>
//
else if ( !Q_stricmp( token, "tcMod" ) )
{
char buffer[1024] = "";
while ( 1 )
{
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 )
break;
strcat( buffer, token );
strcat( buffer, " " );
}
ParseTexMod( buffer, stage );
continue;
}
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -