Skip to content

Commit 2d4e359

Browse files
committed
lights: Change r_showDynamicLights to show a cube for omni lights
Switch to a wireframe cube to make omni lights less busy
1 parent 4fb5b96 commit 2d4e359

File tree

1 file changed

+68
-63
lines changed

1 file changed

+68
-63
lines changed

src/engine/renderer/tr_backend.cpp

Lines changed: 68 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,9 +2347,7 @@ static void RB_RenderDebugUtils()
23472347
for ( int i = 0; i < backEnd.refdef.numLights; ++i )
23482348
{
23492349
const refLight_t &light = lights[ i ];
2350-
// We can't really visualize directional lights since they don't
2351-
// have an origin or a radius.
2352-
if ( light.rlType >= refLightType_t::RL_DIRECTIONAL )
2350+
if ( light.rlType != refLightType_t::RL_PROJ )
23532351
{
23542352
continue;
23552353
}
@@ -2362,77 +2360,84 @@ static void RB_RenderDebugUtils()
23622360
Log::Warn( "Light with index %d has no radius", i );
23632361
}
23642362

2365-
auto addArrow = [ & ]( const vec3_t dirInput, const Color::Color &arrowColor )
2363+
Color::Color color = Color::LtGrey;
2364+
2365+
vec3_t dir;
2366+
VectorCopy( light.projTarget, dir );
2367+
if ( VectorNormalize( dir ) == 0.0f )
23662368
{
2367-
vec3_t dir;
2368-
VectorCopy( dirInput, dir );
2369-
if ( VectorNormalize( dir ) == 0.0f )
2370-
{
2371-
VectorSet( dir, 0.0f, 0.0f, 1.0f );
2372-
}
2373-
// Surface normals point outward from the object. And a light is rendered when the product of its direction and the surface normal is positive.
2374-
// So the light direction vector has to point away from the source for it to work.
2375-
// Negate the direction so the skinny end of the tetrahedron points the same direction as the light.
2376-
VectorNegate( dir, dir );
2377-
2378-
vec3_t tip;
2379-
VectorMA( baseOrigin, light.radius, dir, tip );
2380-
2381-
vec3_t tmp;
2382-
vec3_t tmp2;
2383-
vec3_t tmp3;
2384-
PerpendicularVector( tmp, dir );
2385-
VectorScale( tmp, light.radius * 0.2f, tmp2 );
2386-
VectorMA( tmp2, light.radius * 0.3f, dir, tmp2 );
2387-
2388-
vec4_t tetraVerts[ 4 ];
2389-
for ( int k = 0; k < 3; k++ )
2390-
{
2391-
RotatePointAroundVector( tmp3, dir, tmp2, k * 120.0f );
2392-
VectorAdd( tmp3, baseOrigin, tmp3 );
2393-
VectorCopy( tmp3, tetraVerts[ k ] );
2394-
tetraVerts[ k ][ 3 ] = 1.0f;
2395-
}
2369+
VectorSet( dir, 0.0f, 0.0f, 1.0f );
2370+
}
2371+
// Surface normals point outward from the object. And a light is rendered when the product of its
2372+
// direction and the surface normal is positive. So the light direction vector has to point away from
2373+
// the source for it to work.
2374+
// Negate the direction so the skinny end of the tetrahedron points the same direction as the light.
2375+
VectorNegate( dir, dir );
2376+
2377+
vec3_t tip;
2378+
VectorMA( baseOrigin, light.radius, dir, tip );
2379+
2380+
vec3_t tmp;
2381+
vec3_t tmp2;
2382+
vec3_t tmp3;
2383+
PerpendicularVector( tmp, dir );
2384+
VectorScale( tmp, light.radius * 0.2f, tmp2 );
2385+
VectorMA( tmp2, light.radius * 0.3f, dir, tmp2 );
2386+
2387+
vec4_t tetraVerts[ 4 ];
2388+
for ( int k = 0; k < 3; k++ )
2389+
{
2390+
RotatePointAroundVector( tmp3, dir, tmp2, k * 120.0f );
2391+
VectorAdd( tmp3, baseOrigin, tmp3 );
2392+
VectorCopy( tmp3, tetraVerts[ k ] );
2393+
tetraVerts[ k ][ 3 ] = 1.0f;
2394+
}
2395+
2396+
VectorCopy( baseOrigin, tetraVerts[ 3 ] );
2397+
tetraVerts[ 3 ][ 3 ] = 1.0f;
2398+
Tess_AddTetrahedron( tetraVerts, color );
23962399

2397-
VectorCopy( baseOrigin, tetraVerts[ 3 ] );
2398-
tetraVerts[ 3 ][ 3 ] = 1.0f;
2399-
Tess_AddTetrahedron( tetraVerts, arrowColor );
2400+
VectorCopy( tip, tetraVerts[ 3 ] );
2401+
tetraVerts[ 3 ][ 3 ] = 1.0f;
24002402

2401-
VectorCopy( tip, tetraVerts[ 3 ] );
2402-
tetraVerts[ 3 ][ 3 ] = 1.0f;
2403+
Tess_AddTetrahedron( tetraVerts, color );
2404+
}
2405+
2406+
Tess_End();
2407+
GL_CheckErrors();
2408+
2409+
const uint32_t savedStateBits = glState.glStateBits;
2410+
GL_State( GLS_POLYMODE_LINE );
2411+
2412+
Tess_Begin( Tess_StageIteratorDebug, nullptr, true, -1, 0 );
2413+
2414+
for ( int i = 0; i < backEnd.refdef.numLights; ++i )
2415+
{
2416+
const refLight_t &light = lights[ i ];
2417+
if ( light.rlType != refLightType_t::RL_OMNI )
2418+
{
2419+
continue;
2420+
}
24032421

2404-
Tess_AddTetrahedron( tetraVerts, arrowColor );
2405-
};
2422+
vec3_t baseOrigin;
2423+
VectorCopy( light.origin, baseOrigin );
24062424

2407-
Color::Color color;
2408-
switch ( light.rlType )
2425+
if ( light.radius <= 0.0f )
24092426
{
2410-
case refLightType_t::RL_PROJ:
2411-
color = Color::LtGrey;
2412-
addArrow( light.projTarget, color );
2413-
break;
2414-
default:
2415-
color = Color::MdGrey;
2416-
{
2417-
static const vec3_t kOmniDirs[ 6 ] = {
2418-
{ 1.0f, 0.0f, 0.0f },
2419-
{ -1.0f, 0.0f, 0.0f },
2420-
{ 0.0f, 1.0f, 0.0f },
2421-
{ 0.0f, -1.0f, 0.0f },
2422-
{ 0.0f, 0.0f, 1.0f },
2423-
{ 0.0f, 0.0f, -1.0f}
2424-
};
2425-
for ( int dirIndex = 0; dirIndex < 6; ++dirIndex )
2426-
{
2427-
addArrow( kOmniDirs[ dirIndex ], color );
2428-
}
2429-
}
2430-
break;
2427+
Log::Warn( "Light with index %d has no radius", i );
24312428
}
2429+
2430+
vec3_t cubeMins;
2431+
vec3_t cubeMaxs;
2432+
const float halfSize = light.radius * 0.5f;
2433+
VectorSet( cubeMins, -halfSize, -halfSize, -halfSize );
2434+
VectorSet( cubeMaxs, halfSize, halfSize, halfSize );
2435+
Tess_AddCube( baseOrigin, cubeMins, cubeMaxs, Color::MdGrey );
24322436
}
24332437

24342438
Tess_End();
24352439
GL_CheckErrors();
2440+
GL_State( savedStateBits );
24362441
}
24372442

24382443
if ( r_showBspNodes->integer )

0 commit comments

Comments
 (0)