Skip to content

Commit ab6100b

Browse files
authored
utils: pxrad: fix crash when no lightmapped faces, remove old fastsky (#257)
1 parent 0f1be39 commit ab6100b

File tree

4 files changed

+20
-25
lines changed

4 files changed

+20
-25
lines changed

utils/pxrad/lerp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,7 @@ void GetTriangulationPatches( int facenum, int *numpatches, const int **patches
17641764
{
17651765
const facetriangulation_t *facetrian;
17661766

1767-
if( g_numbounce <= 0 && !g_fastmode && g_indirect_sun == 0.0f )
1767+
if( !g_usingpatches )
17681768
{
17691769
*numpatches = 0;
17701770
*patches = NULL;

utils/pxrad/lightmap.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,7 +2548,7 @@ GatherSampleLight
25482548
=============
25492549
*/
25502550
void GatherSampleLight( int threadnum, int fn, const vec3_t pos, int leafnum, const vec3_t n,
2551-
vec3_t *s_light, vec3_t *s_dir, vec_t *s_occ, byte *styles, byte *vislight, bool topatch, entity_t *ignoreent, const vec_t sky_visibility )
2551+
vec3_t *s_light, vec3_t *s_dir, vec_t *s_occ, byte *styles, byte *vislight, bool topatch, entity_t *ignoreent )
25522552
{
25532553
vec3_t add, delta, add_one;
25542554
vec3_t testline_origin;
@@ -2567,7 +2567,7 @@ vec3_t *s_light, vec3_t *s_dir, vec_t *s_occ, byte *styles, byte *vislight, bool
25672567
// check light visibility
25682568
if( leafnum && g_fakeskylight.pvs && CHECKVISBIT( g_fakeskylight.pvs, leafnum - 1 ) )
25692569
{
2570-
int skylevel = g_fastsky && (sky_visibility > 2.0f) ? SKYLEVEL_FASTSKY : SKYLEVEL_SOFTSKYON;
2570+
int skylevel = SKYLEVEL_SOFTSKYON;
25712571

25722572
vec3_t *skynormals = g_skynormals[skylevel];
25732573
vec3_t sky_intensity;
@@ -3484,7 +3484,7 @@ void BuildFaceLights( int facenum, int thread )
34843484
{
34853485
int leafnum = p->leafnum;
34863486
#ifdef HLRAD_DELUXEMAPPING
3487-
GatherSampleLight( thread, l.surfnum, p->origin, leafnum, normal, p->totallight, p->totallight_dir, NULL, p->totalstyle, NULL, 1, NULL, M_PI - p->trans_sum );
3487+
GatherSampleLight( thread, l.surfnum, p->origin, leafnum, normal, p->totallight, p->totallight_dir, NULL, p->totalstyle, NULL, 1, NULL );
34883488
#else
34893489
GatherSampleLight( thread, l.surfnum, p->origin, leafnum, normal, p->totallight, NULL, NULL, p->totalstyle, NULL, 1 );
34903490
#endif

utils/pxrad/qrad.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,10 @@ vec_t g_lightprobeepsilon = DEFAULT_LIGHTPROBE_EPSILON;
7777
int g_lightprobesamples = 256;
7878
bool g_vertexblur = false;
7979
uint g_numstudiobounce = DEFAULT_STUDIO_BOUNCE;
80-
int g_studiogipasscounter = 0;
81-
vec3_t *g_studioskynormals;
82-
int g_numstudioskynormals;
80+
int g_studiogipasscounter = 0;
8381
bool g_noemissive = false;
84-
int g_skystyle = -1;
82+
int g_skystyle = -1;
83+
bool g_usingpatches = true;
8584

8685

8786
bool g_drawsample = false;
@@ -1918,8 +1917,7 @@ static void SortPatches( void )
19181917
}
19191918
}
19201919

1921-
// if we haven't patches we don't need bounces
1922-
if( g_num_patches <= 0 ) g_numbounce = 0;
1920+
if( g_num_patches <= 0 ) g_usingpatches = false;
19231921
}
19241922

19251923
/*
@@ -2516,8 +2514,6 @@ void RadWorld( void )
25162514
RunThreadsOnIndividual( g_numfaces, true, FindFacePositions );
25172515
CalcPositionsSize();
25182516

2519-
if( g_fastsky )
2520-
MakeTransfers();
25212517
if( g_envsky )
25222518
LoadEnvSkyTextures();
25232519

@@ -2529,7 +2525,7 @@ void RadWorld( void )
25292525
#ifdef HLRAD_VERTEXLIGHTING
25302526
BuildVertexLights(); //BuildFaceLights will get single gi bounce from studiomodels
25312527

2532-
if( g_numstudiobounce > 0 || g_indirect_sun > 0.0f )
2528+
if( g_numstudiobounce > 0 )
25332529
{
25342530
g_studiogipasscounter = 1;
25352531
VertexPatchLights();
@@ -2546,11 +2542,10 @@ void RadWorld( void )
25462542

25472543
CalcLuxelsCount();
25482544

2549-
if( g_numbounce > 0 )
2545+
if( g_numbounce > 0 && g_usingpatches )
25502546
{
25512547
// build transfer lists
2552-
if(!g_fastsky)
2553-
MakeTransfers();
2548+
MakeTransfers();
25542549

25552550
emitlight = (vec3_t (*)[MAXLIGHTMAPS])Mem_Alloc(( g_num_patches + 1 ) * sizeof( vec3_t[MAXLIGHTMAPS] ));
25562551
addlight = (vec3_t (*)[MAXLIGHTMAPS])Mem_Alloc(( g_num_patches + 1 ) * sizeof( vec3_t[MAXLIGHTMAPS] ));
@@ -2574,10 +2569,9 @@ void RadWorld( void )
25742569
emitlight_dir = NULL;
25752570
addlight_dir = NULL;
25762571
#endif
2577-
}
2578-
2579-
if( g_fastsky ||( g_numbounce > 0 ))
2572+
// transfers don't need anymore
25802573
FreeTransfers();
2574+
}
25812575

25822576
// remove direct light from patches
25832577
for( int i = 0; i < g_num_patches; i++ )
@@ -2597,13 +2591,13 @@ void RadWorld( void )
25972591
ScaleDirectLights();
25982592

25992593
// because fastmode uses patches instead of samples
2600-
if( g_numbounce > 0 || g_fastmode || g_indirect_sun > 0.0f )
2594+
if( g_usingpatches )
26012595
RunThreadsOnIndividual( g_numfaces, false, CreateTriangulations );
26022596

26032597
// blend bounced light into direct light and save
26042598
PrecompLightmapOffsets();
26052599

2606-
if( g_numbounce > 0 || g_fastmode || g_indirect_sun > 0.0f )
2600+
if( g_usingpatches )
26072601
{
26082602
CreateFacelightDependencyList();
26092603

@@ -2612,7 +2606,7 @@ void RadWorld( void )
26122606
FreeFacelightDependencyList();
26132607
}
26142608

2615-
if( g_numbounce > 0 || g_fastmode || g_indirect_sun > 0.0f )
2609+
if( g_usingpatches )
26162610
FreeTriangulations();
26172611

26182612
if( g_lightbalance )
@@ -2626,7 +2620,7 @@ void RadWorld( void )
26262620

26272621
#ifdef HLRAD_VERTEXLIGHTING
26282622
g_studiogipasscounter = 0;
2629-
for( int i = 0; i < g_numstudiobounce; i++ )
2623+
for( int i = 0; i < Q_max( 1, g_numstudiobounce ); i++ )
26302624
{
26312625
g_studiogipasscounter++;
26322626
VertexPatchLights();
@@ -3085,6 +3079,7 @@ int main( int argc, char **argv )
30853079

30863080
if( g_skystyle < 0 )
30873081
g_skystyle = IntForKey( &g_entities[0], "zhlt_skystyle" );
3082+
g_usingpatches = g_numbounce > 0 || g_fastmode || g_indirect_sun > 0.0f;
30883083

30893084
// keep it in acceptable range
30903085
g_blur = bound( 1.0, g_blur, 8.0 );

utils/pxrad/qrad.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
#define SKYLEVELMAX 8
6363
#define SKYLEVEL_SOFTSKYON 7
6464
#define SKYLEVEL_SOFTSKYOFF 4
65-
#define SKYLEVEL_FASTSKY 6
6665
#define STUDIO_SAMPLES_PER_PASS 32
6766
#define STUDIO_SAMPLES_SKY 256
6867
#define SKYNORMALS_RANDOM 16384
@@ -439,6 +438,7 @@ extern int g_studiogipasscounter;
439438
extern vec3_t g_skynormals_random[SKYNORMALS_RANDOM];
440439
extern bool g_noemissive;
441440
extern int g_skystyle;
441+
extern bool g_usingpatches;
442442

443443
//
444444
// ambientcube.c
@@ -514,7 +514,7 @@ extern void FreeTriangulations( void );
514514
// lightmap.c
515515
//
516516
void GatherSampleLight( int threadnum, int fn, const vec3_t pos, int leafnum, const vec3_t normal,
517-
vec3_t *s_light, vec3_t *s_dir, vec_t *s_occ, byte *styles, byte *vislight, bool topatch, entity_t *ignoreent = NULL, const vec_t sky_visibility = 0.0f );
517+
vec3_t *s_light, vec3_t *s_dir, vec_t *s_occ, byte *styles, byte *vislight, bool topatch, entity_t *ignoreent = NULL );
518518
void TexelSpaceToWorld( const lightinfo_t *l, vec3_t world, const vec_t s, const vec_t t );
519519
void WorldToTexelSpace( const lightinfo_t *l, const vec3_t world, vec_t &s, vec_t &t );
520520
int ParseLightIntensity( const char *pLight, vec3_t intensity );

0 commit comments

Comments
 (0)