]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
better shadeangle support by jal
authordivverent <divverent@61c419a2-8eb2-4b30-bcec-8cead039b335>
Wed, 29 Apr 2009 15:27:46 +0000 (15:27 +0000)
committerdivverent <divverent@61c419a2-8eb2-4b30-bcec-8cead039b335>
Wed, 29 Apr 2009 15:27:46 +0000 (15:27 +0000)
git-svn-id: svn://svn.icculus.org/netradiant/trunk@355 61c419a2-8eb2-4b30-bcec-8cead039b335

tools/quake3/q3map2/map.c
tools/quake3/q3map2/model.c
tools/quake3/q3map2/q3map2.h
tools/quake3/q3map2/surface.c
tools/quake3/q3map2/surface_foliage.c
tools/quake3/q3map2/surface_meta.c

index 1906819adc5f5d98d1d994544b6d056cdd639eb5..7b8107b5480090fa1d618d2dd13fe32476e983c7 100644 (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 )
index c4df7ba774eddffc7d4fff4d76b6a8f14043ec34..72ce6a5d89e028c3e52beb52c3dcd1b281b75850 100644 (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 )
index e47bf798962b7eda75b196c5aff654981af735e4..bd668ba7dc9edb5c2789aa197101366b055b4f42 100644 (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 );
 
 
index cd8dba66f9be262da0fc3b9c25d5e01315fa393b..98baf9219cf6adb48b867da1e96abe81250caef4 100644 (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;
index e9a8ec71f91f4466b88712b32b40a958f0c704b8..97e18e5b449e910dec35ea3c88ccb3f8c8751ee6 100644 (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++ )
index 727d5a0fbd1aaa6def1512681a8cfe5b71294493..a62cdf37acabb8dc7cfa94c7bd62ab0a33369096 100644 (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;