@@ -540,6 +540,38 @@ static void AddDebugProjectedLight()
540540 light->origin [ 2 ] = r_debugProjLightOriginZ.Get ();
541541}
542542
543+ // Debug sun light (directional) injection
544+ Cvar::Cvar<bool > r_debugSun ( " r_debugSun" , " inject a directional sun light each frame" , Cvar::CHEAT, false );
545+ Cvar::Range<Cvar::Cvar<float >> r_debugSunYaw ( " r_debugSunYaw" , " debug sun yaw in degrees" , Cvar::NONE, 45 .0f , -360 .0f , 360 .0f );
546+ Cvar::Range<Cvar::Cvar<float >> r_debugSunPitch ( " r_debugSunPitch" , " debug sun pitch in degrees" , Cvar::NONE, -60 .0f , -89 .0f , 89 .0f );
547+ Cvar::Range<Cvar::Cvar<float >> r_debugSunR ( " r_debugSunR" , " debug sun color R" , Cvar::NONE, 1 .0f , 0 .0f , 10 .0f );
548+ Cvar::Range<Cvar::Cvar<float >> r_debugSunG ( " r_debugSunG" , " debug sun color G" , Cvar::NONE, 1 .0f , 0 .0f , 10 .0f );
549+ Cvar::Range<Cvar::Cvar<float >> r_debugSunB ( " r_debugSunB" , " debug sun color B" , Cvar::NONE, 1 .0f , 0 .0f , 10 .0f );
550+
551+ static void AddDebugSunLight ()
552+ {
553+ if ( r_numLights >= MAX_REF_LIGHTS )
554+ {
555+ return ;
556+ }
557+ refLight_t *sun = &backEndData[ tr.smpFrame ]->lights [ r_numLights++ ];
558+ *sun = {};
559+ sun->rlType = refLightType_t::RL_DIRECTIONAL;
560+ // Compute direction from yaw/pitch cvars (in degrees)
561+ float yaw = DEG2RAD ( r_debugSunYaw.Get () );
562+ float pitch = DEG2RAD ( r_debugSunPitch.Get () );
563+ // Right-handed: X forward, Y left, Z up. Direction vector components:
564+ sun->projTarget [ 0 ] = cosf ( pitch ) * cosf ( yaw );
565+ sun->projTarget [ 1 ] = cosf ( pitch ) * sinf ( yaw );
566+ sun->projTarget [ 2 ] = sinf ( pitch );
567+ VectorNormalize ( sun->projTarget );
568+ sun->color [ 0 ] = r_debugSunR.Get ();
569+ sun->color [ 1 ] = r_debugSunG.Get ();
570+ sun->color [ 2 ] = r_debugSunB.Get ();
571+ // Max radius to ensure it is always included.
572+ sun->radius = std::numeric_limits<float >::max ();
573+ }
574+
543575/*
544576@@@@@@@@@@@@@@@@@@@@@
545577RE_RenderScene
@@ -619,6 +651,10 @@ void RE_RenderScene( const refdef_t *fd )
619651 {
620652 AddDebugProjectedLight ();
621653 }
654+ if ( r_debugSun.Get () )
655+ {
656+ AddDebugSunLight ();
657+ }
622658
623659 // derived info
624660 if ( r_forceRendererTime.Get () >= 0 ) {
0 commit comments