From: divverent Date: Fri, 1 May 2009 10:45:24 +0000 (+0000) Subject: _lightmapsamplesize entity key by jal X-Git-Tag: svn-r421~61 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c005536caf84ce760f2030ae121ba52151fd7960;p=xonotic%2Fnetradiant.git _lightmapsamplesize entity key by jal git-svn-id: svn://svn.icculus.org/netradiant/trunk@359 61c419a2-8eb2-4b30-bcec-8cead039b335 --- diff --git a/tools/quake3/q3map2/decals.c b/tools/quake3/q3map2/decals.c index f4de7cea..a130334f 100644 --- a/tools/quake3/q3map2/decals.c +++ b/tools/quake3/q3map2/decals.c @@ -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 ) ); diff --git a/tools/quake3/q3map2/map.c b/tools/quake3/q3map2/map.c index 7b8107b5..0173d834 100644 --- a/tools/quake3/q3map2/map.c +++ b/tools/quake3/q3map2/map.c @@ -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,12 +1566,12 @@ 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" ); if( value[ 0 ] == '\0' ) @@ -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; } diff --git a/tools/quake3/q3map2/model.c b/tools/quake3/q3map2/model.c index 72ce6a5d..083e795f 100644 --- a/tools/quake3/q3map2/model.c +++ b/tools/quake3/q3map2/model.c @@ -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; @@ -252,6 +252,10 @@ void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shade /* fix bogus lightmap scale */ 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 ); @@ -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 */ 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 */ - ds->lightmapScale = lightmapScale; + if( lightmapScale > 0.0f ) + ds->lightmapScale = lightmapScale; + + /* set shading angle */ + if( shadeAngle > 0.0f ) + ds->shadeAngleDegrees = shadeAngle; /* set particulars */ ds->numVerts = PicoGetSurfaceNumVertexes( surface ); @@ -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 = FloatForKey( e, "_lightmapscale" ); - if( baseLightmapScale <= 0.0f ) - baseLightmapScale = FloatForKey( e, "_ls" ); - if( baseLightmapScale <= 0.0f ) - baseLightmapScale = 0.0f; + 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 ) + 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++ ) @@ -751,14 +770,37 @@ 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 = FloatForKey( e2, "_lightmapscale" ); - if( lightmapScale <= 0.0f ) - lightmapScale = FloatForKey( e2, "_ls" ); - if( lightmapScale <= 0.0f ) - lightmapScale = baseLightmapScale; + 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 = 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 ) diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index bd668ba7..590b817c 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -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 ); diff --git a/tools/quake3/q3map2/shaders.c b/tools/quake3/q3map2/shaders.c index e5292934..74f5e59c 100644 --- a/tools/quake3/q3map2/shaders.c +++ b/tools/quake3/q3map2/shaders.c @@ -1531,7 +1531,7 @@ static void ParseShaderFile( const char *filename ) si->lightmapSampleSize = atoi( token ); } - /* q3map_lightmapSampleSffset */ + /* q3map_lightmapSampleOffset */ else if( !Q_stricmp( token, "q3map_lightmapSampleOffset" ) ) { GetTokenAppend( shaderText, qfalse ); diff --git a/tools/quake3/q3map2/surface.c b/tools/quake3/q3map2/surface.c index 98baf921..a99c5800 100644 --- a/tools/quake3/q3map2/surface.c +++ b/tools/quake3/q3map2/surface.c @@ -631,21 +631,26 @@ 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 ) + /* calculate lightmap sample size */ + 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; - if( ds->shaderInfo->lightmapSampleSize ) - 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; + 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; diff --git a/tools/quake3/q3map2/surface_foliage.c b/tools/quake3/q3map2/surface_foliage.c index 97e18e5b..71875af0 100644 --- a/tools/quake3/q3map2/surface_foliage.c +++ b/tools/quake3/q3map2/surface_foliage.c @@ -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++ ) diff --git a/tools/quake3/q3map2/surface_meta.c b/tools/quake3/q3map2/surface_meta.c index a62cdf37..f0d48b3d 100644 --- a/tools/quake3/q3map2/surface_meta.c +++ b/tools/quake3/q3map2/surface_meta.c @@ -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 );