Add debug utilities to help debug dynamic lights and small fixes#1908
Add debug utilities to help debug dynamic lights and small fixes#1908DolceTriade wants to merge 4 commits intoDaemonEngine:masterfrom
Conversation
src/engine/renderer/tr_backend.cpp
Outdated
| }; | ||
| for ( int dirIndex = 0; dirIndex < 6; ++dirIndex ) | ||
| { | ||
| addArrow( kOmniDirs[ dirIndex ], color ); |
There was a problem hiding this comment.
The 12 tetrahedrons seems too busy to me. Maybe we could just draw a wireframe cube?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
src/engine/renderer/tr_backend.cpp
Outdated
| glState.modelViewProjectionMatrix[ glState.stackIndex ] ); | ||
|
|
||
| Tess_Begin( Tess_StageIteratorDebug, nullptr, true, -1, 0 ); | ||
| GL_CheckErrors(); |
There was a problem hiding this comment.
This is admittedly cargo culted:
Daemon/src/engine/renderer/tr_backend.cpp
Lines 2245 to 2246 in 29446db
As a convention should I check for errors elsewhere?
There was a problem hiding this comment.
I mean usually you would call that after finishing rendering something, rather than before starting.
There was a problem hiding this comment.
Ok, I moved it after the draw call. I think that makes more sense?
src/engine/renderer/tr_backend.cpp
Outdated
| glState.modelViewProjectionMatrix[ glState.stackIndex ] ); | ||
|
|
||
| Tess_Begin( Tess_StageIteratorDebug, nullptr, true, -1, 0 ); | ||
| GL_CheckErrors(); |
There was a problem hiding this comment.
I mean usually you would call that after finishing rendering something, rather than before starting.
src/engine/renderer/tr_backend.cpp
Outdated
| }; | ||
| for ( int dirIndex = 0; dirIndex < 6; ++dirIndex ) | ||
| { | ||
| addArrow( kOmniDirs[ dirIndex ], color ); |
There was a problem hiding this comment.
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?
src/engine/renderer/tr_backend.cpp
Outdated
| { | ||
| VectorSet( dir, 0.0f, 0.0f, 1.0f ); | ||
| } | ||
| // idk why we need to negate here, but the arrow points the wrong way otherwise. |
There was a problem hiding this comment.
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.
| // 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 ); |
There was a problem hiding this comment.
Seems counterintuitive for the "sun" to default to illuminating things from below.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
The light intensity shouldn't be capped at 1
There was a problem hiding this comment.
Added back intensity. I think it's weird to make RGB more than 1.
There was a problem hiding this comment.
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
slipher
left a comment
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
When I tried it the ceiling was illuminated but the floor was not!
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 |



glsl_restart