mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-14 06:34:10 +00:00
Fixed filmic post processing #661
This commit is contained in:
parent
94fea5c38c
commit
461001d5c0
10 changed files with 136 additions and 64 deletions
|
@ -143,7 +143,7 @@ struct globalFramebuffers_t
|
|||
Framebuffer* shadowFBO[MAX_SHADOWMAP_RESOLUTIONS][6];
|
||||
Framebuffer* hdrFBO;
|
||||
Framebuffer* ldrFBO;
|
||||
Framebuffer* postProcFBO;
|
||||
Framebuffer* postProcFBO; // HDR16
|
||||
Framebuffer* taaMotionVectorsFBO;
|
||||
Framebuffer* taaResolvedFBO;
|
||||
Framebuffer* hdr64FBO; // TODO remove, not needed with new NVRHI tonemapping anymore
|
||||
|
|
|
@ -234,8 +234,6 @@ static void R_RGBA8LinearImage( idImage* image, nvrhi::ICommandList* commandList
|
|||
|
||||
static void R_LdrNativeImage( idImage* image, nvrhi::ICommandList* commandList )
|
||||
{
|
||||
//uint sampleCount = GetMSAASamples();
|
||||
|
||||
image->GenerateImage( NULL, renderSystem->GetWidth(), renderSystem->GetHeight(), TF_NEAREST, TR_CLAMP, TD_LOOKUP_TABLE_RGBA, nullptr, true, false, 1 );
|
||||
}
|
||||
|
||||
|
|
|
@ -2198,7 +2198,7 @@ void idMaterial::ParseStage( idLexer& src, const textureRepeat_t trpDefault )
|
|||
// if we are using newStage, allocate a copy of it
|
||||
if( newStage.fragmentProgram || newStage.vertexProgram )
|
||||
{
|
||||
newStage.glslProgram = renderProgManager.FindProgram( GetName(), newStage.vertexProgram, newStage.fragmentProgram, BINDING_LAYOUT_POST_PROCESS_CNM );
|
||||
newStage.glslProgram = renderProgManager.FindProgram( GetName(), newStage.vertexProgram, newStage.fragmentProgram, BINDING_LAYOUT_POST_PROCESS_INGAME );
|
||||
ss->newStage = ( newShaderStage_t* )Mem_Alloc( sizeof( newStage ), TAG_MATERIAL );
|
||||
*( ss->newStage ) = newStage;
|
||||
}
|
||||
|
|
|
@ -219,7 +219,7 @@ void Framebuffer::ResizeFramebuffers()
|
|||
nvrhi::FramebufferDesc()
|
||||
.addColorAttachment( globalImages->smaaEdgesImage->texture ) );
|
||||
|
||||
globalFramebuffers.smaaEdgesFBO = new Framebuffer( "_smaaBlend",
|
||||
globalFramebuffers.smaaBlendFBO = new Framebuffer( "_smaaBlend",
|
||||
nvrhi::FramebufferDesc()
|
||||
.addColorAttachment( globalImages->smaaBlendImage->texture ) );
|
||||
|
||||
|
|
|
@ -622,7 +622,37 @@ void idRenderBackend::GetCurrentBindingLayout( int type )
|
|||
desc[1].bindings[1].resourceHandle = commonPasses.m_LinearClampSampler;
|
||||
}
|
||||
}
|
||||
else if( type == BINDING_LAYOUT_POST_PROCESS_CNM )
|
||||
else if( type == BINDING_LAYOUT_BLENDLIGHT )
|
||||
{
|
||||
if( desc[0].bindings.empty() )
|
||||
{
|
||||
desc[0].bindings =
|
||||
{
|
||||
nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ),
|
||||
nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ),
|
||||
nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() )
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer();
|
||||
desc[0].bindings[1].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID();
|
||||
desc[0].bindings[2].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID();
|
||||
}
|
||||
|
||||
if( desc[1].bindings.empty() )
|
||||
{
|
||||
desc[1].bindings =
|
||||
{
|
||||
nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_LinearBorderSampler )
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
desc[1].bindings[0].resourceHandle = commonPasses.m_LinearBorderSampler;
|
||||
}
|
||||
}
|
||||
else if( type == BINDING_LAYOUT_POST_PROCESS_INGAME )
|
||||
{
|
||||
if( desc[0].bindings.empty() )
|
||||
{
|
||||
|
@ -654,6 +684,38 @@ void idRenderBackend::GetCurrentBindingLayout( int type )
|
|||
desc[1].bindings[0].resourceHandle = commonPasses.m_LinearClampSampler;
|
||||
}
|
||||
}
|
||||
else if( type == BINDING_LAYOUT_POST_PROCESS_FINAL )
|
||||
{
|
||||
if( desc[0].bindings.empty() )
|
||||
{
|
||||
desc[0].bindings =
|
||||
{
|
||||
nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ),
|
||||
nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ),
|
||||
nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() )
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer();
|
||||
desc[0].bindings[1].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID();
|
||||
desc[0].bindings[2].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID();
|
||||
}
|
||||
|
||||
if( desc[1].bindings.empty() )
|
||||
{
|
||||
desc[1].bindings =
|
||||
{
|
||||
nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_LinearClampSampler ),
|
||||
nvrhi::BindingSetItem::Sampler( 1, commonPasses.m_LinearWrapSampler )
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
desc[1].bindings[0].resourceHandle = commonPasses.m_LinearClampSampler;
|
||||
desc[1].bindings[1].resourceHandle = commonPasses.m_LinearWrapSampler;
|
||||
}
|
||||
}
|
||||
else if( type == BINDING_LAYOUT_NORMAL_CUBE )
|
||||
{
|
||||
if( desc[0].bindings.empty() )
|
||||
|
@ -684,36 +746,6 @@ void idRenderBackend::GetCurrentBindingLayout( int type )
|
|||
desc[1].bindings[0].resourceHandle = commonPasses.m_LinearWrapSampler;
|
||||
}
|
||||
}
|
||||
else if( type == BINDING_LAYOUT_BLENDLIGHT )
|
||||
{
|
||||
if( desc[0].bindings.empty() )
|
||||
{
|
||||
desc[0].bindings =
|
||||
{
|
||||
nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ),
|
||||
nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ),
|
||||
nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() )
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer();
|
||||
desc[0].bindings[1].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID();
|
||||
desc[0].bindings[2].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID();
|
||||
}
|
||||
|
||||
if( desc[1].bindings.empty() )
|
||||
{
|
||||
desc[1].bindings =
|
||||
{
|
||||
nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_LinearBorderSampler )
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
desc[1].bindings[0].resourceHandle = commonPasses.m_LinearBorderSampler;
|
||||
}
|
||||
}
|
||||
else if( type == BINDING_LAYOUT_TAA_MOTION_VECTORS )
|
||||
{
|
||||
if( desc[0].bindings.empty() )
|
||||
|
|
|
@ -7320,28 +7320,34 @@ void idRenderBackend::PostProcess( const void* data )
|
|||
{
|
||||
// only do the post process step if resolution scaling is enabled. Prevents the unnecessary copying of the framebuffer and
|
||||
// corresponding full screen quad pass.
|
||||
/*
|
||||
if( rs_enable.GetInteger() == 0 && !r_useFilmicPostProcessing.GetBool() && r_antiAliasing.GetInteger() == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if( ( r_ssaoDebug.GetInteger() > 0 ) || ( r_ssgiDebug.GetInteger() > 0 ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
if( viewDef->renderView.rdflags & RDF_IRRADIANCE )
|
||||
{
|
||||
#if defined( USE_NVRHI )
|
||||
// we haven't changed ldrImage so it's basically the previewsRenderLDR
|
||||
BlitParameters blitParms;
|
||||
blitParms.sourceTexture = ( nvrhi::ITexture* )globalImages->ldrImage->GetTextureID();
|
||||
blitParms.targetFramebuffer = deviceManager->GetCurrentFramebuffer();
|
||||
blitParms.targetViewport = nvrhi::Viewport( renderSystem->GetWidth(), renderSystem->GetHeight() );
|
||||
commonPasses.BlitTexture( commandList, blitParms, &bindingCache );
|
||||
|
||||
blitParms.sourceTexture = ( nvrhi::ITexture* )globalImages->envprobeHDRImage->GetTextureID();
|
||||
blitParms.targetFramebuffer = deviceManager->GetCurrentFramebuffer();
|
||||
blitParms.targetViewport = nvrhi::Viewport( ENVPROBE_CAPTURE_SIZE, ENVPROBE_CAPTURE_SIZE );
|
||||
commonPasses.BlitTexture( commandList, blitParms, &bindingCache );
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
renderLog.OpenMainBlock( MRB_POSTPROCESS );
|
||||
renderLog.OpenBlock( "Render_PostProcessing", colorBlue );
|
||||
|
||||
// FIXME
|
||||
#if !defined(USE_VULKAN) && !defined(USE_NVRHI)
|
||||
|
||||
// resolve the scaled rendering to a temporary texture
|
||||
postProcessCommand_t* cmd = ( postProcessCommand_t* )data;
|
||||
const idScreenRect& viewport = cmd->viewDef->viewport;
|
||||
|
@ -7355,6 +7361,7 @@ void idRenderBackend::PostProcess( const void* data )
|
|||
GL_Viewport( 0, 0, screenWidth, screenHeight );
|
||||
GL_Scissor( 0, 0, screenWidth, screenHeight );
|
||||
|
||||
#if 0
|
||||
// SMAA
|
||||
int aaMode = r_antiAliasing.GetInteger();
|
||||
if( aaMode == ANTI_ALIASING_SMAA_1X )
|
||||
|
@ -7435,13 +7442,28 @@ void idRenderBackend::PostProcess( const void* data )
|
|||
DrawElementsWithCounters( &unitSquareSurface );
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if( r_useFilmicPostProcessing.GetBool() )
|
||||
{
|
||||
#if defined( USE_NVRHI )
|
||||
BlitParameters blitParms;
|
||||
blitParms.sourceTexture = ( nvrhi::ITexture* )globalImages->ldrImage->GetTextureID();
|
||||
blitParms.targetFramebuffer = globalFramebuffers.smaaBlendFBO->GetApiObject();
|
||||
blitParms.targetViewport = nvrhi::Viewport( renderSystem->GetWidth(), renderSystem->GetHeight() );
|
||||
commonPasses.BlitTexture( commandList, blitParms, &bindingCache );
|
||||
|
||||
GL_SelectTexture( 0 );
|
||||
globalImages->smaaBlendImage->Bind();
|
||||
#else
|
||||
globalImages->currentRenderImage->CopyFramebuffer( viewport.x1, viewport.y1, viewport.GetWidth(), viewport.GetHeight() );
|
||||
|
||||
GL_SelectTexture( 0 );
|
||||
globalImages->currentRenderImage->Bind();
|
||||
#endif
|
||||
|
||||
|
||||
globalFramebuffers.ldrFBO->Bind();
|
||||
|
||||
GL_SelectTexture( 1 );
|
||||
globalImages->blueNoiseImage256->Bind();
|
||||
|
@ -7472,6 +7494,20 @@ void idRenderBackend::PostProcess( const void* data )
|
|||
GL_SelectTexture( 0 );
|
||||
renderProgManager.Unbind();
|
||||
|
||||
#if defined( USE_NVRHI )
|
||||
BlitParameters blitParms;
|
||||
blitParms.sourceTexture = ( nvrhi::ITexture* )globalImages->ldrImage->GetTextureID();
|
||||
blitParms.targetFramebuffer = deviceManager->GetCurrentFramebuffer();
|
||||
blitParms.targetViewport = nvrhi::Viewport( renderSystem->GetWidth(), renderSystem->GetHeight() );
|
||||
commonPasses.BlitTexture( commandList, blitParms, &bindingCache );
|
||||
|
||||
GL_SelectTexture( 0 );
|
||||
globalImages->currentRenderImage->Bind();
|
||||
#else
|
||||
globalImages->currentRenderImage->CopyFramebuffer( viewport.x1, viewport.y1, viewport.GetWidth(), viewport.GetHeight() );
|
||||
|
||||
GL_SelectTexture( 0 );
|
||||
globalImages->currentRenderImage->Bind();
|
||||
#endif
|
||||
|
||||
renderLog.CloseBlock();
|
||||
|
|
|
@ -862,7 +862,8 @@ enum bindingLayoutType_t
|
|||
BINDING_LAYOUT_DRAW_INTERACTION,
|
||||
BINDING_LAYOUT_DRAW_INTERACTION_SM,
|
||||
BINDING_LAYOUT_DRAW_FOG,
|
||||
BINDING_LAYOUT_POST_PROCESS_CNM,
|
||||
BINDING_LAYOUT_POST_PROCESS_INGAME,
|
||||
BINDING_LAYOUT_POST_PROCESS_FINAL,
|
||||
BINDING_LAYOUT_NORMAL_CUBE,
|
||||
BINDING_LAYOUT_BLENDLIGHT,
|
||||
|
||||
|
|
|
@ -283,14 +283,30 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device )
|
|||
|
||||
bindingLayouts[BINDING_LAYOUT_DRAW_FOG] = { device->createBindingLayout( fogBindingLayout ), samplerTwoBindingLayout };
|
||||
|
||||
auto ppFxBindingLayout = nvrhi::BindingLayoutDesc()
|
||||
auto blendLightBindingLayout = nvrhi::BindingLayoutDesc()
|
||||
.setVisibility( nvrhi::ShaderType::All )
|
||||
.addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) )
|
||||
.addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ) // light 1
|
||||
.addItem( nvrhi::BindingLayoutItem::Texture_SRV( 1 ) ); // light 2
|
||||
|
||||
bindingLayouts[BINDING_LAYOUT_BLENDLIGHT] = { device->createBindingLayout( blendLightBindingLayout ), samplerOneBindingLayout };
|
||||
|
||||
auto pp3DBindingLayout = nvrhi::BindingLayoutDesc()
|
||||
.setVisibility( nvrhi::ShaderType::All )
|
||||
.addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) )
|
||||
.addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ) // current render
|
||||
.addItem( nvrhi::BindingLayoutItem::Texture_SRV( 1 ) ) // normal map
|
||||
.addItem( nvrhi::BindingLayoutItem::Texture_SRV( 2 ) ); // mask
|
||||
|
||||
bindingLayouts[BINDING_LAYOUT_POST_PROCESS_CNM] = { device->createBindingLayout( ppFxBindingLayout ), samplerOneBindingLayout };
|
||||
bindingLayouts[BINDING_LAYOUT_POST_PROCESS_INGAME] = { device->createBindingLayout( pp3DBindingLayout ), samplerOneBindingLayout };
|
||||
|
||||
auto ppFxBindingLayout = nvrhi::BindingLayoutDesc()
|
||||
.setVisibility( nvrhi::ShaderType::All )
|
||||
.addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) )
|
||||
.addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) )
|
||||
.addItem( nvrhi::BindingLayoutItem::Texture_SRV( 1 ) );
|
||||
|
||||
bindingLayouts[BINDING_LAYOUT_POST_PROCESS_FINAL] = { device->createBindingLayout( ppFxBindingLayout ), samplerTwoBindingLayout };
|
||||
|
||||
auto normalCubeBindingLayout = nvrhi::BindingLayoutDesc()
|
||||
.setVisibility( nvrhi::ShaderType::All )
|
||||
|
@ -300,14 +316,6 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device )
|
|||
|
||||
bindingLayouts[BINDING_LAYOUT_NORMAL_CUBE] = { device->createBindingLayout( normalCubeBindingLayout ), samplerOneBindingLayout };
|
||||
|
||||
auto blendLightBindingLayout = nvrhi::BindingLayoutDesc()
|
||||
.setVisibility( nvrhi::ShaderType::All )
|
||||
.addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) )
|
||||
.addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ) // light 1
|
||||
.addItem( nvrhi::BindingLayoutItem::Texture_SRV( 1 ) ); // light 2
|
||||
|
||||
bindingLayouts[BINDING_LAYOUT_BLENDLIGHT] = { device->createBindingLayout( blendLightBindingLayout ), samplerOneBindingLayout };
|
||||
|
||||
auto motionVectorsBindingLayout = nvrhi::BindingLayoutDesc()
|
||||
.setVisibility( nvrhi::ShaderType::All )
|
||||
.addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) )
|
||||
|
@ -467,7 +475,7 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device )
|
|||
{ BUILTIN_FOG_SKINNED, "builtin/fog/fog", "_skinned", { {"USE_GPU_SKINNING", "1" } }, true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DRAW_FOG },
|
||||
{ BUILTIN_SKYBOX, "builtin/legacy/skybox", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT },
|
||||
{ BUILTIN_WOBBLESKY, "builtin/legacy/wobblesky", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT },
|
||||
{ BUILTIN_POSTPROCESS, "builtin/post/postprocess", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT },
|
||||
{ BUILTIN_POSTPROCESS, "builtin/post/postprocess", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_POST_PROCESS_FINAL },
|
||||
// RB begin
|
||||
{ BUILTIN_SCREEN, "builtin/post/screen", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT },
|
||||
{ BUILTIN_TONEMAP, "builtin/post/tonemap", "", { { "BRIGHTPASS", "0" }, { "HDR_DEBUG", "0"} }, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT },
|
||||
|
|
|
@ -41,7 +41,7 @@ SamplerState samp1 : register(s1 VK_DESCRIPTOR_SET( 1 ) ); // blue noise 256
|
|||
|
||||
struct PS_IN
|
||||
{
|
||||
float4 position : VPOS;
|
||||
float4 position : SV_Position;
|
||||
float2 texcoord0 : TEXCOORD0_centroid;
|
||||
};
|
||||
|
||||
|
|
|
@ -39,18 +39,15 @@ struct VS_IN {
|
|||
};
|
||||
|
||||
struct VS_OUT {
|
||||
float4 position : POSITION;
|
||||
float2 texcoord0 : TEXCOORD0;
|
||||
float4 position : SV_Position;
|
||||
float2 texcoord0 : TEXCOORD0_centroid;
|
||||
};
|
||||
// *INDENT-ON*
|
||||
|
||||
void main( VS_IN vertex, out VS_OUT result )
|
||||
{
|
||||
result.position = vertex.position;
|
||||
result.position.y = -result.position.y;
|
||||
|
||||
//result.position.x = vertex.position; //dot4( vertex.position, rpMVPmatrixX );
|
||||
//result.position.y = dot4( vertex.position, rpMVPmatrixY );
|
||||
//result.position.z = dot4( vertex.position, rpMVPmatrixZ );
|
||||
//result.position.w = dot4( vertex.position, rpMVPmatrixW );
|
||||
result.texcoord0 = vertex.texcoord;
|
||||
}
|
Loading…
Reference in a new issue