-
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
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 |
|---|---|---|
|
|
@@ -39,6 +39,8 @@ static Cvar::Cvar<bool> r_clear( "r_clear", "Clear screen before painting over i | |
| Cvar::Cvar<bool> r_drawSky( "r_drawSky", "Draw the sky (clear the sky if disabled)", Cvar::NONE, true ); | ||
| static Cvar::Cvar<int> r_showEntityBounds( | ||
| "r_showEntityBounds", "show bboxes used for culling (1: wireframe; 2: translucent solid)", Cvar::CHEAT, 0); | ||
| static Cvar::Cvar<bool> r_showDynamicLights( | ||
| "r_showDynamicLights", "visualize dynamic lights with tetrahedrons", Cvar::CHEAT, false ); | ||
|
|
||
| void GL_Bind( image_t *image ) | ||
| { | ||
|
|
@@ -1301,7 +1303,7 @@ static void RenderDepthTiles() | |
| { | ||
| RB_PrepareForSamplingDepthMap(); | ||
| } | ||
|
|
||
| TransitionMSAAToMain( GL_DEPTH_BUFFER_BIT ); | ||
|
|
||
| // 1st step | ||
|
|
@@ -1317,7 +1319,7 @@ static void RenderDepthTiles() | |
|
|
||
| gl_depthtile1Shader->SetUniform_zFar( zParams ); | ||
| gl_depthtile1Shader->SetUniform_DepthMapBindless( | ||
| GL_BindToTMU( 0, tr.currentDepthImage ) | ||
| GL_BindToTMU( 0, tr.currentDepthImage ) | ||
| ); | ||
|
|
||
| matrix_t ortho; | ||
|
|
@@ -1727,7 +1729,7 @@ void RB_CameraPostFX() { | |
| gl_cameraEffectsShader->SetUniform_Tonemap( tonemap ); | ||
|
|
||
| gl_cameraEffectsShader->SetUniform_CurrentMapBindless( | ||
| GL_BindToTMU( 0, tr.currentRenderImage[backEnd.currentMainFBO] ) | ||
| GL_BindToTMU( 0, tr.currentRenderImage[backEnd.currentMainFBO] ) | ||
| ); | ||
|
|
||
| if ( r_FXAA.Get() && gl_fxaaShader ) | ||
|
|
@@ -2312,6 +2314,125 @@ static void RB_RenderDebugUtils() | |
| Tess_End(); | ||
| } | ||
|
|
||
| if ( r_showDynamicLights.Get() && backEnd.refdef.numLights > 0 ) | ||
| { | ||
| gl_genericShader->SetVertexSkinning( false ); | ||
| gl_genericShader->SetVertexAnimation( false ); | ||
| gl_genericShader->SetTCGenEnvironment( false ); | ||
| gl_genericShader->SetTCGenLightmap( false ); | ||
| gl_genericShader->SetDepthFade( false ); | ||
| gl_genericShader->SetDeform( 0 ); | ||
| gl_genericShader->BindProgram(); | ||
|
|
||
| GL_State( GLS_DEFAULT ); | ||
| GL_Cull( cullType_t::CT_TWO_SIDED ); | ||
|
|
||
| // set uniforms | ||
| gl_genericShader->SetUniform_AlphaTest( GLS_ATEST_NONE ); | ||
| SetUniform_ColorModulateColorGen( gl_genericShader, colorGen_t::CGEN_VERTEX, | ||
| alphaGen_t::AGEN_VERTEX ); | ||
| SetUniform_Color( gl_genericShader, Color::Black ); | ||
| gl_genericShader->SetUniform_ColorMapBindless( GL_BindToTMU( 0, tr.whiteImage ) ); | ||
| gl_genericShader->SetUniform_TextureMatrix( matrixIdentity ); | ||
|
|
||
| // set up the transformation matrix | ||
| backEnd.orientation = backEnd.viewParms.world; | ||
| GL_LoadModelViewMatrix( backEnd.orientation.modelViewMatrix ); | ||
| gl_genericShader->SetUniform_ModelViewProjectionMatrix( | ||
| glState.modelViewProjectionMatrix[ glState.stackIndex ] ); | ||
|
|
||
| Tess_Begin( Tess_StageIteratorDebug, nullptr, true, -1, 0 ); | ||
| GL_CheckErrors(); | ||
|
|
||
| const refLight_t *lights = backEnd.refdef.lights; | ||
| for ( int i = 0; i < backEnd.refdef.numLights; ++i ) | ||
| { | ||
| const refLight_t &light = lights[ i ]; | ||
| // We can't really visualize directional lights since they don't | ||
| // have an origin or a radius. | ||
| if ( light.rlType >= refLightType_t::RL_DIRECTIONAL ) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| vec3_t baseOrigin; | ||
| VectorCopy( light.origin, baseOrigin ); | ||
|
|
||
| if ( light.radius <= 0.0f ) | ||
| { | ||
| Log::Warn( "Light with index %d has no radius", i ); | ||
| } | ||
|
|
||
| auto addArrow = [ & ]( const vec3_t dirInput, const Color::Color &arrowColor ) | ||
| { | ||
| vec3_t dir; | ||
| VectorCopy( dirInput, dir ); | ||
| if ( VectorNormalize( dir ) == 0.0f ) | ||
| { | ||
| VectorSet( dir, 0.0f, 0.0f, 1.0f ); | ||
| } | ||
| // idk why we need to negate here, but the arrow points the wrong way otherwise. | ||
| VectorNegate( dir, dir ); | ||
|
|
||
| vec3_t tip; | ||
| VectorMA( baseOrigin, light.radius, dir, tip ); | ||
|
|
||
| vec3_t tmp; | ||
| vec3_t tmp2; | ||
| vec3_t tmp3; | ||
| PerpendicularVector( tmp, dir ); | ||
| VectorScale( tmp, light.radius * 0.2f, tmp2 ); | ||
| VectorMA( tmp2, light.radius * 0.3f, dir, tmp2 ); | ||
|
|
||
| vec4_t tetraVerts[ 4 ]; | ||
| for ( int k = 0; k < 3; k++ ) | ||
| { | ||
| RotatePointAroundVector( tmp3, dir, tmp2, k * 120.0f ); | ||
| VectorAdd( tmp3, baseOrigin, tmp3 ); | ||
| VectorCopy( tmp3, tetraVerts[ k ] ); | ||
| tetraVerts[ k ][ 3 ] = 1.0f; | ||
| } | ||
|
|
||
| VectorCopy( baseOrigin, tetraVerts[ 3 ] ); | ||
| tetraVerts[ 3 ][ 3 ] = 1.0f; | ||
| Tess_AddTetrahedron( tetraVerts, arrowColor ); | ||
|
|
||
| VectorCopy( tip, tetraVerts[ 3 ] ); | ||
| tetraVerts[ 3 ][ 3 ] = 1.0f; | ||
|
|
||
| Tess_AddTetrahedron( tetraVerts, arrowColor ); | ||
| }; | ||
|
|
||
| Color::Color color; | ||
| switch ( light.rlType ) | ||
| { | ||
| case refLightType_t::RL_PROJ: | ||
| color = Color::LtGrey; | ||
| addArrow( light.projTarget, color ); | ||
| break; | ||
| default: | ||
| color = Color::MdGrey; | ||
| { | ||
| static const vec3_t kOmniDirs[ 6 ] = { | ||
| { 1.0f, 0.0f, 0.0f }, | ||
| { -1.0f, 0.0f, 0.0f }, | ||
| { 0.0f, 1.0f, 0.0f }, | ||
| { 0.0f, -1.0f, 0.0f }, | ||
| { 0.0f, 0.0f, 1.0f }, | ||
| { 0.0f, 0.0f, -1.0f} | ||
| }; | ||
| for ( int dirIndex = 0; dirIndex < 6; ++dirIndex ) | ||
| { | ||
| addArrow( kOmniDirs[ dirIndex ], color ); | ||
|
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. The 12 tetrahedrons seems too busy to me. Maybe we could just draw a wireframe cube?
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 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. |
||
| } | ||
| } | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| Tess_End(); | ||
| } | ||
|
|
||
| if ( r_showBspNodes->integer ) | ||
| { | ||
| if ( ( backEnd.refdef.rdflags & ( RDF_NOWORLDMODEL ) ) || !tr.world ) | ||
|
|
@@ -3486,6 +3607,7 @@ const RenderCommand *SetupLightsCommand::ExecuteSelf() const | |
| default: | ||
| break; | ||
| } | ||
| VectorNormalize( buffer[i].direction ); | ||
| } | ||
|
|
||
| glUnmapBuffer( bufferTarget ); | ||
|
|
||
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.
Oddly placed GL_CheckErrors.
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.
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?