_lightmapsamplesize entity key by jal

git-svn-id: svn://svn.icculus.org/netradiant/trunk@359 61c419a2-8eb2-4b30-bcec-8cead039b335
This commit is contained in:
divverent 2009-05-01 10:45:24 +00:00
parent 9507f334d1
commit c005536caf
8 changed files with 111 additions and 44 deletions

View File

@ -626,6 +626,7 @@ static void ProjectDecalOntoWinding( decalProjector_t *dp, mapDrawSurface_t *ds,
ds2->shaderInfo = dp->si;
ds2->fogNum = ds->fogNum; /* why was this -1? */
ds2->lightmapScale = ds->lightmapScale;
ds2->shadeAngleDegrees = ds->shadeAngleDegrees;
ds2->numVerts = w->numpoints;
ds2->verts = safe_malloc( ds2->numVerts * sizeof( *ds2->verts ) );
memset( ds2->verts, 0, ds2->numVerts * sizeof( *ds2->verts ) );

View File

@ -1416,6 +1416,7 @@ static qboolean ParseMapEntity( qboolean onlyLights )
epair_t *ep;
const char *classname, *value;
float lightmapScale, shadeAngle;
int lightmapSampleSize;
char shader[ MAX_QPATH ];
shaderInfo_t *celShader = NULL;
brush_t *brush;
@ -1554,6 +1555,7 @@ static qboolean ParseMapEntity( qboolean onlyLights )
/* vortex: added _ls key (short name of lightmapscale) */
/* ydnar: get lightmap scaling value for this entity */
lightmapScale = 0.0f;
if( strcmp( "", ValueForKey( mapEnt, "lightmapscale" ) ) ||
strcmp( "", ValueForKey( mapEnt, "_lightmapscale" ) ) ||
strcmp( "", ValueForKey( mapEnt, "_ls" ) ) )
@ -1564,11 +1566,11 @@ static qboolean ParseMapEntity( qboolean onlyLights )
lightmapScale = FloatForKey( mapEnt, "_lightmapscale" );
if( lightmapScale <= 0.0f )
lightmapScale = FloatForKey( mapEnt, "_ls" );
if( lightmapScale < 0.0f )
lightmapScale = 0.0f;
if( lightmapScale > 0.0f )
Sys_Printf( "Entity %d (%s) has lightmap scale of %.4f\n", mapEnt->mapEntityNum, classname, lightmapScale );
}
else
lightmapScale = 0.0f;
/* ydnar: get cel shader :) for this entity */
value = ValueForKey( mapEnt, "_celshader" );
@ -1601,6 +1603,18 @@ static qboolean ParseMapEntity( qboolean onlyLights )
if( shadeAngle > 0.0f )
Sys_Printf( "Entity %d (%s) has shading angle of %.4f\n", mapEnt->mapEntityNum, classname, shadeAngle );
/* jal : entity based _samplesize */
lightmapSampleSize = 0;
if ( strcmp( "", ValueForKey( mapEnt, "_lightmapsamplesize" ) ) )
lightmapSampleSize = IntForKey( mapEnt, "_lightmapsamplesize" );
else if ( strcmp( "", ValueForKey( mapEnt, "_samplesize" ) ) )
lightmapSampleSize = IntForKey( mapEnt, "_samplesize" );
if( lightmapSampleSize < 0 )
lightmapSampleSize = 0;
if( lightmapSampleSize > 0 )
Sys_Printf( "Entity %d (%s) has lightmap sample size of %d\n", mapEnt->mapEntityNum, classname, lightmapSampleSize );
/* attach stuff to everything in the entity */
for( brush = mapEnt->brushes; brush != NULL; brush = brush->next )
@ -1608,6 +1622,7 @@ static qboolean ParseMapEntity( qboolean onlyLights )
brush->entityNum = mapEnt->mapEntityNum;
brush->castShadows = castShadows;
brush->recvShadows = recvShadows;
brush->lightmapSampleSize = lightmapSampleSize;
brush->lightmapScale = lightmapScale;
brush->celShader = celShader;
brush->shadeAngleDegrees = shadeAngle;
@ -1618,6 +1633,7 @@ static qboolean ParseMapEntity( qboolean onlyLights )
patch->entityNum = mapEnt->mapEntityNum;
patch->castShadows = castShadows;
patch->recvShadows = recvShadows;
patch->lightmapSampleSize = lightmapSampleSize;
patch->lightmapScale = lightmapScale;
patch->celShader = celShader;
}

View File

@ -206,7 +206,7 @@ InsertModel() - ydnar
adds a picomodel into the bsp
*/
void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, float shadeAngle )
void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, int lightmapSampleSize, float shadeAngle )
{
int i, j, k, s, numSurfaces;
m4x4_t identity, nTransform;
@ -253,6 +253,10 @@ void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shade
if( lightmapScale <= 0.0f )
lightmapScale = 1.0f;
/* fix bogus shade angle */
if( shadeAngle <= 0.0f )
shadeAngle = 0.0f;
/* each surface on the model will become a new map drawsurface */
numSurfaces = PicoGetModelNumSurfaces( model );
//% Sys_FPrintf( SYS_VRB, "Model %s has %d surfaces\n", name, numSurfaces );
@ -322,19 +326,22 @@ void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shade
if( (si != NULL && si->forceMeta) || (spawnFlags & 4) ) /* 3rd bit */
ds->type = SURFACE_FORCED_META;
/* get shading angle from shader or entity */
if( si->shadeAngleDegrees )
ds->shadeAngleDegrees = si->shadeAngleDegrees;
else if( shadeAngle )
ds->shadeAngleDegrees = shadeAngle; /* otherwise it's 0 */
/* fix the surface's normals (jal: conditioned by shader info) */
if( !(spawnFlags & 64) && ( shadeAngle == 0.0f || ds->type != SURFACE_FORCED_META ) )
PicoFixSurfaceNormals( surface );
/* set sample size */
if( lightmapSampleSize > 0.0f )
ds->sampleSize = lightmapSampleSize;
/* set lightmap scale */
if( lightmapScale > 0.0f )
ds->lightmapScale = lightmapScale;
/* set shading angle */
if( shadeAngle > 0.0f )
ds->shadeAngleDegrees = shadeAngle;
/* set particulars */
ds->numVerts = PicoGetSurfaceNumVertexes( surface );
ds->verts = safe_malloc( ds->numVerts * sizeof( ds->verts[ 0 ] ) );
@ -605,6 +612,7 @@ void AddTriangleModels( entity_t *e )
shaderInfo_t *celShader;
float temp, baseLightmapScale, lightmapScale;
float shadeAngle;
int lightmapSampleSize;
vec3_t origin, scale, angles;
m4x4_t transform;
epair_t *ep;
@ -629,11 +637,22 @@ void AddTriangleModels( entity_t *e )
/* get lightmap scale */
/* vortex: added _ls key (short name of lightmapscale) */
baseLightmapScale = 0.0f;
if( strcmp( "", ValueForKey( e, "lightmapscale" ) ) ||
strcmp( "", ValueForKey( e, "_lightmapscale" ) ) ||
strcmp( "", ValueForKey( e, "_ls" ) ) )
{
baseLightmapScale = FloatForKey( e, "lightmapscale" );
if( baseLightmapScale <= 0.0f )
baseLightmapScale = FloatForKey( e, "_lightmapscale" );
if( baseLightmapScale <= 0.0f )
baseLightmapScale = FloatForKey( e, "_ls" );
if( baseLightmapScale <= 0.0f )
if( baseLightmapScale < 0.0f )
baseLightmapScale = 0.0f;
if( baseLightmapScale > 0.0f )
Sys_Printf( "World Entity has lightmap scale of %.4f\n", baseLightmapScale );
}
/* walk the entity list */
for( num = 1; num < numEntities; num++ )
@ -752,13 +771,36 @@ void AddTriangleModels( entity_t *e )
else
celShader = *globalCelShader ? ShaderInfoForShader(globalCelShader) : NULL;
/* jal : entity based _samplesize */
lightmapSampleSize = 0;
if ( strcmp( "", ValueForKey( e2, "_lightmapsamplesize" ) ) )
lightmapSampleSize = IntForKey( e2, "_lightmapsamplesize" );
else if ( strcmp( "", ValueForKey( e2, "_samplesize" ) ) )
lightmapSampleSize = IntForKey( e2, "_samplesize" );
if( lightmapSampleSize < 0 )
lightmapSampleSize = 0;
if( lightmapSampleSize > 0.0f )
Sys_Printf( "misc_model has lightmap sample size of %.d\n", lightmapSampleSize );
/* get lightmap scale */
/* vortex: added _ls key (short name of lightmapscale) */
lightmapScale = 0.0f;
if( strcmp( "", ValueForKey( e2, "lightmapscale" ) ) ||
strcmp( "", ValueForKey( e2, "_lightmapscale" ) ) ||
strcmp( "", ValueForKey( e2, "_ls" ) ) )
{
lightmapScale = FloatForKey( e2, "lightmapscale" );
if( lightmapScale <= 0.0f )
lightmapScale = FloatForKey( e2, "_lightmapscale" );
if( lightmapScale <= 0.0f )
lightmapScale = FloatForKey( e2, "_ls" );
if( lightmapScale <= 0.0f )
lightmapScale = baseLightmapScale;
if( lightmapScale < 0.0f )
lightmapScale = 0.0f;
if( lightmapScale > 0.0f )
Sys_Printf( "misc_model has lightmap scale of %.4f\n", lightmapScale );
}
/* jal : entity based _shadeangle */
shadeAngle = 0.0f;
@ -779,7 +821,7 @@ void AddTriangleModels( entity_t *e )
Sys_Printf( "misc_model has shading angle of %.4f\n", shadeAngle );
/* insert the model */
InsertModel( (char*) model, frame, transform, remap, celShader, mapEntityNum, castShadows, recvShadows, spawnFlags, lightmapScale, shadeAngle );
InsertModel( (char*) model, frame, transform, remap, celShader, mapEntityNum, castShadows, recvShadows, spawnFlags, lightmapScale, lightmapSampleSize, shadeAngle );
/* free shader remappings */
while( remap != NULL )

View File

@ -889,6 +889,7 @@ typedef struct brush_s
shaderInfo_t *celShader; /* :) */
/* ydnar: gs mods */
int lightmapSampleSize; /* jal : entity based _lightmapsamplesize */
float lightmapScale;
float shadeAngleDegrees; /* jal : entity based _shadeangle */
vec3_t eMins, eMaxs;
@ -941,6 +942,7 @@ typedef struct parseMesh_s
shaderInfo_t *celShader; /* :) */
/* ydnar: gs mods */
int lightmapSampleSize; /* jal : entity based _lightmapsamplesize */
float lightmapScale;
vec3_t eMins, eMaxs;
indexMap_t *im;
@ -1639,7 +1641,7 @@ void PicoPrintFunc( int level, const char *str );
void PicoLoadFileFunc( char *name, byte **buffer, int *bufSize );
picoModel_t *FindModel( char *name, int frame );
picoModel_t *LoadModel( char *name, int frame );
void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, float shadeAngle );
void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, int lightmapSampleSize, float shadeAngle );
void AddTriangleModels( entity_t *e );

View File

@ -1531,7 +1531,7 @@ static void ParseShaderFile( const char *filename )
si->lightmapSampleSize = atoi( token );
}
/* q3map_lightmapSampleSffset <value> */
/* q3map_lightmapSampleOffset <value> */
else if( !Q_stricmp( token, "q3map_lightmapSampleOffset" ) )
{
GetTokenAppend( shaderText, qfalse );

View File

@ -631,22 +631,27 @@ void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds )
//% Sys_Printf( "Failed to map axis %d onto patch\n", bestAxis );
}
/* get lightmap sample size */
if( ds->sampleSize <= 0 )
{
ds->sampleSize = sampleSize;
if( ds->shaderInfo->lightmapSampleSize )
/* calculate lightmap sample size */
if( ds->shaderInfo->lightmapSampleSize > 0 ) /* shader value overrides every other */
ds->sampleSize = ds->shaderInfo->lightmapSampleSize;
if( ds->lightmapScale > 0 )
ds->sampleSize *= ds->lightmapScale;
if( ds->sampleSize <= 0 )
ds->sampleSize = 1;
if(ds->sampleSize < minSampleSize)
else if( ds->sampleSize <= 0 ) /* may contain the entity asigned value */
ds->sampleSize = sampleSize; /* otherwise use global default */
if( ds->lightmapScale > 0.0f ) /* apply surface lightmap scaling factor */
{
ds->sampleSize = ds->lightmapScale * (float)ds->sampleSize;
ds->lightmapScale = 0; /* applied */
}
if( ds->sampleSize < minSampleSize )
ds->sampleSize = minSampleSize;
if( ds->sampleSize < 1 )
ds->sampleSize = 1;
if( ds->sampleSize > 16384 ) /* powers of 2 are preferred */
ds->sampleSize = 16384;
}
}
}
@ -914,6 +919,7 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin
ds->mapBrush = b;
ds->sideRef = AllocSideRef( s, NULL );
ds->fogNum = -1;
ds->sampleSize = b->lightmapSampleSize;
ds->lightmapScale = b->lightmapScale;
ds->numVerts = w->numpoints;
ds->verts = safe_malloc( ds->numVerts * sizeof( *ds->verts ) );
@ -991,10 +997,8 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin
ds->celShader = b->celShader;
/* set shade angle */
if( si->shadeAngleDegrees )
ds->shadeAngleDegrees = ds->shadeAngleDegrees;
else
ds->shadeAngleDegrees = b->shadeAngleDegrees; /* otherwise it's 0 */
if( b->shadeAngleDegrees > 0.0f )
ds->shadeAngleDegrees = b->shadeAngleDegrees;
/* ydnar: gs mods: moved st biasing elsewhere */
return ds;
@ -1103,6 +1107,7 @@ mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh
ds->shaderInfo = si;
ds->mapMesh = p;
ds->sampleSize = p->lightmapSampleSize;
ds->lightmapScale = p->lightmapScale; /* ydnar */
ds->patchWidth = mesh->width;
ds->patchHeight = mesh->height;
@ -3133,7 +3138,7 @@ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, b
}
/* insert the model */
InsertModel( (char *) model->model, 0, transform, NULL, ds->celShader, ds->entityNum, ds->castShadows, ds->recvShadows, 0, ds->lightmapScale, 0 );
InsertModel( (char *) model->model, 0, transform, NULL, ds->celShader, ds->entityNum, ds->castShadows, ds->recvShadows, 0, ds->lightmapScale, 0, 0 );
/* return to sender */
return 1;

View File

@ -275,7 +275,7 @@ void Foliage( mapDrawSurface_t *src )
m4x4_scale_for_vec3( transform, scale );
/* add the model to the bsp */
InsertModel( foliage->model, 0, transform, NULL, NULL, src->entityNum, src->castShadows, src->recvShadows, 0, src->lightmapScale, 0 );
InsertModel( foliage->model, 0, transform, NULL, NULL, src->entityNum, src->castShadows, src->recvShadows, 0, src->lightmapScale, 0, 0 );
/* walk each new surface */
for( i = oldNumMapDrawSurfs; i < numMapDrawSurfs; i++ )

View File

@ -1462,6 +1462,7 @@ static void MetaTrianglesToSurface( int numPossibles, metaTriangle_t *possibles,
ds->planeNum = seed->planeNum;
ds->fogNum = seed->fogNum;
ds->sampleSize = seed->sampleSize;
ds->shadeAngleDegrees = seed->shadeAngleDegrees;
ds->verts = verts;
ds->indexes = indexes;
VectorCopy( seed->lightmapAxis, ds->lightmapAxis );