From 5eeb2509070956593bd53d8aa024c5eefb4d56dc Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 12 Apr 2026 22:44:51 +0500 Subject: [PATCH] ref: common: add R_PushDlightsForBmodel --- ref/common/ref_common.h | 3 ++- ref/common/ref_light.c | 21 ++++++++++++++++++++- ref/gl/gl_rsurf.c | 15 +-------------- ref/soft/r_main.c | 36 +++++------------------------------- 4 files changed, 28 insertions(+), 47 deletions(-) diff --git a/ref/common/ref_common.h b/ref/common/ref_common.h index 62edd999..2f12be6b 100644 --- a/ref/common/ref_common.h +++ b/ref/common/ref_common.h @@ -74,7 +74,8 @@ void Matrix4x4_ToArrayFloatGL( const matrix4x4 in, float out[16] ); // ref_light.c // void CL_RunLightStyles_( lightstyle_t *ls, int *lightstylevalue ); -void R_MarkLights( const dlight_t *light, int bit, const mnode_t *node, model_t *model, int dlightframecount ); +void R_PushDlightsForBmodel( model_t *model, int framecount, const matrix4x4 object_matrix ); int R_PushDlights( model_t *model, int framecount ); + #endif // REF_COMMON_H diff --git a/ref/common/ref_light.c b/ref/common/ref_light.c index 54d0fc1c..e2c56305 100644 --- a/ref/common/ref_light.c +++ b/ref/common/ref_light.c @@ -93,7 +93,7 @@ void CL_RunLightStyles_( lightstyle_t *ls, int *lightstylevalue ) R_MarkLights ============= */ -void R_MarkLights( const dlight_t *light, int bit, const mnode_t *node, model_t *model, int dlightframecount ) +static void R_MarkLights( const dlight_t *light, int bit, const mnode_t *node, model_t *model, int dlightframecount ) { const float virtual_radius = light->radius * Q_max( 1.0f, r_dlight_virtual_radius.value ); const float maxdist = light->radius * light->radius; @@ -186,3 +186,22 @@ int R_PushDlights( model_t *model, int framecount ) return framecount; } + +void R_PushDlightsForBmodel( model_t *model, int framecount, const matrix4x4 object_matrix ) +{ + for( int i = 0; i < MAX_DLIGHTS; i++ ) + { + dlight_t *l = &gp_dlights[i]; + + if( l->die < gp_cl->time || !l->radius ) + continue; + + vec3_t oldorigin; + VectorCopy( l->origin, oldorigin ); + + Matrix4x4_VectorITransform( object_matrix, oldorigin, l->origin ); + R_MarkLights( l, 1 << i, model->nodes + model->hulls[0].firstclipnode, model, framecount ); + + VectorCopy( oldorigin, l->origin ); + } +} diff --git a/ref/gl/gl_rsurf.c b/ref/gl/gl_rsurf.c index 00555cb1..9c68b4e2 100644 --- a/ref/gl/gl_rsurf.c +++ b/ref/gl/gl_rsurf.c @@ -1857,20 +1857,7 @@ void R_DrawBrushModel( cl_entity_t *e ) e->visframe = tr.realframecount; // visible // calculate dynamic lighting for bmodel - for( int k = 0; k < MAX_DLIGHTS; k++ ) - { - dlight_t *l = &gp_dlights[k]; - vec3_t origin_l, oldorigin; - - if( l->die < gp_cl->time || !l->radius ) - continue; - - VectorCopy( l->origin, oldorigin ); // save lightorigin - Matrix4x4_VectorITransform( RI.objectMatrix, l->origin, origin_l ); - VectorCopy( origin_l, l->origin ); // move light in bmodel space - R_MarkLights( l, 1<nodes + clmodel->hulls[0].firstclipnode, clmodel, tr.dlightframecount ); - VectorCopy( oldorigin, l->origin ); // restore lightorigin - } + R_PushDlightsForBmodel( clmodel, tr.dlightframecount, RI.objectMatrix ); // setup the rendermode R_SetRenderMode( e ); diff --git a/ref/soft/r_main.c b/ref/soft/r_main.c index 48a6ccfe..2ee84276 100644 --- a/ref/soft/r_main.c +++ b/ref/soft/r_main.c @@ -840,21 +840,8 @@ static void R_DrawBEntitiesOnList( void ) R_RotateBmodel(); // calculate dynamic lighting for bmodel - for( k = 0; k < MAX_DLIGHTS; k++ ) - { - dlight_t *l = &gp_dlights[k]; - vec3_t origin_l, oldorigin; - - if( l->die < gp_cl->time || !l->radius ) - continue; - - VectorCopy( l->origin, oldorigin ); // save lightorigin - Matrix4x4_CreateFromEntity( RI.objectMatrix, RI.currententity->angles, RI.currententity->origin, 1 ); - Matrix4x4_VectorITransform( RI.objectMatrix, l->origin, origin_l ); - VectorCopy( origin_l, l->origin ); // move light in bmodel space - R_MarkLights( l, 1 << k, RI.currentmodel->nodes + RI.currentmodel->hulls[0].firstclipnode, RI.currentmodel, tr.dlightframecount ); - VectorCopy( oldorigin, l->origin ); // restore lightorigin - } + Matrix4x4_CreateFromEntity( RI.objectMatrix, RI.currententity->angles, RI.currententity->origin, 1 ); + R_PushDlightsForBmodel( RI.currentmodel, tr.dlightframecount, RI.objectMatrix ); RI.currententity->topnode = topnode; if( topnode->contents >= 0 ) @@ -965,22 +952,9 @@ void R_DrawBrushModel( cl_entity_t *pent ) R_RotateBmodel(); // calculate dynamic lighting for bmodel - for( k = 0; k < MAX_DLIGHTS; k++ ) - { - dlight_t *l = &gp_dlights[k]; - vec3_t origin_l, oldorigin; - - if( l->die < gp_cl->time || !l->radius ) - continue; - - VectorCopy( l->origin, oldorigin ); // save lightorigin - Matrix4x4_CreateFromEntity( RI.objectMatrix, RI.currententity->angles, RI.currententity->origin, 1 ); - Matrix4x4_VectorITransform( RI.objectMatrix, l->origin, origin_l ); - tr.modelviewIdentity = false; - VectorCopy( origin_l, l->origin ); // move light in bmodel space - R_MarkLights( l, 1 << k, RI.currentmodel->nodes + RI.currentmodel->hulls[0].firstclipnode, RI.currentmodel, tr.dlightframecount ); - VectorCopy( oldorigin, l->origin ); // restore lightorigin*/ - } + Matrix4x4_CreateFromEntity( RI.objectMatrix, RI.currententity->angles, RI.currententity->origin, 1 ); + R_PushDlightsForBmodel( RI.currentmodel, tr.dlightframecount, RI.objectMatrix ); + tr.modelviewIdentity = false; RI.currententity->topnode = topnode; if( topnode->contents >= 0 )