]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/light_trace.c
try to help subsampling with grates
[xonotic/netradiant.git] / tools / quake3 / q3map2 / light_trace.c
index ea3769a1b4d1fab59bcd0e261fc2425ca282e619..d035ee01324f8d931542bf803743d9768c79054d 100644 (file)
@@ -73,7 +73,7 @@ traceVert_t;
 typedef struct traceInfo_s
 {
        shaderInfo_t                            *si;
-       int                                                     surfaceNum, castShadows;
+       int                                                     surfaceNum, castShadows, skipGrid;
 }
 traceInfo_t;
 
@@ -144,7 +144,8 @@ static int AddTraceInfo( traceInfo_t *ti )
        {
                if( traceInfos[ num ].si == ti->si &&
                        traceInfos[ num ].surfaceNum == ti->surfaceNum &&
-                       traceInfos[ num ].castShadows == ti->castShadows )
+                       traceInfos[ num ].castShadows == ti->castShadows &&
+                       traceInfos[ num ].skipGrid == ti->skipGrid )
                        return num;
        }
        
@@ -401,7 +402,13 @@ static int SetupTraceNodes_r( int bspNodeNum )
                
                /* normal node */
                else
-                       traceNodes[ nodeNum ].children[ i ] = SetupTraceNodes_r( bspNode->children[ i ] );
+               {
+                       newNode = SetupTraceNodes_r( bspNode->children[ i ] );
+                       traceNodes[ nodeNum ].children[ i ] = newNode;
+               }
+
+               if(traceNodes[ nodeNum ].children[ i ] == 0)
+                       Error( "Invalid tracenode allocated" );
        }
 
        /* Sys_Printf("node %d children: %d %d\n", nodeNum, traceNodes[ nodeNum ].children[0], traceNodes[ nodeNum ].children[1]); */
@@ -968,6 +975,7 @@ static void PopulateWithBSPModel( bspModel_t *model, m4x4_t transform )
                ti.si = info->si;
                ti.castShadows = info->castShadows;
                ti.surfaceNum = model->firstBSPBrush + i;
+               ti.skipGrid = (ds->surfaceType == MST_PATCH);
                
                /* choose which node (normal or skybox) */
                if( info->parentSurfaceNum >= 0 )
@@ -1137,6 +1145,7 @@ static void PopulateWithPicoModel( int castShadows, picoModel_t *model, m4x4_t t
                /* setup trace info */
                ti.castShadows = castShadows;
                ti.surfaceNum = -1;
+               ti.skipGrid = qtrue; // also ignore picomodels when skipping patches
                
                /* setup trace winding */
                memset( &tw, 0, sizeof( tw ) );
@@ -1420,7 +1429,7 @@ qboolean TraceTriangle( traceInfo_t *ti, traceTriangle_t *tt, trace_t *trace )
                if( ti->castShadows != 1 )
                        return qfalse;
        }
-       
+
        /* receive shadows from same group and worldspawn group */
        else if( trace->recvShadows > 1 )
        {
@@ -1436,6 +1445,13 @@ qboolean TraceTriangle( traceInfo_t *ti, traceTriangle_t *tt, trace_t *trace )
                        return qfalse;
        }
        
+       /* skip patches when doing the grid (FIXME this is an ugly hack) */
+       if( inGrid )
+       {
+               if (ti->skipGrid)
+                       return qfalse;
+       }
+       
        /* begin calculating determinant - also used to calculate u parameter */
        CrossProduct( trace->direction, tt->edge2, pvec );
        
@@ -1537,6 +1553,7 @@ qboolean TraceTriangle( traceInfo_t *ti, traceTriangle_t *tt, trace_t *trace )
        /* check filter for opaque */
        if( trace->color[ 0 ] <= 0.001f && trace->color[ 1 ] <= 0.001f && trace->color[ 2 ] <= 0.001f )
        {
+               VectorClear( trace->color );
                VectorMA( trace->origin, depth, trace->direction, trace->hit );
                trace->opaque = qtrue;
                return qtrue;