Skip to content

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

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

Add debug utilities to help debug dynamic lights and small fixes#1908
DolceTriade wants to merge 4 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

};
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.

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.

Sure, the shape makes sense for directed lights, I meant for normal point lights. When you have more than one point light they often overlap and it is impossible to tell how many there are with this visualization. Anyway since projected and directed are distinguished by color, how about just drawing one "arrow" with some arbitrary vector for point lights?

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.

Ok, how does this look?

Image

I think in order to draw in wireframe mode I need to do two passes.

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?

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.

I mean usually you would call that after finishing rendering something, rather than before starting.

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.

Ok, I moved it after the draw call. I think that makes more sense?

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.

I mean usually you would call that after finishing rendering something, rather than before starting.

};
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.

Sure, the shape makes sense for directed lights, I meant for normal point lights. When you have more than one point light they often overlap and it is impossible to tell how many there are with this visualization. Anyway since projected and directed are distinguished by color, how about just drawing one "arrow" with some arbitrary vector for point lights?

{
VectorSet( dir, 0.0f, 0.0f, 1.0f );
}
// idk why we need to negate here, but the arrow points the wrong way otherwise.
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.

Surface normals point outward from the object. And a light is rendered when the product of its direction and the surface normal is positive. So the light direction vector has to point away from the source for it to work. But I think the negation should be dropped, so that it is consistent with r_showLightGrid. With the light grid visualization, the long skinny side shows the directed light color and direction.

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.

hm...

This is what it looks like with the negation:
Image

This is what it looks like without negation:

Image

I think the rendering with negation looks better. I think that's what you're saying in your comment?

// 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 );
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.

Seems counterintuitive for the "sun" to default to illuminating things from below.

Copy link
Copy Markdown
Contributor Author

@DolceTriade DolceTriade Apr 2, 2026

Choose a reason for hiding this comment

The 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.

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.

When I tried it the ceiling was illuminated but the floor was not!

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::Range<Cvar::Cvar<float>> r_debugProjLightR( "r_debugProjLightR", "debug projected color R", Cvar::NONE, 1.0f, 0.0f, 1.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.

The light intensity shouldn't be capped at 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.

Added back intensity. I think it's weird to make RGB more than 1.

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.

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.

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.
Switch to a wireframe cube to make omni lights less busy
Copy link
Copy Markdown
Member

@slipher slipher left a comment

Choose a reason for hiding this comment

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

I suspect something is wrong with the projected light math as a lot of times it doesn't seem to illuminate anything in any direction near the origin. It would probably be good to get rid of the projTarget etc. garbage from refLight_t and instead use the same parameters as in the GLSL

// 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 );
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.

When I tried it the ceiling was illuminated but the floor was not!

@slipher
Copy link
Copy Markdown
Member

slipher commented Apr 2, 2026

I suspect something is wrong with the projected light math as a lot of times it doesn't seem to illuminate anything in any direction near the origin. It would probably be good to get rid of the projTarget etc. garbage from refLight_t and instead use the same parameters as in the GLSL

Never mind, I got it to work now. It's just confusing when the tetrahedrons are very big and I don't know which part of them the light is supposed to originate from.

@DolceTriade
Copy link
Copy Markdown
Contributor Author

Never mind, I got it to work now. It's just confusing when the tetrahedrons are very big and I don't know which part of them the light is supposed to originate from.

Is there any further action to change?

@slipher
Copy link
Copy Markdown
Member

slipher commented Apr 4, 2026

Never mind, I got it to work now. It's just confusing when the tetrahedrons are very big and I don't know which part of them the light is supposed to originate from.

Is there any further action to change?

The only suggestion I had left was changing the default sun pitch angle so that the floor is illuminated rather than the ceiling. LGTM besides that. On the subject of the default values, the spotlight intensity could optionally be increased a little so that it's easier to see

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.

3 participants