Skip to content

Commit 9501439

Browse files
authored
utils: pxrad: push overlapping vertices outside the model to prevent overdarkening, add zhlt_vertexblur (#259)
1 parent 9d7b843 commit 9501439

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

utils/pxrad/vertexlight.cpp

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ void BuildVertexLights( int indexnum, int thread = -1 )
213213
NudgeVertexPosition( tv->light->pos ); // nudged vertexes will be used on indirect lighting too
214214
VectorCopy( tv->normal, normal );
215215

216-
// calculate visibility for the sample
217-
int leaf = PointInLeaf( tv->light->pos ) - g_dleafs;
216+
218217

219218
// two-sided verts pos will be adjusted later
220219
if( tv->twosided )
@@ -223,7 +222,39 @@ void BuildVertexLights( int indexnum, int thread = -1 )
223222
{
224223
VectorMA( tv->light->pos, DEFAULT_HUNT_OFFSET, tv->normal, point );
225224
VectorCopy( point, tv->light->pos );
225+
226+
//check overlapping by back faces
227+
if( FBitSet( mesh->flags, FMESH_SELF_SHADOW )&&( !g_studiolegacy ) )
228+
{
229+
vec3_t trace_end;
230+
vec3_t trace_dir;
231+
trace_t trace;
232+
233+
VectorSubtract( point, tv->point, trace_dir );
234+
VectorAdd( trace_dir, tv->normal, trace_dir );
235+
VectorNormalize2( trace_dir );
236+
237+
VectorMA( point, 8.0f, trace_dir, trace_end );
238+
239+
for( int i = 0; i < 8; i++ )
240+
{
241+
trace.contents = CONTENTS_EMPTY;
242+
mesh->rayBVH.TraceRay( point, trace_end, &trace, false );
243+
if( (trace.contents == CONTENTS_SOLID)&&(trace.surface == -1) )
244+
{
245+
VectorLerp( point, trace.fraction, trace_end, point );
246+
VectorMA( point, DEFAULT_HUNT_OFFSET, trace_dir, point );
247+
}
248+
else
249+
break;
250+
}
251+
252+
VectorCopy( point, tv->light->pos );
253+
}
226254
}
255+
256+
// calculate visibility for the sample
257+
int leaf = PointInLeaf( tv->light->pos ) - g_dleafs;
227258

228259
memset( light, 0, sizeof( light ));
229260
memset( delux, 0, sizeof( delux ));
@@ -521,6 +552,7 @@ void FinalLightVertex( int modelnum, int threadnum = -1 )
521552
vec3_t lb, v, direction;
522553
int lightstyles;
523554
vec_t minlight;
555+
bool vertexblur;
524556
tmesh_t *mesh;
525557
dmodelvertlight_t *dml;
526558
dvlightlump_t *l;
@@ -558,8 +590,10 @@ void FinalLightVertex( int modelnum, int threadnum = -1 )
558590
minlight *= g_direct_scale;
559591
if( g_numbounce > 0 ) minlight = 0.0f; // ignore for radiosity
560592

593+
vertexblur = BoolForKey( mapent, "zhlt_vertexblur" );
594+
vertexblur = vertexblur || g_vertexblur;
561595

562-
if( g_vertexblur )
596+
if( vertexblur )
563597
{
564598
for( int i = 0; i < mesh->numverts; i++ )
565599
mesh->verts[i].light->face_counter = 0;

0 commit comments

Comments
 (0)