Rip out indexmap, legacyTerrain code that is broken since we abuse vertex

colors for more interesting things now.
This commit is contained in:
Marco Cawthorne 2021-11-01 23:59:54 +01:00
parent 8da6cc3a76
commit 11b15aec3d
Signed by: eukara
GPG key ID: C196CD8BA993248A
3 changed files with 5 additions and 278 deletions

View file

@ -698,14 +698,6 @@ void FinishShader( shaderInfo_t *si ){
si->shaderHeight = si->shaderImage->height; si->shaderHeight = si->shaderImage->height;
} }
/* legacy terrain has explicit image-sized texture projection */
if ( si->legacyTerrain && si->tcGen == qfalse ) {
/* set xy texture projection */
si->tcGen = qtrue;
VectorSet( si->vecs[ 0 ], ( 1.0f / ( si->shaderWidth * 0.5f ) ), 0, 0 );
VectorSet( si->vecs[ 1 ], 0, ( 1.0f / ( si->shaderHeight * 0.5f ) ), 0 );
}
/* find pixel coordinates best matching the average color of the image */ /* find pixel coordinates best matching the average color of the image */
bestDist = 99999999; bestDist = 99999999;
o[ 0 ] = 1.0f / si->shaderImage->width; o[ 0 ] = 1.0f / si->shaderImage->width;
@ -1020,7 +1012,7 @@ shaderInfo_t *ShaderInfoForShader( const char *shaderName ){
} }
/* tesssize is used to force liquid surfaces to subdivide */ /* tesssize is used to force liquid surfaces to subdivide */
else if ( !Q_stricmp( mattoken, "tessSize" ) ) { else if ( !Q_stricmp( mattoken, "vmap_tessSize" ) ) {
GetMatTokenAppend( shaderText, qfalse ); GetMatTokenAppend( shaderText, qfalse );
si->subdivisions = atof( mattoken ); si->subdivisions = atof( mattoken );
} }
@ -1577,20 +1569,6 @@ shaderInfo_t *ShaderInfoForShader( const char *shaderName ){
si->furFade = atof( mattoken ); si->furFade = atof( mattoken );
} }
/* ydnar: gs mods: legacy support for terrain/terrain2 shaders */
else if ( !Q_stricmp( mattoken, "q3map_terrain" ) || !Q_stricmp( mattoken, "vmap_terrain" ) ) {
/* team arena terrain is assumed to be nonplanar, with full normal averaging,
passed through the metatriangle surface pipeline, with a lightmap axis on z */
si->legacyTerrain = qtrue;
si->noClip = qtrue;
si->notjunc = qtrue;
si->indexed = qtrue;
si->nonplanar = qtrue;
si->forceMeta = qtrue;
si->shadeAngleDegrees = 179.0f;
//% VectorSet( si->lightmapAxis, 0, 0, 1 ); /* ydnar 2002-09-21: turning this off for better lightmapping of cliff faces */
}
/* ydnar: picomodel: q3map_forceMeta (forces brush faces and/or triangle models to go through the metasurface pipeline) */ /* ydnar: picomodel: q3map_forceMeta (forces brush faces and/or triangle models to go through the metasurface pipeline) */
else if ( !Q_stricmp( mattoken, "q3map_forceMeta" ) || !Q_stricmp( mattoken, "vmap_forceMeta" ) ) { else if ( !Q_stricmp( mattoken, "q3map_forceMeta" ) || !Q_stricmp( mattoken, "vmap_forceMeta" ) ) {
si->forceMeta = qtrue; si->forceMeta = qtrue;
@ -1808,11 +1786,6 @@ shaderInfo_t *ShaderInfoForShader( const char *shaderName ){
si->noFog = qtrue; si->noFog = qtrue;
} }
/* ydnar: gs mods: q3map_indexed (for explicit terrain-style indexed mapping) */
else if ( !Q_stricmp( mattoken, "q3map_indexed" ) || !Q_stricmp( mattoken, "vmap_indexed" ) ) {
si->indexed = qtrue;
}
/* ydnar: q3map_invert (inverts a drawsurface's facing) */ /* ydnar: q3map_invert (inverts a drawsurface's facing) */
else if ( !Q_stricmp( mattoken, "q3map_invert" ) || !Q_stricmp( mattoken, "vmap_invert" ) ) { else if ( !Q_stricmp( mattoken, "q3map_invert" ) || !Q_stricmp( mattoken, "vmap_invert" ) ) {
si->invert = qtrue; si->invert = qtrue;
@ -2110,7 +2083,7 @@ static void ParseShaderFile( const char *filename ){
} }
/* tesssize is used to force liquid surfaces to subdivide */ /* tesssize is used to force liquid surfaces to subdivide */
else if ( !Q_stricmp( token, "tessSize" ) ) { else if ( !Q_stricmp( token, "vmap_tessSize" ) ) {
GetTokenAppend( shaderText, qfalse ); GetTokenAppend( shaderText, qfalse );
si->subdivisions = atof( token ); si->subdivisions = atof( token );
} }
@ -2661,20 +2634,6 @@ static void ParseShaderFile( const char *filename ){
si->furFade = atof( token ); si->furFade = atof( token );
} }
/* ydnar: gs mods: legacy support for terrain/terrain2 shaders */
else if ( !Q_stricmp( token, "q3map_terrain" ) || !Q_stricmp( token, "vmap_terrain" ) ) {
/* team arena terrain is assumed to be nonplanar, with full normal averaging,
passed through the metatriangle surface pipeline, with a lightmap axis on z */
si->legacyTerrain = qtrue;
si->noClip = qtrue;
si->notjunc = qtrue;
si->indexed = qtrue;
si->nonplanar = qtrue;
si->forceMeta = qtrue;
si->shadeAngleDegrees = 179.0f;
//% VectorSet( si->lightmapAxis, 0, 0, 1 ); /* ydnar 2002-09-21: turning this off for better lightmapping of cliff faces */
}
/* ydnar: picomodel: q3map_forceMeta (forces brush faces and/or triangle models to go through the metasurface pipeline) */ /* ydnar: picomodel: q3map_forceMeta (forces brush faces and/or triangle models to go through the metasurface pipeline) */
else if ( !Q_stricmp( token, "q3map_forceMeta" ) || !Q_stricmp( token, "vmap_forceMeta" ) ) { else if ( !Q_stricmp( token, "q3map_forceMeta" ) || !Q_stricmp( token, "vmap_forceMeta" ) ) {
si->forceMeta = qtrue; si->forceMeta = qtrue;
@ -2892,11 +2851,6 @@ static void ParseShaderFile( const char *filename ){
si->noFog = qtrue; si->noFog = qtrue;
} }
/* ydnar: gs mods: q3map_indexed (for explicit terrain-style indexed mapping) */
else if ( !Q_stricmp( token, "q3map_indexed" ) || !Q_stricmp( token, "vmap_indexed" ) ) {
si->indexed = qtrue;
}
/* ydnar: q3map_invert (inverts a drawsurface's facing) */ /* ydnar: q3map_invert (inverts a drawsurface's facing) */
else if ( !Q_stricmp( token, "q3map_invert" ) || !Q_stricmp( token, "vmap_invert" ) ) { else if ( !Q_stricmp( token, "q3map_invert" ) || !Q_stricmp( token, "vmap_invert" ) ) {
si->invert = qtrue; si->invert = qtrue;

View file

@ -700,177 +700,11 @@ void ClassifyEntitySurfaces( entity_t *e ){
TidyEntitySurfaces( e ); TidyEntitySurfaces( e );
} }
/*
GetShaderIndexForPoint() - ydnar
for shader-indexed surfaces (terrain), find a matching index from the indexmap
*/
byte GetShaderIndexForPoint( indexMap_t *im, vec3_t eMins, vec3_t eMaxs, vec3_t point ){
int i, x, y;
float s, t;
vec3_t mins, maxs, size;
/* early out if no indexmap */
if ( im == NULL ) {
return 0;
}
/* this code is really broken */
#if 0
/* legacy precision fudges for terrain */
for ( i = 0; i < 3; i++ )
{
mins[ i ] = floor( eMins[ i ] + 0.1 );
maxs[ i ] = floor( eMaxs[ i ] + 0.1 );
size[ i ] = maxs[ i ] - mins[ i ];
}
/* find st (fixme: support more than just z-axis projection) */
s = floor( point[ 0 ] + 0.1f - mins[ 0 ] ) / size[ 0 ];
t = floor( maxs[ 1 ] - point[ 1 ] + 0.1f ) / size[ 1 ];
if ( s < 0.0f ) {
s = 0.0f;
}
else if ( s > 1.0f ) {
s = 1.0f;
}
if ( t < 0.0f ) {
t = 0.0f;
}
else if ( t > 1.0f ) {
t = 1.0f;
}
/* make xy */
x = ( im->w - 1 ) * s;
y = ( im->h - 1 ) * t;
#else
/* get size */
for ( i = 0; i < 3; i++ )
{
mins[ i ] = eMins[ i ];
maxs[ i ] = eMaxs[ i ];
size[ i ] = maxs[ i ] - mins[ i ];
}
/* calc st */
s = ( point[ 0 ] - mins[ 0 ] ) / size[ 0 ];
t = ( maxs[ 1 ] - point[ 1 ] ) / size[ 1 ];
/* calc xy */
x = s * im->w;
y = t * im->h;
if ( x < 0 ) {
x = 0;
}
else if ( x > ( im->w - 1 ) ) {
x = ( im->w - 1 );
}
if ( y < 0 ) {
y = 0;
}
else if ( y > ( im->h - 1 ) ) {
y = ( im->h - 1 );
}
#endif
/* return index */
return im->pixels[ y * im->w + x ];
}
#define snprintf_ignore(s, n, format, ...) do { \ #define snprintf_ignore(s, n, format, ...) do { \
size_t __n = snprintf(s, n, format, __VA_ARGS__); \ size_t __n = snprintf(s, n, format, __VA_ARGS__); \
if (n >= n) {} /* truncated, ignore */ \ if (n >= n) {} /* truncated, ignore */ \
} while (0) } while (0)
/*
GetIndexedShader() - ydnar
for a given set of indexes and an indexmap, get a shader and set the vertex alpha in-place
this combines a couple different functions from terrain.c
*/
shaderInfo_t *GetIndexedShader( shaderInfo_t *parent, indexMap_t *im, int numPoints, byte *shaderIndexes ){
int i;
byte minShaderIndex, maxShaderIndex;
char shader[ MAX_QPATH ];
shaderInfo_t *si;
/* early out if bad data */
if ( im == NULL || numPoints <= 0 || shaderIndexes == NULL ) {
return ShaderInfoForShader( "default" );
}
/* determine min/max index */
minShaderIndex = 255;
maxShaderIndex = 0;
for ( i = 0; i < numPoints; i++ )
{
if ( shaderIndexes[ i ] < minShaderIndex ) {
minShaderIndex = shaderIndexes[ i ];
}
if ( shaderIndexes[ i ] > maxShaderIndex ) {
maxShaderIndex = shaderIndexes[ i ];
}
}
/* set alpha inline */
for ( i = 0; i < numPoints; i++ )
{
/* straight rip from terrain.c */
if ( shaderIndexes[ i ] < maxShaderIndex ) {
shaderIndexes[ i ] = 0;
}
else{
shaderIndexes[ i ] = 255;
}
}
/* make a shader name */
if ( minShaderIndex == maxShaderIndex ) {
snprintf_ignore( shader, sizeof shader, "textures/%s_%d", im->shader, maxShaderIndex );
}
else{
snprintf_ignore( shader, sizeof shader, "textures/%s_%dto%d", im->shader, minShaderIndex, maxShaderIndex );
}
/* get the shader */
si = ShaderInfoForShader( shader );
/* inherit a few things from parent shader */
if ( parent->globalTexture ) {
si->globalTexture = qtrue;
}
if ( parent->forceMeta ) {
si->forceMeta = qtrue;
}
if ( parent->nonplanar ) {
si->nonplanar = qtrue;
}
if ( si->shadeAngleDegrees == 0.0 ) {
si->shadeAngleDegrees = parent->shadeAngleDegrees;
}
if ( parent->tcGen && si->tcGen == qfalse ) {
/* set xy texture projection */
si->tcGen = qtrue;
VectorCopy( parent->vecs[ 0 ], si->vecs[ 0 ] );
VectorCopy( parent->vecs[ 1 ], si->vecs[ 1 ] );
}
if ( VectorLength( parent->lightmapAxis ) > 0.0f && VectorLength( si->lightmapAxis ) <= 0.0f ) {
/* set lightmap projection axis */
VectorCopy( parent->lightmapAxis, si->lightmapAxis );
}
/* return the shader */
return si;
}
/* /*
DrawSurfaceForSide() DrawSurfaceForSide()
@ -888,7 +722,6 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin
vec3_t texX, texY; vec3_t texX, texY;
vec_t x, y; vec_t x, y;
vec3_t vTranslated; vec3_t vTranslated;
qboolean indexed;
byte shaderIndexes[ 256 ]; byte shaderIndexes[ 256 ];
float offsets[ 256 ]; float offsets[ 256 ];
char tempShader[ MAX_QPATH ]; char tempShader[ MAX_QPATH ];
@ -907,27 +740,6 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin
/* get shader */ /* get shader */
si = s->shaderInfo; si = s->shaderInfo;
/* ydnar: gs mods: check for indexed shader */
if ( si->indexed && b->im != NULL ) {
/* indexed */
indexed = qtrue;
/* get shader indexes for each point */
for ( i = 0; i < w->numpoints; i++ )
{
shaderIndexes[ i ] = GetShaderIndexForPoint( b->im, b->eMins, b->eMaxs, w->p[ i ] );
offsets[ i ] = b->im->offsets[ shaderIndexes[ i ] ];
//% Sys_Printf( "%f ", offsets[ i ] );
}
/* get matching shader and set alpha */
parent = si;
si = GetIndexedShader( parent, b->im, w->numpoints, shaderIndexes );
}
else{
indexed = qfalse;
}
/* ydnar: sky hack/fix for GL_CLAMP borders on ati cards */ /* ydnar: sky hack/fix for GL_CLAMP borders on ati cards */
if ( skyFixHack && si->skyParmsImageBase[ 0 ] != '\0' ) { if ( skyFixHack && si->skyParmsImageBase[ 0 ] != '\0' ) {
//% Sys_FPrintf( SYS_VRB, "Enabling sky hack for shader %s using env %s\n", si->shader, si->skyParmsImageBase ); //% Sys_FPrintf( SYS_VRB, "Enabling sky hack for shader %s using env %s\n", si->shader, si->skyParmsImageBase );
@ -977,9 +789,6 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin
/* copy xyz and do potential z offset */ /* copy xyz and do potential z offset */
VectorCopy( w->p[ j ], dv->xyz ); VectorCopy( w->p[ j ], dv->xyz );
if ( indexed ) {
dv->xyz[ 2 ] += offsets[ j ];
}
/* round the xyz to a given precision and translate by origin */ /* round the xyz to a given precision and translate by origin */
for ( i = 0; i < 3; i++ ) for ( i = 0; i < 3; i++ )
@ -1026,9 +835,7 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin
dv->color[ k ][ 0 ] = 255; dv->color[ k ][ 0 ] = 255;
dv->color[ k ][ 1 ] = 255; dv->color[ k ][ 1 ] = 255;
dv->color[ k ][ 2 ] = 255; dv->color[ k ][ 2 ] = 255;
dv->color[ k ][ 3 ] = 255;
/* ydnar: gs mods: handle indexed shader blending */
dv->color[ k ][ 3 ] = ( indexed ? shaderIndexes[ i ] : 255 );
} }
} }
@ -1075,7 +882,6 @@ mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh
bspDrawVert_t *dv; bspDrawVert_t *dv;
vec3_t vTranslated; vec3_t vTranslated;
mesh_t *copy; mesh_t *copy;
qboolean indexed;
byte shaderIndexes[ MAX_EXPANDED_AXIS * MAX_EXPANDED_AXIS ]; byte shaderIndexes[ MAX_EXPANDED_AXIS * MAX_EXPANDED_AXIS ];
float offsets[ MAX_EXPANDED_AXIS * MAX_EXPANDED_AXIS ]; float offsets[ MAX_EXPANDED_AXIS * MAX_EXPANDED_AXIS ];
@ -1120,26 +926,6 @@ mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh
/* free the old mesh */ /* free the old mesh */
FreeMesh( copy ); FreeMesh( copy );
/* ydnar: gs mods: check for indexed shader */
if ( si->indexed && p->im != NULL ) {
/* indexed */
indexed = qtrue;
/* get shader indexes for each point */
for ( i = 0; i < numVerts; i++ )
{
shaderIndexes[ i ] = GetShaderIndexForPoint( p->im, p->eMins, p->eMaxs, mesh->verts[ i ].xyz );
offsets[ i ] = p->im->offsets[ shaderIndexes[ i ] ];
}
/* get matching shader and set alpha */
parent = si;
si = GetIndexedShader( parent, p->im, numVerts, shaderIndexes );
}
else{
indexed = qfalse;
}
/* ydnar: gs mods */ /* ydnar: gs mods */
ds = AllocDrawSurface( SURFACE_PATCH ); ds = AllocDrawSurface( SURFACE_PATCH );
@ -1229,18 +1015,7 @@ mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh
dv->color[ k ][ 0 ] = 255; dv->color[ k ][ 0 ] = 255;
dv->color[ k ][ 1 ] = 255; dv->color[ k ][ 1 ] = 255;
dv->color[ k ][ 2 ] = 255; dv->color[ k ][ 2 ] = 255;
dv->color[ k ][ 3 ] *= 1.0f;
/* ydnar: gs mods: handle indexed shader blending */
if (indexed) {
dv->color[ k ][ 3 ] = shaderIndexes[ i ];
} else {
dv->color[ k ][ 3 ] *= 1.0f;
}
}
/* ydnar: offset */
if ( indexed ) {
dv->xyz[ 2 ] += offsets[ i ];
} }
} }
@ -1832,7 +1607,7 @@ void ClipSidesIntoTree( entity_t *e, tree_t *tree ){
/* don't create faces for non-visible sides */ /* don't create faces for non-visible sides */
/* ydnar: except indexed shaders, like common/terrain and nodraw fog surfaces */ /* ydnar: except indexed shaders, like common/terrain and nodraw fog surfaces */
if ( ( si->compileFlags & C_NODRAW ) && si->indexed == qfalse && !( si->compileFlags & C_FOG ) ) { if ( ( si->compileFlags & C_NODRAW ) && !( si->compileFlags & C_FOG ) ) {
continue; continue;
} }

View file

@ -706,8 +706,6 @@ typedef struct shaderInfo_s
vec3_t mins, maxs; /* ydnar: for particle studio vertexDeform move support */ vec3_t mins, maxs; /* ydnar: for particle studio vertexDeform move support */
qb_t legacyTerrain; /* ydnar: enable legacy terrain crutches */
qb_t indexed; /* ydnar: attempt to use indexmap (terrain alphamap style) */
qb_t forceMeta; /* ydnar: force metasurface path */ qb_t forceMeta; /* ydnar: force metasurface path */
qb_t noClip; /* ydnar: don't clip into bsp, preserve original face winding */ qb_t noClip; /* ydnar: don't clip into bsp, preserve original face winding */
qb_t noFast; /* ydnar: supress fast lighting for surfaces with this shader */ qb_t noFast; /* ydnar: supress fast lighting for surfaces with this shader */