@@ -542,6 +542,40 @@ static void AddDebugProjectedLight()
542542 light->origin [ 2 ] = r_debugProjLightOriginZ.Get ();
543543}
544544
545+ // Debug sun light (directional) injection
546+ Cvar::Cvar<bool > r_debugSun ( " r_debugSun" , " inject a directional sun light each frame" , Cvar::CHEAT, false );
547+ Cvar::Range<Cvar::Cvar<float >> r_debugSunYaw ( " r_debugSunYaw" , " debug sun yaw in degrees" , Cvar::NONE, 45 .0f , -360 .0f , 360 .0f );
548+ Cvar::Range<Cvar::Cvar<float >> r_debugSunPitch ( " r_debugSunPitch" , " debug sun pitch in degrees" , Cvar::NONE, -60 .0f , -89 .0f , 89 .0f );
549+ Cvar::Cvar<float > r_debugSunIntensity ( " r_debugSunIntensity" , " debug sun intensity" , Cvar::NONE, 1 .0f );
550+ Cvar::Range<Cvar::Cvar<float >> r_debugSunR ( " r_debugSunR" , " debug sun color R" , Cvar::NONE, 1 .0f , 0 .0f , 10 .0f );
551+ Cvar::Range<Cvar::Cvar<float >> r_debugSunG ( " r_debugSunG" , " debug sun color G" , Cvar::NONE, 1 .0f , 0 .0f , 10 .0f );
552+ Cvar::Range<Cvar::Cvar<float >> r_debugSunB ( " r_debugSunB" , " debug sun color B" , Cvar::NONE, 1 .0f , 0 .0f , 10 .0f );
553+
554+ static void AddDebugSunLight ()
555+ {
556+ if ( r_numLights >= MAX_REF_LIGHTS )
557+ {
558+ return ;
559+ }
560+ refLight_t *sun = &backEndData[ tr.smpFrame ]->lights [ r_numLights++ ];
561+ *sun = {};
562+ sun->rlType = refLightType_t::RL_DIRECTIONAL;
563+ // Compute direction from yaw/pitch cvars (in degrees)
564+ float yaw = DEG2RAD ( r_debugSunYaw.Get () );
565+ float pitch = DEG2RAD ( r_debugSunPitch.Get () );
566+ // Right-handed: X forward, Y left, Z up. Direction vector components:
567+ sun->projTarget [ 0 ] = cosf ( pitch ) * cosf ( yaw );
568+ sun->projTarget [ 1 ] = cosf ( pitch ) * sinf ( yaw );
569+ sun->projTarget [ 2 ] = sinf ( pitch );
570+ VectorNormalize ( sun->projTarget );
571+ float intensity = r_debugSunIntensity.Get ();
572+ sun->color [ 0 ] = r_debugSunR.Get () * intensity;
573+ sun->color [ 1 ] = r_debugSunG.Get () * intensity;
574+ sun->color [ 2 ] = r_debugSunB.Get () * intensity;
575+ // Max radius to ensure it is always included.
576+ sun->radius = std::numeric_limits<float >::max ();
577+ }
578+
545579/*
546580@@@@@@@@@@@@@@@@@@@@@
547581RE_RenderScene
@@ -621,6 +655,10 @@ void RE_RenderScene( const refdef_t *fd )
621655 {
622656 AddDebugProjectedLight ();
623657 }
658+ if ( r_debugSun.Get () )
659+ {
660+ AddDebugSunLight ();
661+ }
624662
625663 // derived info
626664 if ( r_forceRendererTime.Get () >= 0 ) {
0 commit comments