_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->shaderInfo = dp->si;
ds2->fogNum = ds->fogNum; /* why was this -1? */ ds2->fogNum = ds->fogNum; /* why was this -1? */
ds2->lightmapScale = ds->lightmapScale; ds2->lightmapScale = ds->lightmapScale;
ds2->shadeAngleDegrees = ds->shadeAngleDegrees;
ds2->numVerts = w->numpoints; ds2->numVerts = w->numpoints;
ds2->verts = safe_malloc( ds2->numVerts * sizeof( *ds2->verts ) ); ds2->verts = safe_malloc( ds2->numVerts * sizeof( *ds2->verts ) );
memset( ds2->verts, 0, 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; epair_t *ep;
const char *classname, *value; const char *classname, *value;
float lightmapScale, shadeAngle; float lightmapScale, shadeAngle;
int lightmapSampleSize;
char shader[ MAX_QPATH ]; char shader[ MAX_QPATH ];
shaderInfo_t *celShader = NULL; shaderInfo_t *celShader = NULL;
brush_t *brush; brush_t *brush;
@ -1554,6 +1555,7 @@ static qboolean ParseMapEntity( qboolean onlyLights )
/* vortex: added _ls key (short name of lightmapscale) */ /* vortex: added _ls key (short name of lightmapscale) */
/* ydnar: get lightmap scaling value for this entity */ /* ydnar: get lightmap scaling value for this entity */
lightmapScale = 0.0f;
if( strcmp( "", ValueForKey( mapEnt, "lightmapscale" ) ) || if( strcmp( "", ValueForKey( mapEnt, "lightmapscale" ) ) ||
strcmp( "", ValueForKey( mapEnt, "_lightmapscale" ) ) || strcmp( "", ValueForKey( mapEnt, "_lightmapscale" ) ) ||
strcmp( "", ValueForKey( mapEnt, "_ls" ) ) ) strcmp( "", ValueForKey( mapEnt, "_ls" ) ) )
@ -1564,12 +1566,12 @@ static qboolean ParseMapEntity( qboolean onlyLights )
lightmapScale = FloatForKey( mapEnt, "_lightmapscale" ); lightmapScale = FloatForKey( mapEnt, "_lightmapscale" );
if( lightmapScale <= 0.0f ) if( lightmapScale <= 0.0f )
lightmapScale = FloatForKey( mapEnt, "_ls" ); lightmapScale = FloatForKey( mapEnt, "_ls" );
if( lightmapScale < 0.0f )
lightmapScale = 0.0f;
if( lightmapScale > 0.0f ) if( lightmapScale > 0.0f )
Sys_Printf( "Entity %d (%s) has lightmap scale of %.4f\n", mapEnt->mapEntityNum, classname, lightmapScale ); 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 */ /* ydnar: get cel shader :) for this entity */
value = ValueForKey( mapEnt, "_celshader" ); value = ValueForKey( mapEnt, "_celshader" );
if( value[ 0 ] == '\0' ) if( value[ 0 ] == '\0' )
@ -1601,6 +1603,18 @@ static qboolean ParseMapEntity( qboolean onlyLights )
if( shadeAngle > 0.0f ) if( shadeAngle > 0.0f )
Sys_Printf( "Entity %d (%s) has shading angle of %.4f\n", mapEnt->mapEntityNum, classname, shadeAngle ); 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 */ /* attach stuff to everything in the entity */
for( brush = mapEnt->brushes; brush != NULL; brush = brush->next ) for( brush = mapEnt->brushes; brush != NULL; brush = brush->next )
@ -1608,6 +1622,7 @@ static qboolean ParseMapEntity( qboolean onlyLights )
brush->entityNum = mapEnt->mapEntityNum; brush->entityNum = mapEnt->mapEntityNum;
brush->castShadows = castShadows; brush->castShadows = castShadows;
brush->recvShadows = recvShadows; brush->recvShadows = recvShadows;
brush->lightmapSampleSize = lightmapSampleSize;
brush->lightmapScale = lightmapScale; brush->lightmapScale = lightmapScale;
brush->celShader = celShader; brush->celShader = celShader;
brush->shadeAngleDegrees = shadeAngle; brush->shadeAngleDegrees = shadeAngle;
@ -1618,6 +1633,7 @@ static qboolean ParseMapEntity( qboolean onlyLights )
patch->entityNum = mapEnt->mapEntityNum; patch->entityNum = mapEnt->mapEntityNum;
patch->castShadows = castShadows; patch->castShadows = castShadows;
patch->recvShadows = recvShadows; patch->recvShadows = recvShadows;
patch->lightmapSampleSize = lightmapSampleSize;
patch->lightmapScale = lightmapScale; patch->lightmapScale = lightmapScale;
patch->celShader = celShader; patch->celShader = celShader;
} }

View File

@ -206,7 +206,7 @@ InsertModel() - ydnar
adds a picomodel into the bsp 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; int i, j, k, s, numSurfaces;
m4x4_t identity, nTransform; m4x4_t identity, nTransform;
@ -252,6 +252,10 @@ void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shade
/* fix bogus lightmap scale */ /* fix bogus lightmap scale */
if( lightmapScale <= 0.0f ) if( lightmapScale <= 0.0f )
lightmapScale = 1.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 */ /* each surface on the model will become a new map drawsurface */
numSurfaces = PicoGetModelNumSurfaces( model ); numSurfaces = PicoGetModelNumSurfaces( model );
@ -322,18 +326,21 @@ void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shade
if( (si != NULL && si->forceMeta) || (spawnFlags & 4) ) /* 3rd bit */ if( (si != NULL && si->forceMeta) || (spawnFlags & 4) ) /* 3rd bit */
ds->type = SURFACE_FORCED_META; 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) */ /* fix the surface's normals (jal: conditioned by shader info) */
if( !(spawnFlags & 64) && ( shadeAngle == 0.0f || ds->type != SURFACE_FORCED_META ) ) if( !(spawnFlags & 64) && ( shadeAngle == 0.0f || ds->type != SURFACE_FORCED_META ) )
PicoFixSurfaceNormals( surface ); PicoFixSurfaceNormals( surface );
/* set sample size */
if( lightmapSampleSize > 0.0f )
ds->sampleSize = lightmapSampleSize;
/* set lightmap scale */ /* set lightmap scale */
ds->lightmapScale = lightmapScale; if( lightmapScale > 0.0f )
ds->lightmapScale = lightmapScale;
/* set shading angle */
if( shadeAngle > 0.0f )
ds->shadeAngleDegrees = shadeAngle;
/* set particulars */ /* set particulars */
ds->numVerts = PicoGetSurfaceNumVertexes( surface ); ds->numVerts = PicoGetSurfaceNumVertexes( surface );
@ -605,6 +612,7 @@ void AddTriangleModels( entity_t *e )
shaderInfo_t *celShader; shaderInfo_t *celShader;
float temp, baseLightmapScale, lightmapScale; float temp, baseLightmapScale, lightmapScale;
float shadeAngle; float shadeAngle;
int lightmapSampleSize;
vec3_t origin, scale, angles; vec3_t origin, scale, angles;
m4x4_t transform; m4x4_t transform;
epair_t *ep; epair_t *ep;
@ -629,11 +637,22 @@ void AddTriangleModels( entity_t *e )
/* get lightmap scale */ /* get lightmap scale */
/* vortex: added _ls key (short name of lightmapscale) */ /* vortex: added _ls key (short name of lightmapscale) */
baseLightmapScale = FloatForKey( e, "_lightmapscale" ); baseLightmapScale = 0.0f;
if( baseLightmapScale <= 0.0f ) if( strcmp( "", ValueForKey( e, "lightmapscale" ) ) ||
baseLightmapScale = FloatForKey( e, "_ls" ); strcmp( "", ValueForKey( e, "_lightmapscale" ) ) ||
if( baseLightmapScale <= 0.0f ) strcmp( "", ValueForKey( e, "_ls" ) ) )
baseLightmapScale = 0.0f; {
baseLightmapScale = FloatForKey( e, "lightmapscale" );
if( baseLightmapScale <= 0.0f )
baseLightmapScale = FloatForKey( e, "_lightmapscale" );
if( baseLightmapScale <= 0.0f )
baseLightmapScale = FloatForKey( e, "_ls" );
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 */ /* walk the entity list */
for( num = 1; num < numEntities; num++ ) for( num = 1; num < numEntities; num++ )
@ -751,14 +770,37 @@ void AddTriangleModels( entity_t *e )
} }
else else
celShader = *globalCelShader ? ShaderInfoForShader(globalCelShader) : NULL; 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 */ /* get lightmap scale */
/* vortex: added _ls key (short name of lightmapscale) */ /* vortex: added _ls key (short name of lightmapscale) */
lightmapScale = FloatForKey( e2, "_lightmapscale" ); lightmapScale = 0.0f;
if( lightmapScale <= 0.0f ) if( strcmp( "", ValueForKey( e2, "lightmapscale" ) ) ||
lightmapScale = FloatForKey( e2, "_ls" ); strcmp( "", ValueForKey( e2, "_lightmapscale" ) ) ||
if( lightmapScale <= 0.0f ) strcmp( "", ValueForKey( e2, "_ls" ) ) )
lightmapScale = baseLightmapScale; {
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 = 0.0f;
if( lightmapScale > 0.0f )
Sys_Printf( "misc_model has lightmap scale of %.4f\n", lightmapScale );
}
/* jal : entity based _shadeangle */ /* jal : entity based _shadeangle */
shadeAngle = 0.0f; shadeAngle = 0.0f;
@ -779,7 +821,7 @@ void AddTriangleModels( entity_t *e )
Sys_Printf( "misc_model has shading angle of %.4f\n", shadeAngle ); Sys_Printf( "misc_model has shading angle of %.4f\n", shadeAngle );
/* insert the model */ /* 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 */ /* free shader remappings */
while( remap != NULL ) while( remap != NULL )

View File

@ -889,6 +889,7 @@ typedef struct brush_s
shaderInfo_t *celShader; /* :) */ shaderInfo_t *celShader; /* :) */
/* ydnar: gs mods */ /* ydnar: gs mods */
int lightmapSampleSize; /* jal : entity based _lightmapsamplesize */
float lightmapScale; float lightmapScale;
float shadeAngleDegrees; /* jal : entity based _shadeangle */ float shadeAngleDegrees; /* jal : entity based _shadeangle */
vec3_t eMins, eMaxs; vec3_t eMins, eMaxs;
@ -941,6 +942,7 @@ typedef struct parseMesh_s
shaderInfo_t *celShader; /* :) */ shaderInfo_t *celShader; /* :) */
/* ydnar: gs mods */ /* ydnar: gs mods */
int lightmapSampleSize; /* jal : entity based _lightmapsamplesize */
float lightmapScale; float lightmapScale;
vec3_t eMins, eMaxs; vec3_t eMins, eMaxs;
indexMap_t *im; indexMap_t *im;
@ -1639,7 +1641,7 @@ void PicoPrintFunc( int level, const char *str );
void PicoLoadFileFunc( char *name, byte **buffer, int *bufSize ); void PicoLoadFileFunc( char *name, byte **buffer, int *bufSize );
picoModel_t *FindModel( char *name, int frame ); picoModel_t *FindModel( char *name, int frame );
picoModel_t *LoadModel( 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 ); void AddTriangleModels( entity_t *e );

View File

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

View File

@ -631,21 +631,26 @@ void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds )
//% Sys_Printf( "Failed to map axis %d onto patch\n", bestAxis ); //% Sys_Printf( "Failed to map axis %d onto patch\n", bestAxis );
} }
/* get lightmap sample size */ /* calculate lightmap sample size */
if( ds->sampleSize <= 0 ) if( ds->shaderInfo->lightmapSampleSize > 0 ) /* shader value overrides every other */
ds->sampleSize = ds->shaderInfo->lightmapSampleSize;
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 = sampleSize; ds->sampleSize = ds->lightmapScale * (float)ds->sampleSize;
if( ds->shaderInfo->lightmapSampleSize ) ds->lightmapScale = 0; /* applied */
ds->sampleSize = ds->shaderInfo->lightmapSampleSize;
if( ds->lightmapScale > 0 )
ds->sampleSize *= ds->lightmapScale;
if( ds->sampleSize <= 0 )
ds->sampleSize = 1;
if(ds->sampleSize < minSampleSize)
ds->sampleSize = minSampleSize;
if( ds->sampleSize > 16384 ) /* powers of 2 are preferred */
ds->sampleSize = 16384;
} }
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->mapBrush = b;
ds->sideRef = AllocSideRef( s, NULL ); ds->sideRef = AllocSideRef( s, NULL );
ds->fogNum = -1; ds->fogNum = -1;
ds->sampleSize = b->lightmapSampleSize;
ds->lightmapScale = b->lightmapScale; ds->lightmapScale = b->lightmapScale;
ds->numVerts = w->numpoints; ds->numVerts = w->numpoints;
ds->verts = safe_malloc( ds->numVerts * sizeof( *ds->verts ) ); 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; ds->celShader = b->celShader;
/* set shade angle */ /* set shade angle */
if( si->shadeAngleDegrees ) if( b->shadeAngleDegrees > 0.0f )
ds->shadeAngleDegrees = ds->shadeAngleDegrees; ds->shadeAngleDegrees = b->shadeAngleDegrees;
else
ds->shadeAngleDegrees = b->shadeAngleDegrees; /* otherwise it's 0 */
/* ydnar: gs mods: moved st biasing elsewhere */ /* ydnar: gs mods: moved st biasing elsewhere */
return ds; return ds;
@ -1103,6 +1107,7 @@ mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh
ds->shaderInfo = si; ds->shaderInfo = si;
ds->mapMesh = p; ds->mapMesh = p;
ds->sampleSize = p->lightmapSampleSize;
ds->lightmapScale = p->lightmapScale; /* ydnar */ ds->lightmapScale = p->lightmapScale; /* ydnar */
ds->patchWidth = mesh->width; ds->patchWidth = mesh->width;
ds->patchHeight = mesh->height; ds->patchHeight = mesh->height;
@ -3133,7 +3138,7 @@ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, b
} }
/* insert the model */ /* 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 to sender */
return 1; return 1;

View File

@ -275,7 +275,7 @@ void Foliage( mapDrawSurface_t *src )
m4x4_scale_for_vec3( transform, scale ); m4x4_scale_for_vec3( transform, scale );
/* add the model to the bsp */ /* 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 */ /* walk each new surface */
for( i = oldNumMapDrawSurfs; i < numMapDrawSurfs; i++ ) 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->planeNum = seed->planeNum;
ds->fogNum = seed->fogNum; ds->fogNum = seed->fogNum;
ds->sampleSize = seed->sampleSize; ds->sampleSize = seed->sampleSize;
ds->shadeAngleDegrees = seed->shadeAngleDegrees;
ds->verts = verts; ds->verts = verts;
ds->indexes = indexes; ds->indexes = indexes;
VectorCopy( seed->lightmapAxis, ds->lightmapAxis ); VectorCopy( seed->lightmapAxis, ds->lightmapAxis );