-
Notifications
You must be signed in to change notification settings - Fork 70
Add debug utilities to help debug dynamic lights and small fixes #1908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ef014dc
7cd603a
4fb5b96
2d4e359
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -366,7 +366,7 @@ static void RE_RenderCubeProbeFace( const refdef_t* originalRefdef ) { | |
| Log::Warn( "Cube probe face out of range! (%i/%i)", probeID, tr.cubeProbes.size() ); | ||
| return; | ||
| } | ||
|
|
||
| refdef_t refdef{}; | ||
| const int faceID = globalID % 6; | ||
|
|
||
|
|
@@ -487,6 +487,95 @@ static void RE_RenderCubeProbeFace( const refdef_t* originalRefdef ) { | |
|
|
||
| } | ||
|
|
||
| // Debug spot light (projected) injection | ||
| static Cvar::Cvar<bool> r_debugProjLight( "r_debugProjLight", "inject a directional sun light each frame", Cvar::CHEAT, false ); | ||
| static Cvar::Range<Cvar::Cvar<float>> r_debugProjLightYaw( "r_debugProjLightYaw", "debug projected yaw in degrees", Cvar::NONE, 45.0f, -360.0f, 360.0f ); | ||
| static Cvar::Range<Cvar::Cvar<float>> r_debugProjLightPitch( "r_debugProjLightPitch", "debug projected pitch in degrees", Cvar::NONE, -60.0f, -89.0f, 89.0f ); | ||
| static Cvar::Cvar<float> r_debugProjLightRadius( "r_debugProjLightRadius", "debug projected radius (size)", Cvar::NONE, 100.0f ); | ||
| static Cvar::Cvar<float> r_debugProjLightIntensity( "r_debugProjLightIntensity", "debug projected intensity", Cvar::NONE, 1.0f ); | ||
| static Cvar::Range<Cvar::Cvar<float>> r_debugProjLightR( "r_debugProjLightR", "debug projected color R", Cvar::NONE, 1.0f, 0.0f, 1.0f ); | ||
| static Cvar::Range<Cvar::Cvar<float>> r_debugProjLightG( "r_debugProjLightG", "debug projected color G", Cvar::NONE, 1.0f, 0.0f, 1.0f ); | ||
| static Cvar::Range<Cvar::Cvar<float>> r_debugProjLightB( "r_debugProjLightB", "debug projected color B", Cvar::NONE, 1.0f, 0.0f, 1.0f ); | ||
| static Cvar::Cvar<float> r_debugProjLightOriginX( "r_debugProjLightOriginX", "debug projected origin X", Cvar::NONE, 0.0f ); | ||
| static Cvar::Cvar<float> r_debugProjLightOriginY( "r_debugProjLightOriginY", "debug projected origin Y", Cvar::NONE, 0.0f ); | ||
| static Cvar::Cvar<float> r_debugProjLightOriginZ( "r_debugProjLightOriginZ", "debug projected origin Z", Cvar::NONE, 0.0f ); | ||
| static Cvar::Cvar<float> r_debugProjLightAngle( "r_debugProjLightAngle", "debug projected angle", | ||
| Cvar::NONE, 60.0f ); | ||
|
|
||
| static void AddDebugProjectedLight() | ||
| { | ||
| if ( r_numLights >= MAX_REF_LIGHTS ) | ||
| { | ||
| return; | ||
| } | ||
| refLight_t *light = &backEndData[ tr.smpFrame ]->lights[ r_numLights++ ]; | ||
| *light = {}; | ||
| light->rlType = refLightType_t::RL_PROJ; | ||
| // Compute direction from yaw/pitch cvars (in degrees) | ||
| float yaw = DEG2RAD( r_debugProjLightYaw.Get() ); | ||
| float pitch = DEG2RAD( r_debugProjLightPitch.Get() ); | ||
| // Right-handed: X forward, Y left, Z up. Direction vector components: | ||
| light->projTarget[ 0 ] = cosf( pitch ) * cosf( yaw ); | ||
| light->projTarget[ 1 ] = cosf( pitch ) * sinf( yaw ); | ||
| light->projTarget[ 2 ] = sinf( pitch ); | ||
|
|
||
| vec3_t dir; | ||
| VectorCopy( light->projTarget, dir ); | ||
| VectorNormalize( dir ); | ||
|
|
||
| PerpendicularVector( light->projUp, dir ); | ||
|
|
||
| float upLen = VectorLength( light->projUp ); | ||
| float tgtLen = VectorLength( light->projTarget ); | ||
|
|
||
| VectorScale( light->projUp, tanf( DEG2RAD( r_debugProjLightAngle.Get() ) ) / upLen / tgtLen, | ||
| light->projUp ); | ||
|
|
||
| // Set properties | ||
| float intensity = r_debugProjLightIntensity.Get(); | ||
| light->color[ 0 ] = r_debugProjLightR.Get() * intensity; | ||
| light->color[ 1 ] = r_debugProjLightG.Get() * intensity; | ||
| light->color[ 2 ] = r_debugProjLightB.Get() * intensity; | ||
| light->radius = r_debugProjLightRadius.Get(); | ||
| light->origin[ 0 ] = r_debugProjLightOriginX.Get(); | ||
| light->origin[ 1 ] = r_debugProjLightOriginY.Get(); | ||
| light->origin[ 2 ] = r_debugProjLightOriginZ.Get(); | ||
| } | ||
|
|
||
| // Debug sun light (directional) injection | ||
| Cvar::Cvar<bool> r_debugSun( "r_debugSun", "inject a directional sun light each frame", Cvar::CHEAT, false ); | ||
| Cvar::Range<Cvar::Cvar<float>> r_debugSunYaw( "r_debugSunYaw", "debug sun yaw in degrees", Cvar::NONE, 45.0f, -360.0f, 360.0f ); | ||
| Cvar::Range<Cvar::Cvar<float>> r_debugSunPitch( "r_debugSunPitch", "debug sun pitch in degrees", Cvar::NONE, -60.0f, -89.0f, 89.0f ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems counterintuitive for the "sun" to default to illuminating things from below.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking from the sun's perspective cuz the sun shines down, but if you want me to change it, I can change it. Just let me know what you think makes sense.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I tried it the ceiling was illuminated but the floor was not! |
||
| Cvar::Cvar<float> r_debugSunIntensity( "r_debugSunIntensity", "debug sun intensity", Cvar::NONE, 1.0f ); | ||
| Cvar::Range<Cvar::Cvar<float>> r_debugSunR( "r_debugSunR", "debug sun color R", Cvar::NONE, 1.0f, 0.0f, 10.0f ); | ||
| Cvar::Range<Cvar::Cvar<float>> r_debugSunG( "r_debugSunG", "debug sun color G", Cvar::NONE, 1.0f, 0.0f, 10.0f ); | ||
| Cvar::Range<Cvar::Cvar<float>> r_debugSunB( "r_debugSunB", "debug sun color B", Cvar::NONE, 1.0f, 0.0f, 10.0f ); | ||
|
|
||
| static void AddDebugSunLight() | ||
| { | ||
| if ( r_numLights >= MAX_REF_LIGHTS ) | ||
| { | ||
| return; | ||
| } | ||
| refLight_t *sun = &backEndData[ tr.smpFrame ]->lights[ r_numLights++ ]; | ||
| *sun = {}; | ||
| sun->rlType = refLightType_t::RL_DIRECTIONAL; | ||
| // Compute direction from yaw/pitch cvars (in degrees) | ||
| float yaw = DEG2RAD( r_debugSunYaw.Get() ); | ||
| float pitch = DEG2RAD( r_debugSunPitch.Get() ); | ||
| // Right-handed: X forward, Y left, Z up. Direction vector components: | ||
| sun->projTarget[ 0 ] = cosf( pitch ) * cosf( yaw ); | ||
| sun->projTarget[ 1 ] = cosf( pitch ) * sinf( yaw ); | ||
| sun->projTarget[ 2 ] = sinf( pitch ); | ||
| VectorNormalize( sun->projTarget ); | ||
| float intensity = r_debugSunIntensity.Get(); | ||
| sun->color[ 0 ] = r_debugSunR.Get() * intensity; | ||
| sun->color[ 1 ] = r_debugSunG.Get() * intensity; | ||
| sun->color[ 2 ] = r_debugSunB.Get() * intensity; | ||
| // Max radius to ensure it is always included. | ||
| sun->radius = std::numeric_limits<float>::max(); | ||
| } | ||
|
|
||
| /* | ||
| @@@@@@@@@@@@@@@@@@@@@ | ||
| RE_RenderScene | ||
|
|
@@ -562,6 +651,15 @@ void RE_RenderScene( const refdef_t *fd ) | |
| } | ||
| } | ||
|
|
||
| if ( r_debugProjLight.Get() ) | ||
| { | ||
| AddDebugProjectedLight(); | ||
| } | ||
| if ( r_debugSun.Get() ) | ||
| { | ||
| AddDebugSunLight(); | ||
| } | ||
|
|
||
| // derived info | ||
| if ( r_forceRendererTime.Get() >= 0 ) { | ||
| tr.refdef.floatTime = float( double( r_forceRendererTime.Get() ) * 0.001 ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The light intensity shouldn't be capped at 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added back intensity. I think it's weird to make RGB more than 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sRGB is in [0,1] but RGB is [0,…]
The lightmap themselves get multiplied by overbright and then are already in a range higher than [0, 1], also our whole pipeline uses HDR framebuffers so is ready for that.