From f3321cef5fd504ab487410ed76bd3de8a91c6552 Mon Sep 17 00:00:00 2001 From: Garux Date: Wed, 8 Sep 2021 19:22:18 +0300 Subject: [PATCH] * auto fog direction: try all sides, not just axial; default to none, if no visible sides * q3map_fogDir: pick best matching side, not strict match only; ignore invisible 'bevel' sides --- tools/quake3/q3map2/fog.cpp | 16 +++++++-------- tools/quake3/q3map2/writebsp.cpp | 34 ++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/tools/quake3/q3map2/fog.cpp b/tools/quake3/q3map2/fog.cpp index add59ae9..f763f358 100644 --- a/tools/quake3/q3map2/fog.cpp +++ b/tools/quake3/q3map2/fog.cpp @@ -670,17 +670,17 @@ void CreateMapFogs( void ){ fog.visibleSide = -1; /* if shader specifies an explicit direction, then find a matching brush side with an opposed normal */ - if ( vector3_length( fog.si->fogDir ) ) { - /* flip it */ - const Vector3 invFogDir = -fog.si->fogDir; - + if ( fog.si->fogDir != g_vector3_identity ) { + double bestDot = 0; /* find the brush side */ for ( size_t j = 0; j < brush.sides.size(); ++j ) { - if ( VectorCompare( invFogDir, mapplanes[ brush.sides[ j ].planenum ].normal() ) ) { - fog.visibleSide = j; - //% Sys_Printf( "Brush num: %d Side num: %d\n", fog->brushNum, fog->visibleSide ); - break; + if( !brush.sides[ j ].bevel ){ + const double dot = vector3_dot( fog.si->fogDir, mapplanes[ brush.sides[ j ].planenum ].normal() ); + if( dot < bestDot ){ + bestDot = dot; + fog.visibleSide = j; + } } } } diff --git a/tools/quake3/q3map2/writebsp.cpp b/tools/quake3/q3map2/writebsp.cpp index 813effe6..16a0da19 100644 --- a/tools/quake3/q3map2/writebsp.cpp +++ b/tools/quake3/q3map2/writebsp.cpp @@ -476,35 +476,49 @@ void EmitFogs( void ){ /* walk list */ for ( int i = 0; i < numMapFogs; i++ ) { + const fog_t& fog = mapFogs[i]; + bspFog_t& bspFog = bspFogs[i]; /* set shader */ // copy and clear the rest of memory - strncpy( bspFogs[ i ].shader, mapFogs[ i ].si->shader, sizeof( bspFogs[ i ].shader ) ); + strncpy( bspFog.shader, fog.si->shader, sizeof( bspFog.shader ) ); /* global fog doesn't have an associated brush */ - if ( mapFogs[ i ].brush == NULL ) { - bspFogs[ i ].brushNum = -1; - bspFogs[ i ].visibleSide = -1; + if ( fog.brush == NULL ) { + bspFog.brushNum = -1; + bspFog.visibleSide = -1; } else { /* set brush */ - bspFogs[ i ].brushNum = mapFogs[ i ].brush->outputNum; + bspFog.brushNum = fog.brush->outputNum; + bspFog.visibleSide = -1; // default to something sensible, not just zero index /* try to use forced visible side */ - if ( mapFogs[ i ].visibleSide >= 0 ) { - bspFogs[ i ].visibleSide = mapFogs[ i ].visibleSide; + if ( fog.visibleSide >= 0 ) { + bspFog.visibleSide = fog.visibleSide; continue; } - /* find visible side */ + /* find visible axial side */ for ( int j = 6; j-- > 0; ) // prioritize +Z (index 5) then -Z (index 4) in ambiguous case; fogged pit is assumed as most likely case { - if ( !mapFogs[ i ].brush->sides[ j ].visibleHull.empty() ) { + if ( !fog.brush->sides[ j ].visibleHull.empty() ) { Sys_Printf( "Fog %d has visible side %d\n", i, j ); - bspFogs[ i ].visibleSide = j; + bspFog.visibleSide = j; break; } } + /* try other sides */ + if( bspFog.visibleSide < 0 ){ + for ( size_t j = 6; j < fog.brush->sides.size(); ++j ) + { + if ( !fog.brush->sides[ j ].visibleHull.empty() ) { + Sys_Printf( "Fog %d has visible side %d\n", i, j ); + bspFog.visibleSide = j; + break; + } + } + } } }