mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-15 07:00:58 +00:00
Fixed blending of multilayered normals
This commit is contained in:
parent
7b87863a50
commit
8c3179f313
2 changed files with 64 additions and 121 deletions
|
@ -2057,23 +2057,6 @@ void idRenderBackend::AmbientPass( const drawSurf_t* const* drawSurfs, int numDr
|
|||
{
|
||||
const bool hdrIsActive = ( r_useHDR.GetBool() && globalFramebuffers.hdrFBO != NULL && globalFramebuffers.hdrFBO->IsBound() );
|
||||
|
||||
if( fillGbuffer )
|
||||
{
|
||||
if( !r_useSSGI.GetBool() && !r_useSSAO.GetBool() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( r_forceAmbient.GetFloat() <= 0 )//|| r_skipAmbient.GetBool() )
|
||||
{
|
||||
// clear gbuffer
|
||||
GL_Clear( true, false, false, 0, 0.0f, 0.0f, 0.0f, 1.0f, false );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if( numDrawSurfs == 0 )
|
||||
{
|
||||
return;
|
||||
|
@ -2085,6 +2068,12 @@ void idRenderBackend::AmbientPass( const drawSurf_t* const* drawSurfs, int numDr
|
|||
return;
|
||||
}
|
||||
|
||||
if( !fillGbuffer )
|
||||
{
|
||||
// clear gbuffer
|
||||
GL_Clear( true, false, false, 0, 0.0f, 0.0f, 0.0f, 1.0f, false );
|
||||
}
|
||||
|
||||
if( !fillGbuffer && r_useSSAO.GetBool() && r_ssaoDebug.GetBool() )
|
||||
{
|
||||
GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO | GLS_DEPTHMASK | GLS_DEPTHFUNC_ALWAYS );
|
||||
|
@ -2142,16 +2131,10 @@ void idRenderBackend::AmbientPass( const drawSurf_t* const* drawSurfs, int numDr
|
|||
|
||||
// draw all the subview surfaces, which will already be at the start of the sorted list,
|
||||
// with the general purpose path
|
||||
//GL_State( GLS_DEFAULT );
|
||||
GL_State( GLS_DEFAULT );
|
||||
|
||||
//if( fillGbuffer )
|
||||
{
|
||||
GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO | GLS_DEPTHMASK | GLS_DEPTHFUNC_EQUAL );
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE | GLS_DEPTHMASK | GLS_DEPTHFUNC_EQUAL );
|
||||
//}
|
||||
// RB: even use additive blending to blend the normals
|
||||
GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE | GLS_DEPTHMASK | GLS_DEPTHFUNC_EQUAL );
|
||||
|
||||
GL_Color( colorWhite );
|
||||
|
||||
|
@ -2465,11 +2448,10 @@ void idRenderBackend::AmbientPass( const drawSurf_t* const* drawSurfs, int numDr
|
|||
renderLog.CloseBlock();
|
||||
}
|
||||
|
||||
// disable blending
|
||||
GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO | GLS_DEPTHMASK | GLS_DEPTHFUNC_EQUAL );
|
||||
SetFragmentParm( RENDERPARM_ALPHA_TEST, vec4_zero.ToFloatPtr() );
|
||||
|
||||
renderLog.CloseBlock();
|
||||
renderLog.CloseMainBlock();
|
||||
|
||||
GL_SelectTexture( 0 );
|
||||
|
||||
if( fillGbuffer )
|
||||
|
@ -2494,6 +2476,9 @@ void idRenderBackend::AmbientPass( const drawSurf_t* const* drawSurfs, int numDr
|
|||
}
|
||||
|
||||
renderProgManager.Unbind();
|
||||
|
||||
renderLog.CloseBlock();
|
||||
renderLog.CloseMainBlock();
|
||||
}
|
||||
|
||||
// RB end
|
||||
|
@ -4761,81 +4746,6 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef
|
|||
renderLog.OpenMainBlock( MRB_SSAO_PASS );
|
||||
renderLog.OpenBlock( "Render_SSAO", colorBlue );
|
||||
|
||||
#if 0
|
||||
GL_CheckErrors();
|
||||
|
||||
// clear the alpha buffer and draw only the hands + weapon into it so
|
||||
// we can avoid blurring them
|
||||
glClearColor( 0, 0, 0, 1 );
|
||||
GL_State( GLS_COLORMASK | GLS_DEPTHMASK );
|
||||
glClear( GL_COLOR_BUFFER_BIT );
|
||||
GL_Color( 0, 0, 0, 0 );
|
||||
|
||||
|
||||
GL_SelectTexture( 0 );
|
||||
globalImages->blackImage->Bind();
|
||||
backEnd.currentSpace = NULL;
|
||||
|
||||
drawSurf_t** drawSurfs = ( drawSurf_t** )&backEnd.viewDef->drawSurfs[0];
|
||||
for( int surfNum = 0; surfNum < backEnd.viewDef->numDrawSurfs; surfNum++ )
|
||||
{
|
||||
const drawSurf_t* surf = drawSurfs[ surfNum ];
|
||||
|
||||
if( !surf->space->weaponDepthHack && !surf->space->skipMotionBlur && !surf->material->HasSubview() )
|
||||
{
|
||||
// Apply motion blur to this object
|
||||
continue;
|
||||
}
|
||||
|
||||
const idMaterial* shader = surf->material;
|
||||
if( shader->Coverage() == MC_TRANSLUCENT )
|
||||
{
|
||||
// muzzle flash, etc
|
||||
continue;
|
||||
}
|
||||
|
||||
// set mvp matrix
|
||||
if( surf->space != backEnd.currentSpace )
|
||||
{
|
||||
RB_SetMVP( surf->space->mvp );
|
||||
backEnd.currentSpace = surf->space;
|
||||
}
|
||||
|
||||
// this could just be a color, but we don't have a skinned color-only prog
|
||||
if( surf->jointCache )
|
||||
{
|
||||
renderProgManager.BindShader_TextureVertexColorSkinned();
|
||||
}
|
||||
else
|
||||
{
|
||||
renderProgManager.BindShader_TextureVertexColor();
|
||||
}
|
||||
|
||||
// draw it solid
|
||||
RB_DrawElementsWithCounters( surf );
|
||||
}
|
||||
GL_State( GLS_DEPTHFUNC_ALWAYS );
|
||||
|
||||
// copy off the color buffer and the depth buffer for the motion blur prog
|
||||
// we use the viewport dimensions for copying the buffers in case resolution scaling is enabled.
|
||||
const idScreenRect& viewport = backEnd.viewDef->viewport;
|
||||
globalImages->currentRenderImage->CopyFramebuffer( viewport.x1, viewport.y1, viewport.GetWidth(), viewport.GetHeight() );
|
||||
|
||||
// in stereo rendering, each eye needs to get a separate previous frame mvp
|
||||
int mvpIndex = ( backEnd.viewDef->renderView.viewEyeBuffer == 1 ) ? 1 : 0;
|
||||
|
||||
// derive the matrix to go from current pixels to previous frame pixels
|
||||
idRenderMatrix inverseMVP;
|
||||
idRenderMatrix::Inverse( backEnd.viewDef->worldSpace.mvp, inverseMVP );
|
||||
|
||||
idRenderMatrix motionMatrix;
|
||||
idRenderMatrix::Multiply( backEnd.prevMVP[mvpIndex], inverseMVP, motionMatrix );
|
||||
|
||||
backEnd.prevMVP[mvpIndex] = backEnd.viewDef->worldSpace.mvp;
|
||||
|
||||
RB_SetMVP( motionMatrix );
|
||||
#endif
|
||||
|
||||
currentSpace = &viewDef->worldSpace;
|
||||
RB_SetMVP( viewDef->worldSpace.mvp );
|
||||
|
||||
|
@ -4851,7 +4761,7 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef
|
|||
|
||||
renderProgManager.BindShader_AmbientOcclusionMinify();
|
||||
|
||||
glClearColor( 0, 0, 0, 1 );
|
||||
GL_Color( 0, 0, 0, 1 );
|
||||
|
||||
GL_SelectTexture( 0 );
|
||||
//globalImages->currentDepthImage->Bind();
|
||||
|
@ -4861,10 +4771,12 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef
|
|||
int width = globalFramebuffers.csDepthFBO[i]->GetWidth();
|
||||
int height = globalFramebuffers.csDepthFBO[i]->GetHeight();
|
||||
|
||||
globalFramebuffers.csDepthFBO[i]->Bind();
|
||||
|
||||
GL_Viewport( 0, 0, width, height );
|
||||
GL_Scissor( 0, 0, width, height );
|
||||
|
||||
globalFramebuffers.csDepthFBO[i]->Bind();
|
||||
GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO | GLS_DEPTHMASK | GLS_DEPTHFUNC_ALWAYS | GLS_CULL_TWOSIDED );
|
||||
|
||||
glClear( GL_COLOR_BUFFER_BIT );
|
||||
|
||||
|
@ -4909,7 +4821,7 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef
|
|||
GL_Viewport( 0, 0, aoScreenWidth, aoScreenHeight );
|
||||
GL_Scissor( 0, 0, aoScreenWidth, aoScreenHeight );
|
||||
|
||||
GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO | GLS_DEPTHMASK | GLS_DEPTHFUNC_ALWAYS | GLS_CULL_TWOSIDED );
|
||||
|
||||
|
||||
if( downModulateScreen )
|
||||
{
|
||||
|
@ -4945,6 +4857,8 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef
|
|||
{
|
||||
globalFramebuffers.ambientOcclusionFBO[0]->Bind();
|
||||
|
||||
GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO | GLS_DEPTHMASK | GLS_DEPTHFUNC_ALWAYS | GLS_CULL_TWOSIDED );
|
||||
|
||||
glClearColor( 0, 0, 0, 0 );
|
||||
glClear( GL_COLOR_BUFFER_BIT );
|
||||
|
||||
|
|
|
@ -4267,7 +4267,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"\n"
|
||||
"void main( PS_IN fragment, out PS_OUT result )\n"
|
||||
"{\n"
|
||||
" result.color = idtex2Dproj( samp0, fragment.texcoord0 ) * tex2D( samp1, fragment.texcoord1 ) * rpColor;\n"
|
||||
" result.color = sRGBAToLinearRGBA( idtex2Dproj( samp0, fragment.texcoord0 ) * tex2D( samp1, fragment.texcoord1 ) * rpColor );\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
|
||||
|
@ -7498,7 +7498,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"\n"
|
||||
"void main( PS_IN fragment, out PS_OUT result )\n"
|
||||
"{\n"
|
||||
" result.color = tex2D( samp0, fragment.texcoord0 ) * tex2D( samp1, fragment.texcoord1 ) * sRGBAToLinearRGBA( rpColor );\n"
|
||||
" result.color = sRGBAToLinearRGBA( tex2D( samp0, fragment.texcoord0 ) * tex2D( samp1, fragment.texcoord1 ) * rpColor );\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
|
@ -10235,7 +10235,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" float shadow = 0.0;\n"
|
||||
"\n"
|
||||
" // RB: casting a float to int and using it as index can really kill the performance ...\n"
|
||||
" float numSamples = 12.0;\n"
|
||||
" float numSamples = 6.0;\n"
|
||||
" float stepSize = 1.0 / numSamples;\n"
|
||||
"\n"
|
||||
" float random = BlueNoise( fragment.position.xy, 1.0 );\n"
|
||||
|
@ -10248,7 +10248,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" rot.y = sin( random );\n"
|
||||
"\n"
|
||||
" float shadowTexelSize = rpScreenCorrectionFactor.z * rpJitterTexScale.x;\n"
|
||||
" for( int i = 0; i < 12; i++ )\n"
|
||||
" for( int i = 0; i < 6; i++ )\n"
|
||||
" {\n"
|
||||
" float2 jitter = poissonDisk[i];\n"
|
||||
" float2 jitterRotated;\n"
|
||||
|
@ -10262,6 +10262,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"\n"
|
||||
" shadow *= stepSize;\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"#else\n"
|
||||
"\n"
|
||||
" // Vogel Disk Sampling\n"
|
||||
|
@ -10825,7 +10826,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"};\n"
|
||||
"// *INDENT-ON*\n"
|
||||
"\n"
|
||||
"#define USE_CHROMATIC_ABERRATION 1\n"
|
||||
"#define USE_CHROMATIC_ABERRATION 0\n"
|
||||
"#define Chromatic_Amount 0.075\n"
|
||||
"\n"
|
||||
"#define USE_TECHNICOLOR 0 // [0 or 1]\n"
|
||||
|
@ -10953,10 +10954,37 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" sumColor += so * tex2D( samp0, BarrelDistortion( fragment.texcoord0, ( 0.5 * amount * t ) ) ).rgb;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" color.rgb = ( sumColor / sum );\n"
|
||||
" //color.rgb = lerp(color.rgb, (sumColor / sum), Technicolor_Amount);\n"
|
||||
" float3 outColor = ( sumColor / sum );\n"
|
||||
" color.rgb = lerp( color.rgb, outColor, Technicolor_Amount );\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"void ChromaticAberrationPass2( inout float4 color )\n"
|
||||
"{\n"
|
||||
" float amount = 6.0;\n"
|
||||
"\n"
|
||||
" float2 uv = fragment.texcoord0;\n"
|
||||
"\n"
|
||||
" //float2 texel = 1.0 / rpWindowCoord.zw;\n"
|
||||
" float2 texel = 1.0 / float2( 1920.0, 1080.0 );\n"
|
||||
"\n"
|
||||
" float2 coords = ( uv - 0.5 ) * 2.0;\n"
|
||||
" float coordDot = dot( coords, coords );\n"
|
||||
"\n"
|
||||
" float2 precompute = amount * coordDot * coords;\n"
|
||||
" float2 uvR = uv - texel.xy * precompute;\n"
|
||||
" float2 uvB = uv + texel.xy * precompute;\n"
|
||||
"\n"
|
||||
" float3 outColor;\n"
|
||||
" outColor.r = tex2D( samp0, uvR ).r;\n"
|
||||
" outColor.g = tex2D( samp0, uv ).g;\n"
|
||||
" outColor.b = tex2D( samp0, uvB ).b;\n"
|
||||
"\n"
|
||||
" color.rgb = lerp( color.rgb, outColor, Technicolor_Amount );\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"// https://gpuopen.com/vdr-follow-up-fine-art-of-film-grain/\n"
|
||||
|
@ -11257,7 +11285,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" return 1.0 / v;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"void ContrastAdaptiveSharpeningPass( inout float4 fragColor )\n"
|
||||
"void ContrastAdaptiveSharpeningPass( inout float4 color )\n"
|
||||
"{\n"
|
||||
" float2 texcoord = fragment.texcoord0;\n"
|
||||
" float Sharpness = 1;\n"
|
||||
|
@ -11339,7 +11367,8 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" saturate( ( b.g * wG + d.g * wG + f.g * wG + h.g * wG + e.g ) * rcpWeightG ),\n"
|
||||
" saturate( ( b.b * wB + d.b * wB + f.b * wB + h.b * wB + e.b ) * rcpWeightB ) );\n"
|
||||
"\n"
|
||||
" fragColor.rgb = outColor;\n"
|
||||
" color.rgb = outColor;\n"
|
||||
" //color.rgb = lerp( color.rgb, outColor, Technicolor_Amount );\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"void main( PS_IN fragment, out PS_OUT result )\n"
|
||||
|
@ -11349,8 +11378,12 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" // base color with tone mapping and other post processing applied\n"
|
||||
" float4 color = tex2D( samp0, tCoords );\n"
|
||||
"\n"
|
||||
"#if USE_CAS\n"
|
||||
" ContrastAdaptiveSharpeningPass( color );\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"#if USE_CHROMATIC_ABERRATION\n"
|
||||
" ChromaticAberrationPass( color );\n"
|
||||
" ChromaticAberrationPass2( color );\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"#if USE_TECHNICOLOR\n"
|
||||
|
@ -11361,10 +11394,6 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" VibrancePass( color );\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"#if USE_CAS\n"
|
||||
" ContrastAdaptiveSharpeningPass( color );\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"#if USE_DITHERING\n"
|
||||
" DitheringPass( color );\n"
|
||||
"#endif\n"
|
||||
|
|
Loading…
Reference in a new issue