mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-14 06:34:10 +00:00
Always clear the envprobe FBO for lightgrid capturing
This commit is contained in:
parent
cdc39a0294
commit
60330e2d8d
6 changed files with 63 additions and 31 deletions
|
@ -160,9 +160,9 @@ void TonemapPass::Render(
|
|||
state.framebuffer = _targetFb;
|
||||
state.bindings = { renderBindingSet };
|
||||
nvrhi::Viewport viewport{ ( float )viewDef->viewport.x1,
|
||||
( float )viewDef->viewport.x2,
|
||||
( float )viewDef->viewport.x2 + 1,
|
||||
( float )viewDef->viewport.y1,
|
||||
( float )viewDef->viewport.y2,
|
||||
( float )viewDef->viewport.y2 + 1,
|
||||
viewDef->viewport.zmin,
|
||||
viewDef->viewport.zmax };
|
||||
state.viewport.addViewportAndScissorRect( viewport );
|
||||
|
|
|
@ -6753,17 +6753,15 @@ void idRenderBackend::DrawViewInternal( const viewDef_t* _viewDef, const int ste
|
|||
|
||||
bool useHDR = r_useHDR.GetBool() && !_viewDef->is2Dgui;
|
||||
bool clearColor = false;
|
||||
if( useHDR )
|
||||
|
||||
if( _viewDef->renderView.rdflags & RDF_IRRADIANCE )
|
||||
{
|
||||
if( _viewDef->renderView.rdflags & RDF_IRRADIANCE )
|
||||
{
|
||||
globalFramebuffers.envprobeFBO->Bind();
|
||||
clearColor = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
globalFramebuffers.hdrFBO->Bind();
|
||||
}
|
||||
globalFramebuffers.envprobeFBO->Bind();
|
||||
clearColor = true;
|
||||
}
|
||||
else if( useHDR )
|
||||
{
|
||||
globalFramebuffers.hdrFBO->Bind();
|
||||
}
|
||||
else if( viewDef->targetRender )
|
||||
{
|
||||
|
@ -7228,6 +7226,11 @@ void idRenderBackend::DrawView( const void* data, const int stereoEye )
|
|||
// if there aren't any drawsurfs, do nothing
|
||||
if( !viewDef->numDrawSurfs )
|
||||
{
|
||||
if( viewDef->renderView.rdflags & RDF_IRRADIANCE )
|
||||
{
|
||||
nvrhi::utils::ClearColorAttachment( commandList, globalFramebuffers.envprobeFBO->GetApiObject(), 0, nvrhi::Color( 0.f ) );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -7451,8 +7454,7 @@ void idRenderBackend::PostProcess( const void* data )
|
|||
blitParms.sourceTexture = ( nvrhi::ITexture* )globalImages->ldrImage->GetTextureID();
|
||||
blitParms.targetFramebuffer = globalFramebuffers.smaaBlendFBO->GetApiObject();
|
||||
|
||||
// RB: add + 1 to dimensions so filtering works
|
||||
blitParms.targetViewport = nvrhi::Viewport( renderSystem->GetWidth() + 1, renderSystem->GetHeight() + 1 );
|
||||
blitParms.targetViewport = nvrhi::Viewport( renderSystem->GetWidth(), renderSystem->GetHeight() );
|
||||
commonPasses.BlitTexture( commandList, blitParms, &bindingCache );
|
||||
|
||||
GL_SelectTexture( 0 );
|
||||
|
|
|
@ -1350,7 +1350,7 @@ NVRHI helpers
|
|||
====================================================================
|
||||
*/
|
||||
bool R_ReadPixelsRGB8( nvrhi::IDevice* device, CommonRenderPasses* pPasses, nvrhi::ITexture* texture, nvrhi::ResourceStates textureState, const char* fullname );
|
||||
bool R_ReadPixelsRGB16F( nvrhi::IDevice* device, CommonRenderPasses* pPasses, nvrhi::ITexture* texture, nvrhi::ResourceStates textureState, void* pic, int picWidth, int picHeight );
|
||||
bool R_ReadPixelsRGB16F( nvrhi::IDevice* device, CommonRenderPasses* pPasses, nvrhi::ITexture* texture, nvrhi::ResourceStates textureState, byte** pic, int picWidth, int picHeight );
|
||||
|
||||
/*
|
||||
====================================================================
|
||||
|
|
|
@ -885,9 +885,19 @@ bool R_ReadPixelsRGB8( nvrhi::IDevice* device, CommonRenderPasses* pPasses, nvrh
|
|||
pData = newData;
|
||||
}
|
||||
|
||||
// fix alpha
|
||||
byte* data = static_cast<byte*>( pData );
|
||||
|
||||
#if 0
|
||||
// fill with red for debugging
|
||||
for( int i = 0; i < ( desc.width * desc.height ); i++ )
|
||||
{
|
||||
data[ i * 4 + 0 ] = 255;
|
||||
data[ i * 4 + 1 ] = 0;
|
||||
data[ i * 4 + 2 ] = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
// fix alpha
|
||||
for( int i = 0; i < ( desc.width * desc.height ); i++ )
|
||||
{
|
||||
data[ i * 4 + 3 ] = 0xff;
|
||||
|
@ -906,16 +916,18 @@ bool R_ReadPixelsRGB8( nvrhi::IDevice* device, CommonRenderPasses* pPasses, nvrh
|
|||
return true;
|
||||
}
|
||||
|
||||
bool R_ReadPixelsRGB16F( nvrhi::IDevice* device, CommonRenderPasses* pPasses, nvrhi::ITexture* texture, nvrhi::ResourceStates textureState, void* pic, int picWidth, int picHeight )
|
||||
bool R_ReadPixelsRGB16F( nvrhi::IDevice* device, CommonRenderPasses* pPasses, nvrhi::ITexture* texture, nvrhi::ResourceStates textureState, byte** pic, int picWidth, int picHeight )
|
||||
{
|
||||
nvrhi::TextureDesc desc = texture->getDesc();
|
||||
nvrhi::TextureHandle tempTexture;
|
||||
nvrhi::FramebufferHandle tempFramebuffer;
|
||||
|
||||
#if 0
|
||||
if( desc.width != picWidth || desc.height != picHeight )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
nvrhi::CommandListHandle commandList = device->createCommandList();
|
||||
commandList->open();
|
||||
|
@ -976,9 +988,22 @@ bool R_ReadPixelsRGB16F( nvrhi::IDevice* device, CommonRenderPasses* pPasses, nv
|
|||
pData = newData;
|
||||
}
|
||||
|
||||
int pix = picWidth * picHeight;
|
||||
const int bufferSize = pix * 3 * 2;
|
||||
|
||||
void* floatRGB16F = R_StaticAlloc( bufferSize );
|
||||
*pic = ( byte* ) floatRGB16F;
|
||||
|
||||
// copy from RGBA16F to RGB16F
|
||||
uint16_t* data = static_cast<uint16_t*>( pData );
|
||||
uint16_t* outData = static_cast<uint16_t*>( pic );
|
||||
uint16_t* outData = static_cast<uint16_t*>( floatRGB16F );
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
for( int i = 0; i < ( desc.width * desc.height ); i++ )
|
||||
{
|
||||
|
|
|
@ -1049,15 +1049,13 @@ CONSOLE_COMMAND( bakeEnvironmentProbes, "Bake environment probes", NULL )
|
|||
// discard anything currently on the list (this triggers SwapBuffers)
|
||||
tr.SwapCommandBuffers( NULL, NULL, NULL, NULL, NULL, NULL );
|
||||
|
||||
int pix = captureSize * captureSize;
|
||||
const int bufferSize = pix * 3 * 2;
|
||||
|
||||
byte* floatRGB16F = ( byte* )R_StaticAlloc( bufferSize );
|
||||
|
||||
#if defined( USE_VULKAN )
|
||||
// TODO
|
||||
#elif defined( USE_NVRHI )
|
||||
R_ReadPixelsRGB16F( deviceManager->GetDevice(), &tr.backend.GetCommonPasses(), globalImages->envprobeHDRImage->GetTextureHandle() , nvrhi::ResourceStates::RenderTarget, floatRGB16F, captureSize, captureSize );
|
||||
|
||||
byte* floatRGB16F = NULL;
|
||||
|
||||
R_ReadPixelsRGB16F( deviceManager->GetDevice(), &tr.backend.GetCommonPasses(), globalImages->envprobeHDRImage->GetTextureHandle() , nvrhi::ResourceStates::RenderTarget, &floatRGB16F, captureSize, captureSize );
|
||||
|
||||
#if 0
|
||||
idStr testName;
|
||||
|
@ -1066,6 +1064,11 @@ CONSOLE_COMMAND( bakeEnvironmentProbes, "Bake environment probes", NULL )
|
|||
#endif
|
||||
|
||||
#else
|
||||
int pix = captureSize * captureSize;
|
||||
const int bufferSize = pix * 3 * 2;
|
||||
|
||||
byte* floatRGB16F = ( byte* )R_StaticAlloc( bufferSize );
|
||||
|
||||
|
||||
glFinish();
|
||||
|
||||
|
|
|
@ -1275,29 +1275,31 @@ CONSOLE_COMMAND( bakeLightGrids, "Bake irradiance/vis light grid data", NULL )
|
|||
// discard anything currently on the list (this triggers SwapBuffers)
|
||||
tr.SwapCommandBuffers( NULL, NULL, NULL, NULL, NULL, NULL );
|
||||
|
||||
int pix = captureSize * captureSize;
|
||||
const int bufferSize = pix * 3 * 2;
|
||||
|
||||
byte* floatRGB16F = ( byte* )R_StaticAlloc( bufferSize );
|
||||
|
||||
#if defined( USE_VULKAN )
|
||||
// TODO
|
||||
#elif defined( USE_NVRHI )
|
||||
// make sure that all frames have finished rendering
|
||||
//deviceManager->GetDevice()->waitForIdle();
|
||||
|
||||
R_ReadPixelsRGB16F( deviceManager->GetDevice(), &tr.backend.GetCommonPasses(), globalImages->envprobeHDRImage->GetTextureHandle() , nvrhi::ResourceStates::RenderTarget, floatRGB16F, captureSize, captureSize );
|
||||
byte* floatRGB16F = NULL;
|
||||
|
||||
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
|
||||
#if 1
|
||||
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
|
||||
int pix = captureSize * captureSize;
|
||||
const int bufferSize = pix * 3 * 2;
|
||||
|
||||
byte* floatRGB16F = ( byte* )R_StaticAlloc( bufferSize );
|
||||
|
||||
glFinish();
|
||||
|
||||
glReadBuffer( GL_BACK );
|
||||
|
|
Loading…
Reference in a new issue