Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion utils/pxrad/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2813,6 +2813,7 @@ vec3_t *s_light, vec3_t *s_dir, vec_t *s_occ, byte *styles, byte *vislight, bool
{
vec_t sightarea;
vec_t ratio2, frac;
vec3_t sightareadirection;

// do things slow
if( light_behind_surface )
Expand All @@ -2822,14 +2823,17 @@ vec3_t *s_light, vec3_t *s_dir, vec_t *s_occ, byte *styles, byte *vislight, bool
}

GetAlternateOrigin( *pos, n, dl->patch, testline_origin );
sightarea = CalcSightArea( *pos, n, dl->patch->winding, dl->patch->emitter_skylevel );

sightarea = CalcSightArea( *pos, n, dl->patch->winding, dl->patch->emitter_skylevel, &sightareadirection );

frac = dist / range;
frac = ( frac - 0.5 ) * 2.0; // make a smooth transition between the two methods
frac = bound( 0.0, frac, 1.0 );
// because dl->patch_area has been multiplied into dl->intensity
ratio2 = (sightarea / dl->patch_area);
ratio = frac * ratio + (1.0 - frac) * ratio2;

VectorLerp( sightareadirection, frac, direction, direction );
}
else if( light_behind_surface )
{
Expand Down
14 changes: 12 additions & 2 deletions utils/pxrad/qrad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ vec_t CalcFaceSolidAngle( dface_t *f, const vec3_t origin )
// =====================================================================================
// CalcSightArea
// =====================================================================================
vec_t CalcSightArea( const vec3_t receiver_origin, const vec3_t receiver_normal, const winding_t *emitter_winding, int skylevel )
vec_t CalcSightArea( const vec3_t receiver_origin, const vec3_t receiver_normal, const winding_t *emitter_winding, int skylevel, vec3_t* avg_direction )
{
// maybe there are faster ways in calculating the weighted area, but at least this way is not bad.
int numedges = emitter_winding->numpoints;
Expand All @@ -600,6 +600,7 @@ vec_t CalcSightArea( const vec3_t receiver_origin, const vec3_t receiver_normal,
vec_t dot;
vec_t area = 0.0f;
int i, j, x;
vec3_t avg_dir = {0,0,0};

for( x = 0; x < numedges; x++ )
{
Expand Down Expand Up @@ -634,11 +635,20 @@ vec_t CalcSightArea( const vec3_t receiver_origin, const vec3_t receiver_normal,
if( j < numedges )
continue;
area += dot;

VectorMA( avg_dir, dot, *pnormal, avg_dir );
}

if( avg_direction )
{
if( area > 0.0f )
VectorScale( avg_dir, 1.0f / area, avg_dir );
VectorCopy( avg_dir, *avg_direction );
}

area /= (float)i;

area = area * 4.0 * M_PI; // convert to absolute sphere area
area = area * 4.0f * M_PI; // convert to absolute sphere area
Mem_Free( edges );

return area;
Expand Down
2 changes: 1 addition & 1 deletion utils/pxrad/qrad.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ float GatherSampleDirt( int threadnum, int fn, const vec3_t pos, const vec3_t no
const dplane_t *GetPlaneFromFace( const dface_t *face );
const dplane_t *GetPlaneFromFace( const uint facenum );
dleaf_t *HuntForWorld( vec3_t point, const vec3_t plane_offset, const dplane_t *plane, int hunt_size, vec_t hunt_scale, vec_t hunt_offset );
vec_t CalcSightArea( const vec3_t receiver_origin, const vec3_t receiver_normal, const winding_t *emitter_winding, int skylevel );
vec_t CalcSightArea( const vec3_t receiver_origin, const vec3_t receiver_normal, const winding_t *emitter_winding, int skylevel, vec3_t* avg_direction = NULL );
void GetAlternateOrigin( const vec3_t pos, const vec3_t normal, const patch_t *patch, vec3_t origin );
vec_t BaseLightForFace( dface_t *f, vec3_t light, vec3_t reflectivity );
void InitWorldLightFromPatch( dworldlight_t *wl, patch_t *p );
Expand Down
Loading