better shadeangle support by jal

git-svn-id: svn://svn.icculus.org/netradiant/trunk@355 61c419a2-8eb2-4b30-bcec-8cead039b335
This commit is contained in:
divverent 2009-04-29 15:27:46 +00:00
parent d0244e3b2e
commit 65fcedfc4c
6 changed files with 83 additions and 43 deletions

View File

@ -1415,7 +1415,7 @@ static qboolean ParseMapEntity( qboolean onlyLights )
{
epair_t *ep;
const char *classname, *value;
float lightmapScale;
float lightmapScale, shadeAngle;
char shader[ MAX_QPATH ];
shaderInfo_t *celShader = NULL;
brush_t *brush;
@ -1569,7 +1569,7 @@ static qboolean ParseMapEntity( qboolean onlyLights )
}
else
lightmapScale = 0.0f;
/* ydnar: get cel shader :) for this entity */
value = ValueForKey( mapEnt, "_celshader" );
if( value[ 0 ] == '\0' )
@ -1582,6 +1582,25 @@ static qboolean ParseMapEntity( qboolean onlyLights )
}
else
celShader = *globalCelShader ? ShaderInfoForShader(globalCelShader) : NULL;
/* jal : entity based _shadeangle */
shadeAngle = 0.0f;
if ( strcmp( "", ValueForKey( mapEnt, "_shadeangle" ) ) )
shadeAngle = FloatForKey( mapEnt, "_shadeangle" );
/* vortex' aliases */
else if ( strcmp( "", ValueForKey( mapEnt, "_smoothnormals" ) ) )
shadeAngle = FloatForKey( mapEnt, "_smoothnormals" );
else if ( strcmp( "", ValueForKey( mapEnt, "_sn" ) ) )
shadeAngle = FloatForKey( mapEnt, "_sn" );
else if ( strcmp( "", ValueForKey( mapEnt, "_smooth" ) ) )
shadeAngle = FloatForKey( mapEnt, "_smooth" );
if( shadeAngle < 0.0f )
shadeAngle = 0.0f;
if( shadeAngle > 0.0f )
Sys_Printf( "Entity %d (%s) has shading angle of %.4f\n", mapEnt->mapEntityNum, classname, shadeAngle );
/* attach stuff to everything in the entity */
for( brush = mapEnt->brushes; brush != NULL; brush = brush->next )
@ -1591,6 +1610,7 @@ static qboolean ParseMapEntity( qboolean onlyLights )
brush->recvShadows = recvShadows;
brush->lightmapScale = lightmapScale;
brush->celShader = celShader;
brush->shadeAngleDegrees = shadeAngle;
}
for( patch = mapEnt->patches; patch != NULL; patch = patch->next )

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 )
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 )
{
int i, j, k, s, numSurfaces;
m4x4_t identity, nTransform;
@ -267,10 +267,6 @@ void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shade
if( PicoGetSurfaceType( surface ) != PICO_TRIANGLES )
continue;
/* fix the surface's normals */
if( !(spawnFlags & 64) )
PicoFixSurfaceNormals( surface );
/* allocate a surface (ydnar: gs mods) */
ds = AllocDrawSurface( SURFACE_TRIANGLES );
ds->entityNum = eNum;
@ -321,13 +317,23 @@ void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shade
/* set shader */
ds->shaderInfo = si;
/* set lightmap scale */
ds->lightmapScale = lightmapScale;
/* force to meta? */
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 lightmap scale */
ds->lightmapScale = lightmapScale;
/* set particulars */
ds->numVerts = PicoGetSurfaceNumVertexes( surface );
@ -598,6 +604,7 @@ void AddTriangleModels( entity_t *e )
char shader[ MAX_QPATH ];
shaderInfo_t *celShader;
float temp, baseLightmapScale, lightmapScale;
float shadeAngle;
vec3_t origin, scale, angles;
m4x4_t transform;
epair_t *ep;
@ -752,9 +759,27 @@ void AddTriangleModels( entity_t *e )
lightmapScale = FloatForKey( e2, "_ls" );
if( lightmapScale <= 0.0f )
lightmapScale = baseLightmapScale;
/* jal : entity based _shadeangle */
shadeAngle = 0.0f;
if ( strcmp( "", ValueForKey( e2, "_shadeangle" ) ) )
shadeAngle = FloatForKey( e2, "_shadeangle" );
/* vortex' aliases */
else if ( strcmp( "", ValueForKey( mapEnt, "_smoothnormals" ) ) )
shadeAngle = FloatForKey( mapEnt, "_smoothnormals" );
else if ( strcmp( "", ValueForKey( mapEnt, "_sn" ) ) )
shadeAngle = FloatForKey( mapEnt, "_sn" );
else if ( strcmp( "", ValueForKey( mapEnt, "_smooth" ) ) )
shadeAngle = FloatForKey( mapEnt, "_smooth" );
if( shadeAngle < 0.0f )
shadeAngle = 0.0f;
if( shadeAngle > 0.0f )
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 );
InsertModel( (char*) model, frame, transform, remap, celShader, mapEntityNum, castShadows, recvShadows, spawnFlags, lightmapScale, shadeAngle );
/* free shader remappings */
while( remap != NULL )

View File

@ -890,6 +890,7 @@ typedef struct brush_s
/* ydnar: gs mods */
float lightmapScale;
float shadeAngleDegrees; /* jal : entity based _shadeangle */
vec3_t eMins, eMaxs;
indexMap_t *im;
@ -1037,6 +1038,9 @@ typedef struct mapDrawSurface_s
/* ydnar: per-surface (per-entity, actually) lightmap sample size scaling */
float lightmapScale;
/* jal: per-surface (per-entity, actually) shadeangle */
float shadeAngleDegrees;
/* ydnar: surface classification */
vec3_t mins, maxs;
@ -1080,6 +1084,7 @@ typedef struct metaTriangle_s
shaderInfo_t *si;
side_t *side;
int entityNum, surfaceNum, planeNum, fogNum, sampleSize, castShadows, recvShadows;
float shadeAngleDegrees;
vec4_t plane;
vec3_t lightmapAxis;
int indexes[ 3 ];
@ -1104,7 +1109,6 @@ typedef struct
int firstBrush, numBrushes; /* only valid during BSP compile */
epair_t *epairs;
vec3_t originbrush_origin;
qboolean forceNormalSmoothing; /* vortex: true if entity has _smoothnormals/_sn/_smooth key */
}
entity_t;
@ -1635,7 +1639,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 );
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 AddTriangleModels( entity_t *e );

View File

@ -989,6 +989,12 @@ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, windin
/* set cel shader */
ds->celShader = b->celShader;
/* set shade angle */
if( si->shadeAngleDegrees )
ds->shadeAngleDegrees = ds->shadeAngleDegrees;
else
ds->shadeAngleDegrees = b->shadeAngleDegrees; /* otherwise it's 0 */
/* ydnar: gs mods: moved st biasing elsewhere */
return ds;
@ -3127,7 +3133,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 );
InsertModel( (char *) model->model, 0, transform, NULL, ds->celShader, ds->entityNum, ds->castShadows, ds->recvShadows, 0, ds->lightmapScale, 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 );
InsertModel( foliage->model, 0, transform, NULL, NULL, src->entityNum, src->castShadows, src->recvShadows, 0, src->lightmapScale, 0 );
/* walk each new surface */
for( i = oldNumMapDrawSurfs; i < numMapDrawSurfs; i++ )

View File

@ -288,6 +288,7 @@ static void SurfaceToMetaTriangles( mapDrawSurface_t *ds )
src.recvShadows = ds->recvShadows;
src.fogNum = ds->fogNum;
src.sampleSize = ds->sampleSize;
src.shadeAngleDegrees = ds->shadeAngleDegrees;
VectorCopy( ds->lightmapAxis, src.lightmapAxis );
/* copy drawverts */
@ -1005,7 +1006,6 @@ void SmoothMetaTriangles( void )
vec3_t average, diff;
int indexes[ MAX_SAMPLES ];
vec3_t votes[ MAX_SAMPLES ];
const char *classname;
/* note it */
Sys_FPrintf( SYS_VRB, "--- SmoothMetaTriangles ---\n" );
@ -1027,33 +1027,18 @@ void SmoothMetaTriangles( void )
and set per-vertex smoothing angle */
for( i = 0, tri = &metaTriangles[ i ]; i < numMetaTriangles; i++, tri++ )
{
/* vortex: try get smoothing from entity key */
shadeAngle = FloatForKey(&entities[tri->entityNum], "_shadeangle");
if (shadeAngle <= 0.0f)
shadeAngle = FloatForKey(&entities[tri->entityNum], "_smoothnormals");
if (shadeAngle <= 0.0f)
shadeAngle = FloatForKey(&entities[tri->entityNum], "_sn");
if (shadeAngle <= 0.0f)
shadeAngle = FloatForKey(&entities[tri->entityNum], "_smooth");
if (shadeAngle > 0.0f)
{
if (entities[tri->entityNum].forceNormalSmoothing == qfalse)
{
entities[tri->entityNum].forceNormalSmoothing = qtrue;
classname = ValueForKey( &entities[tri->entityNum], "classname" );
Sys_Printf( "Entity %d (%s) has vertex normal smoothing with breaking angle of %3.0f\n", tri->entityNum, classname, shadeAngle );
}
shadeAngle = DEG2RAD( shadeAngle );
}
shadeAngle = defaultShadeAngle;
/* get shade angle from shader */
if( tri->si->shadeAngleDegrees > 0.0f )
shadeAngle = DEG2RAD( tri->si->shadeAngleDegrees );
/* get shade angle from entity */
else if( tri->shadeAngleDegrees > 0.0f )
shadeAngle = DEG2RAD( tri->shadeAngleDegrees );
if( shadeAngle <= 0.0f )
shadeAngle = defaultShadeAngle;
/* get shader for shade angle */
if (shadeAngle <= 0.0f)
{
if( tri->si->shadeAngleDegrees > 0.0f )
shadeAngle = DEG2RAD( tri->si->shadeAngleDegrees );
else
shadeAngle = defaultShadeAngle;
}
if( shadeAngle > maxShadeAngle )
maxShadeAngle = shadeAngle;