Skip to content

Add debug utilities to help debug dynamic lights and small fixes#1908

Open
DolceTriade wants to merge 3 commits intoDaemonEngine:masterfrom
DolceTriade:debuglight
Open

Add debug utilities to help debug dynamic lights and small fixes#1908
DolceTriade wants to merge 3 commits intoDaemonEngine:masterfrom
DolceTriade:debuglight

Conversation

@DolceTriade
Copy link
Copy Markdown
Contributor

  • Add cvars to create a debug spotlight and a debug sun light.
  • Ensure that sun lights affect all light tiles
  • Add a debug cvar to help visualize spot lights and point lights
  • Stop segfaulting when running glsl_restart

{
static const vec3_t kOmniDirs[ 6 ] = {
{ 1.0f, 0.0f, 0.0f },
{ -1.0f, 0.0f, 0.0f },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

messed up spacing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's consistent now.

};
for ( int dirIndex = 0; dirIndex < 6; ++dirIndex )
{
addArrow( kOmniDirs[ dirIndex ], color );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 12 tetrahedrons seems too busy to me. Maybe we could just draw a wireframe cube?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept tetrahedrons so I could show the direction of the light for projected lights and show that omni lights go in all directions. I also cargo culted the lightgrid code here.

I've found it helpful to debug dynamic light in my testing as is.

glState.modelViewProjectionMatrix[ glState.stackIndex ] );

Tess_Begin( Tess_StageIteratorDebug, nullptr, true, -1, 0 );
GL_CheckErrors();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oddly placed GL_CheckErrors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is admittedly cargo culted:

Tess_Begin( Tess_StageIteratorDebug, nullptr, true, -1 );
GL_CheckErrors();

As a convention should I check for errors elsewhere?

light->color[ 0 ] = r_debugProjLightR.Get();
light->color[ 1 ] = r_debugProjLightG.Get();
light->color[ 2 ] = r_debugProjLightB.Get();
light->scale = r_debugProjLightIntensity.Get();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't compile since scale was removed on the for-0.56 branch. Now it's just unbounded r/g/b values.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, removed the cvar. People can just double the color if they want.

}

// Debug spot light (projected) injection
static Cvar::Cvar<bool> r_debugProjLight( "r_debugProjLight", "inject a directional sun light each frame", Cvar::NONE, false );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cvar::CHEAT

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call


static void AddDebugProjectedLight()
{
if ( r_numLights + 1 >= MAX_REF_LIGHTS )
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for + 1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right. If r_numLights == MAX_REF_LIGHTS we're maxed out. If it is less, then the increment will happen after assigning the light, so we're still good.

for( uint i = uint( u_lightLayer ); i < uint( u_numLights ); i += uint( NUM_LIGHT_LAYERS ) ) {
Light l = GetLight( i );
// Directional lights (sun) have infinite extent, so always include them in tiles
if ( l.type == 2 ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this how about setting a large radius in the code that adds the light?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works. Nice suggestion

This adds a debug cvar to draw a tetrahedron (similar to what you get
when yuou enable r_showSkeleton) in the direction of a spot light or in
6 directions for an omnilight that is proportional to the radius of the
light.

This makes it easier to visualize dynamic lights and see what they
should be doing, what direction they are intended to point, etc.

Also, while here, normalize spotlight direction.
Makes it easier to test dynamic lights.
Directional lights should affect all light tiles, so set a really high
radius to ensure they are included in all light tiles.

Also add some cvars to allow adding a debug sun.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants