Don't allocate non shadow casting lights into the shadow atlasgit difftool #746

This commit is contained in:
Robert Beckebans 2023-02-24 13:04:34 +01:00
parent 91abc9dffd
commit 302eb3fa85
4 changed files with 41 additions and 13 deletions

View file

@ -44,7 +44,7 @@ static const int IRRADIANCE_OCTAHEDRON_SIZE = 30 + 2;
//static int shadowMapResolutions[MAX_SHADOWMAP_RESOLUTIONS] = { 2048, 1024, 512, 512, 256 };
// if we use higher resolutions than this than the shadow casting lights don't fit into the 16384^2 atlas anymore
static int shadowMapResolutions[MAX_SHADOWMAP_RESOLUTIONS] = { 1024, 512, 512, 256, 128 };
static int shadowMapResolutions[MAX_SHADOWMAP_RESOLUTIONS] = { 1024, 512, 256, 256, 128 };
class Framebuffer

View file

@ -1235,7 +1235,7 @@ void idRenderBackend::DrawSingleInteraction( drawInteraction_t* din, bool useFas
}
else
{
if( !r_skipShadows.GetBool() && r_useShadowMapping.GetBool() && din->vLight->globalShadows )
if( !r_skipShadows.GetBool() && r_useShadowMapping.GetBool() && din->vLight->globalShadows && din->vLight->shadowLOD > -1 )
{
// RB: we have shadow mapping enabled and shadow maps so do a shadow compare
@ -1616,7 +1616,7 @@ void idRenderBackend::RenderInteractions( const drawSurf_t* surfList, const view
bool lightDepthBoundsDisabled = false;
// RB begin
if( !r_skipShadows.GetBool() && r_useShadowMapping.GetBool() )
if( !r_skipShadows.GetBool() && r_useShadowMapping.GetBool() && vLight->shadowLOD > -1 )
{
const static int JITTER_SIZE = 128;
@ -4019,10 +4019,16 @@ void idRenderBackend::ShadowAtlasPass( const viewDef_t* _viewDef )
GL_ViewportAndScissor( 0, 0, r_shadowMapAtlasSize.GetInteger(), r_shadowMapAtlasSize.GetInteger() );
const nvrhi::FramebufferAttachment& att = currentFrameBuffer->GetApiObject()->getDesc().depthAttachment;
if( att.texture )
const nvrhi::FramebufferAttachment& attColor = currentFrameBuffer->GetApiObject()->getDesc().colorAttachments[0];
if( attColor.texture )
{
commandList->clearDepthStencilTexture( att.texture, nvrhi::AllSubresources, true, 1.0f, false, 0x80 );
commandList->clearTextureFloat( attColor.texture, nvrhi::AllSubresources, nvrhi::Color( 0.0f ) );
}
const nvrhi::FramebufferAttachment& attDepth = currentFrameBuffer->GetApiObject()->getDesc().depthAttachment;
if( attDepth.texture )
{
commandList->clearDepthStencilTexture( attDepth.texture, nvrhi::AllSubresources, true, 1.0f, false, 0x80 );
}
//
@ -4031,7 +4037,7 @@ void idRenderBackend::ShadowAtlasPass( const viewDef_t* _viewDef )
int shadowIndex = 0;
idList<idVec2i> inputSizes;
//idStrList inputNames;
idStrList inputNames;
for( const viewLight_t* vLight = viewDef->viewLights; vLight != NULL; vLight = vLight->next )
{
@ -4050,6 +4056,12 @@ void idRenderBackend::ShadowAtlasPass( const viewDef_t* _viewDef )
continue;
}
if( vLight->shadowLOD == -1 )
{
// light doesn't cast shadows
continue;
}
int side, sideStop;
if( vLight->parallel )
@ -4080,8 +4092,13 @@ void idRenderBackend::ShadowAtlasPass( const viewDef_t* _viewDef )
for( ; side < sideStop ; side++ )
{
inputSizes.Append( idVec2i( shadowMapResolutions[ vLight->shadowLOD ], shadowMapResolutions[ vLight->shadowLOD ] ) );
//inputNames.Append( lightShader->GetName() );
idVec2i size( shadowMapResolutions[ vLight->shadowLOD ], shadowMapResolutions[ vLight->shadowLOD ] );
inputSizes.Append( size );
if( size.x >= 1024 )
{
inputNames.Append( lightShader->GetName() );
}
shadowIndex++;
}
@ -4182,6 +4199,13 @@ void idRenderBackend::ShadowAtlasPass( const viewDef_t* _viewDef )
continue;
}
if( vLight->shadowLOD == -1 )
{
// light doesn't cast shadows
vLight->imageSize.x = vLight->imageSize.y = -1;
continue;
}
const idMaterial* lightShader = vLight->lightShader;
renderLog.OpenBlock( lightShader->GetName(), colorMdGrey );

View file

@ -271,7 +271,7 @@ idCVar r_useVirtualScreenResolution( "r_useVirtualScreenResolution", "0", CVAR_R
idCVar r_useShadowMapping( "r_useShadowMapping", "1", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_INTEGER, "use shadow mapping instead of stencil shadows" );
#endif
idCVar r_useShadowAtlas( "r_useShadowAtlas", "1", CVAR_RENDERER | CVAR_INTEGER, "" );
idCVar r_shadowMapAtlasSize( "r_shadowMapAtlasSize", "16384", CVAR_RENDERER | CVAR_INTEGER | CVAR_ROM, "size of the shadowmap atlas" );
idCVar r_shadowMapAtlasSize( "r_shadowMapAtlasSize", "8192", CVAR_RENDERER | CVAR_INTEGER | CVAR_ROM, "size of the shadowmap atlas" );
idCVar r_shadowMapFrustumFOV( "r_shadowMapFrustumFOV", "92", CVAR_RENDERER | CVAR_FLOAT, "oversize FOV for point light side matching" );
idCVar r_shadowMapSingleSide( "r_shadowMapSingleSide", "-1", CVAR_RENDERER | CVAR_INTEGER, "only draw a single side (0-5) of point lights" );
idCVar r_shadowMapImageSize( "r_shadowMapImageSize", "1024", CVAR_RENDERER | CVAR_INTEGER, "", 128, 2048 );

View file

@ -266,7 +266,9 @@ static void R_AddSingleLight( viewLight_t* vLight )
vLight->scissorRect.zmax = projected[1][2];
// RB: calculate shadow LOD similar to Q3A .md3 LOD code
vLight->shadowLOD = 0;
// -1 means no shadows
vLight->shadowLOD = -1;
if( r_useShadowMapping.GetBool() && lightCastsShadows )
{
@ -275,6 +277,8 @@ static void R_AddSingleLight( viewLight_t* vLight )
int lod;
int numLods;
vLight->shadowLOD = 0;
numLods = MAX_SHADOWMAP_RESOLUTIONS;
// compute projected bounding sphere
@ -327,9 +331,9 @@ static void R_AddSingleLight( viewLight_t* vLight )
if( lod >= numLods )
{
// don't draw any shadow
//lod = -1;
lod = -1;
lod = numLods - 1;
//lod = numLods - 1;
}
// 2048^2 ultra quality is only for cascaded shadow mapping with sun lights