@@ -366,7 +366,7 @@ static void RE_RenderCubeProbeFace( const refdef_t* originalRefdef ) {
366366 Log::Warn ( " Cube probe face out of range! (%i/%i)" , probeID, tr.cubeProbes .size () );
367367 return ;
368368 }
369-
369+
370370 refdef_t refdef{};
371371 const int faceID = globalID % 6 ;
372372
@@ -487,6 +487,61 @@ static void RE_RenderCubeProbeFace( const refdef_t* originalRefdef ) {
487487
488488}
489489
490+ // Debug spot light (projected) injection
491+ static Cvar::Cvar<bool > r_debugProjLight ( " r_debugProjLight" , " inject a directional sun light each frame" , Cvar::CHEAT, false );
492+ static Cvar::Range<Cvar::Cvar<float >> r_debugProjLightYaw ( " r_debugProjLightYaw" , " debug projected yaw in degrees" , Cvar::NONE, 45 .0f , -360 .0f , 360 .0f );
493+ static Cvar::Range<Cvar::Cvar<float >> r_debugProjLightPitch ( " r_debugProjLightPitch" , " debug projected pitch in degrees" , Cvar::NONE, -60 .0f , -89 .0f , 89 .0f );
494+ static Cvar::Cvar<float > r_debugProjLightRadius ( " r_debugProjLightRadius" , " debug projected radius (size)" , Cvar::NONE, 100 .0f );
495+ static Cvar::Cvar<float > r_debugProjLightIntensity ( " r_debugProjLightIntensity" , " debug projected intensity" , Cvar::NONE, 1 .0f );
496+ static Cvar::Range<Cvar::Cvar<float >> r_debugProjLightR ( " r_debugProjLightR" , " debug projected color R" , Cvar::NONE, 1 .0f , 0 .0f , 1 .0f );
497+ static Cvar::Range<Cvar::Cvar<float >> r_debugProjLightG ( " r_debugProjLightG" , " debug projected color G" , Cvar::NONE, 1 .0f , 0 .0f , 1 .0f );
498+ static Cvar::Range<Cvar::Cvar<float >> r_debugProjLightB ( " r_debugProjLightB" , " debug projected color B" , Cvar::NONE, 1 .0f , 0 .0f , 1 .0f );
499+ static Cvar::Cvar<float > r_debugProjLightOriginX ( " r_debugProjLightOriginX" , " debug projected origin X" , Cvar::NONE, 0 .0f );
500+ static Cvar::Cvar<float > r_debugProjLightOriginY ( " r_debugProjLightOriginY" , " debug projected origin Y" , Cvar::NONE, 0 .0f );
501+ static Cvar::Cvar<float > r_debugProjLightOriginZ ( " r_debugProjLightOriginZ" , " debug projected origin Z" , Cvar::NONE, 0 .0f );
502+ static Cvar::Cvar<float > r_debugProjLightAngle ( " r_debugProjLightAngle" , " debug projected angle" ,
503+ Cvar::NONE, 60 .0f );
504+
505+ static void AddDebugProjectedLight ()
506+ {
507+ if ( r_numLights >= MAX_REF_LIGHTS )
508+ {
509+ return ;
510+ }
511+ refLight_t *light = &backEndData[ tr.smpFrame ]->lights [ r_numLights++ ];
512+ *light = {};
513+ light->rlType = refLightType_t::RL_PROJ;
514+ // Compute direction from yaw/pitch cvars (in degrees)
515+ float yaw = DEG2RAD ( r_debugProjLightYaw.Get () );
516+ float pitch = DEG2RAD ( r_debugProjLightPitch.Get () );
517+ // Right-handed: X forward, Y left, Z up. Direction vector components:
518+ light->projTarget [ 0 ] = cosf ( pitch ) * cosf ( yaw );
519+ light->projTarget [ 1 ] = cosf ( pitch ) * sinf ( yaw );
520+ light->projTarget [ 2 ] = sinf ( pitch );
521+
522+ vec3_t dir;
523+ VectorCopy ( light->projTarget , dir );
524+ VectorNormalize ( dir );
525+
526+ PerpendicularVector ( light->projUp , dir );
527+
528+ float upLen = VectorLength ( light->projUp );
529+ float tgtLen = VectorLength ( light->projTarget );
530+
531+ VectorScale ( light->projUp , tanf ( DEG2RAD ( r_debugProjLightAngle.Get () ) ) / upLen / tgtLen,
532+ light->projUp );
533+
534+ // Set properties
535+ float intensity = r_debugProjLightIntensity.Get ();
536+ light->color [ 0 ] = r_debugProjLightR.Get () * intensity;
537+ light->color [ 1 ] = r_debugProjLightG.Get () * intensity;
538+ light->color [ 2 ] = r_debugProjLightB.Get () * intensity;
539+ light->radius = r_debugProjLightRadius.Get ();
540+ light->origin [ 0 ] = r_debugProjLightOriginX.Get ();
541+ light->origin [ 1 ] = r_debugProjLightOriginY.Get ();
542+ light->origin [ 2 ] = r_debugProjLightOriginZ.Get ();
543+ }
544+
490545/*
491546@@@@@@@@@@@@@@@@@@@@@
492547RE_RenderScene
@@ -562,6 +617,11 @@ void RE_RenderScene( const refdef_t *fd )
562617 }
563618 }
564619
620+ if ( r_debugProjLight.Get () )
621+ {
622+ AddDebugProjectedLight ();
623+ }
624+
565625 // derived info
566626 if ( r_forceRendererTime.Get () >= 0 ) {
567627 tr.refdef .floatTime = float ( double ( r_forceRendererTime.Get () ) * 0.001 );
0 commit comments