* 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
This commit is contained in:
Garux 2021-09-08 19:22:18 +03:00
parent 23d82aa9ef
commit f3321cef5f
2 changed files with 32 additions and 18 deletions

View File

@ -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;
}
}
}
}

View File

@ -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;
}
}
}
}
}