mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-14 06:34:10 +00:00
[bakeLightGrids] Fixed too bright grid points caused by bad cubemap captures
This commit is contained in:
parent
2e6f61f9cb
commit
7f95839129
2 changed files with 56 additions and 5 deletions
|
@ -998,12 +998,14 @@ bool R_ReadPixelsRGB16F( nvrhi::IDevice* device, CommonRenderPasses* pPasses, nv
|
|||
uint16_t* data = static_cast<uint16_t*>( pData );
|
||||
uint16_t* outData = static_cast<uint16_t*>( floatRGB16F );
|
||||
|
||||
#if 0
|
||||
for( int i = 0; i < ( desc.width * desc.height ); i++ )
|
||||
{
|
||||
outData[ i * 3 + 0 ] = F32toF16( 1 );
|
||||
outData[ i * 3 + 1 ] = F32toF16( 0 );
|
||||
outData[ i * 3 + 2 ] = F32toF16( 0 );
|
||||
}
|
||||
#endif
|
||||
|
||||
for( int i = 0; i < ( desc.width * desc.height ); i++ )
|
||||
{
|
||||
|
@ -1012,6 +1014,45 @@ bool R_ReadPixelsRGB16F( nvrhi::IDevice* device, CommonRenderPasses* pPasses, nv
|
|||
outData[ i * 3 + 2 ] = data[ i * 4 + 2 ];
|
||||
}
|
||||
|
||||
// RB: filter out garbage and reset it to black
|
||||
// this is a rare case but with a high visual impact
|
||||
bool isCorrupted = false;
|
||||
|
||||
const idVec3 LUMINANCE_LINEAR( 0.299f, 0.587f, 0.144f );
|
||||
idVec3 rgb;
|
||||
|
||||
for( int i = 0; i < ( desc.width * desc.height ); i++ )
|
||||
{
|
||||
rgb.x = F16toF32( outData[ i * 3 + 0 ] );
|
||||
rgb.y = F16toF32( outData[ i * 3 + 1 ] );
|
||||
rgb.z = F16toF32( outData[ i * 3 + 2 ] );
|
||||
|
||||
if( IsNAN( rgb.x ) || IsNAN( rgb.y ) || IsNAN( rgb.z ) )
|
||||
{
|
||||
isCorrupted = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// captures within the Doom 3 main campaign usually have a luminance of ~ 0.5 - 4.0
|
||||
// the threshold is a bit higher and might need to be adapted for total conversion content
|
||||
float luminance = rgb * LUMINANCE_LINEAR;
|
||||
if( luminance > 20.0f )
|
||||
{
|
||||
isCorrupted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( isCorrupted )
|
||||
{
|
||||
for( int i = 0; i < ( desc.width * desc.height ); i++ )
|
||||
{
|
||||
outData[ i * 3 + 0 ] = F32toF16( 0 );
|
||||
outData[ i * 3 + 1 ] = F32toF16( 0 );
|
||||
outData[ i * 3 + 2 ] = F32toF16( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
if( newData )
|
||||
{
|
||||
delete[] newData;
|
||||
|
@ -1020,7 +1061,7 @@ bool R_ReadPixelsRGB16F( nvrhi::IDevice* device, CommonRenderPasses* pPasses, nv
|
|||
|
||||
device->unmapStagingTexture( stagingTexture );
|
||||
|
||||
return true;
|
||||
return ( !isCorrupted );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1283,15 +1283,25 @@ CONSOLE_COMMAND( bakeLightGrids, "Bake irradiance/vis light grid data", NULL )
|
|||
|
||||
byte* floatRGB16F = NULL;
|
||||
|
||||
#if 0
|
||||
// this probe fails in game/admin.map
|
||||
if( a == 5 && tr.lightGridJobs.Num() == 17 && side == 4 )
|
||||
{
|
||||
idLib::Printf( "debugging shitty capture\n" );
|
||||
}
|
||||
#endif
|
||||
//bool validCapture =
|
||||
R_ReadPixelsRGB16F( deviceManager->GetDevice(), &tr.backend.GetCommonPasses(), globalImages->envprobeHDRImage->GetTextureHandle() , nvrhi::ResourceStates::RenderTarget, &floatRGB16F, captureSize, captureSize );
|
||||
|
||||
// release all in-flight references to the render targets
|
||||
//deviceManager->GetDevice()->runGarbageCollection();
|
||||
|
||||
#if 0
|
||||
idStr testName;
|
||||
testName.Format( "env/test/area%i_envprobe_%i_side_%i.exr", a, tr.lightGridJobs.Num(), side );
|
||||
R_WriteEXR( testName, floatRGB16F, 3, captureSize, captureSize, "fs_basepath" );
|
||||
if( !validCapture )
|
||||
{
|
||||
idStr testName;
|
||||
testName.Format( "env/test/area%i_envprobe_%i_side_%i.exr", a, tr.lightGridJobs.Num(), side );
|
||||
R_WriteEXR( testName, floatRGB16F, 3, captureSize, captureSize, "fs_basepath" );
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
|
Loading…
Reference in a new issue