Fixed r_ssaoDebug

This commit is contained in:
Robert Beckebans 2020-05-10 12:58:14 +02:00
parent 50eb5b4537
commit d5e8380a5f
6 changed files with 83 additions and 30 deletions

View file

@ -147,7 +147,7 @@ float3 reconstructCSPosition( float2 S, float z )
{
float4 P;
P.z = z * 2.0 - 1.0;
P.xy = ( S * rpScreenCorrectionFactor.xy ) * 2.0 - 1.0;
P.xy = ( S * rpWindowCoord.xy ) * 2.0 - 1.0;
P.w = 1.0;
float4 csP;
@ -335,10 +335,10 @@ void main( PS_IN fragment, out PS_OUT result )
#endif
// Pixel being shaded
//float2 ssC = fragment.texcoord0;
//int2 issC = int2( ssC.x * rpScreenCorrectionFactor.z, ssC.y * rpScreenCorrectionFactor.w );
float2 ssC = fragment.texcoord0 * rpScreenCorrectionFactor.xy;
int2 ssP = int2( ssC.x * rpWindowCoord.z, ssC.y * rpWindowCoord.w );
int2 ssP = int2( gl_FragCoord.xy );
//int2 ssP = int2( gl_FragCoord.xy );
// World space point being shaded
vec3 C = getPosition( ssP, CS_Z_buffer );

View file

@ -129,7 +129,7 @@ float3 reconstructCSPosition( float2 S, float z )
{
float4 P;
P.z = z * 2.0 - 1.0;
P.xy = ( S * rpScreenCorrectionFactor.xy ) * 2.0 - 1.0;
P.xy = ( S * rpWindowCoord.xy ) * 2.0 - 1.0;
P.w = 1.0;
float4 csP;
@ -270,6 +270,9 @@ void main( PS_IN fragment, out PS_OUT result )
int2 ssC = int2( gl_FragCoord.xy );
//float2 ssF = fragment.texcoord0 * rpScreenCorrectionFactor.xy;
//int2 ssC = int2( ssF.x * rpWindowCoord.z, ssF.y * rpWindowCoord.w );
float4 temp = texelFetch( source, ssC, 0 );
#if 0

View file

@ -143,7 +143,7 @@ void main( PS_IN fragment, out PS_OUT result )
// calculate the screen texcoord in the 0.0 to 1.0 range
//float2 screenTexCoord = vposToScreenPosTexCoord( fragment.position.xy );
float2 screenTexCoord = fragment.position.xy * rpScreenCorrectionFactor.xy;
float2 screenTexCoord = fragment.position.xy * rpWindowCoord.xy;
float ao = tex2D( samp4, screenTexCoord ).r;
//diffuseColor.rgb *= ao;

View file

@ -267,6 +267,11 @@ static void R_SMAAImage_ResNative( idImage* image )
image->GenerateImage( NULL, renderSystem->GetWidth(), renderSystem->GetHeight(), TF_LINEAR, TR_CLAMP, TD_LOOKUP_TABLE_RGBA );
}
static void R_SSAOImage_ResHalf( idImage* image )
{
image->GenerateImage( NULL, renderSystem->GetWidth() / 2, renderSystem->GetHeight() / 2, TF_LINEAR, TR_CLAMP, TD_LOOKUP_TABLE_RGBA );
}
static void R_HierarchicalZBufferImage_ResNative( idImage* image )
{
image->GenerateImage( NULL, renderSystem->GetWidth(), renderSystem->GetHeight(), TF_NEAREST_MIPMAP, TR_CLAMP, TD_R32F );

View file

@ -2057,6 +2057,8 @@ idRenderBackend::AmbientPass
*/
void idRenderBackend::AmbientPass( const drawSurf_t* const* drawSurfs, int numDrawSurfs, bool fillGbuffer )
{
const bool hdrIsActive = ( r_useHDR.GetBool() && globalFramebuffers.hdrFBO != NULL && globalFramebuffers.hdrFBO->IsBound() );
if( fillGbuffer )
{
if( !r_useSSGI.GetBool() && !r_useSSAO.GetBool() )
@ -2068,6 +2070,8 @@ void idRenderBackend::AmbientPass( const drawSurf_t* const* drawSurfs, int numDr
{
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;
}
}
@ -2083,18 +2087,42 @@ void idRenderBackend::AmbientPass( const drawSurf_t* const* drawSurfs, int numDr
return;
}
const bool hdrIsActive = ( r_useHDR.GetBool() && globalFramebuffers.hdrFBO != NULL && globalFramebuffers.hdrFBO->IsBound() );
if( !fillGbuffer )
if( !fillGbuffer && r_useSSAO.GetBool() && r_ssaoDebug.GetBool() )
{
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;
}
GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO | GLS_DEPTHMASK | GLS_DEPTHFUNC_ALWAYS );
// We just want to do a quad pass - so make sure we disable any texgen and
// set the texture matrix to the identity so we don't get anomalies from
// any stale uniform data being present from a previous draw call
const float texS[4] = { 1.0f, 0.0f, 0.0f, 0.0f };
const float texT[4] = { 0.0f, 1.0f, 0.0f, 0.0f };
renderProgManager.SetRenderParm( RENDERPARM_TEXTUREMATRIX_S, texS );
renderProgManager.SetRenderParm( RENDERPARM_TEXTUREMATRIX_T, texT );
// disable any texgen
const float texGenEnabled[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
renderProgManager.SetRenderParm( RENDERPARM_TEXGEN_0_ENABLED, texGenEnabled );
currentSpace = NULL;
RB_SetMVP( renderMatrix_identity );
renderProgManager.BindShader_Texture();
GL_Color( 1, 1, 1, 1 );
GL_SelectTexture( 0 );
globalImages->ambientOcclusionImage[0]->Bind();
DrawElementsWithCounters( &unitSquareSurface );
renderProgManager.Unbind();
GL_State( GLS_DEFAULT );
SetFragmentParm( RENDERPARM_ALPHA_TEST, vec4_zero.ToFloatPtr() );
return;
}
/*
if( fillGbuffer )
{
@ -4877,8 +4905,11 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef
}
// set the window clipping
GL_Viewport( 0, 0, screenWidth, screenHeight );
GL_Scissor( 0, 0, screenWidth, screenHeight );
int aoScreenWidth = globalFramebuffers.ambientOcclusionFBO[0]->GetWidth();
int aoScreenHeight = globalFramebuffers.ambientOcclusionFBO[0]->GetHeight();
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 );
@ -4930,12 +4961,20 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef
}
float screenCorrectionParm[4];
screenCorrectionParm[0] = 1.0f / screenWidth;
screenCorrectionParm[1] = 1.0f / screenHeight;
screenCorrectionParm[2] = screenWidth;
screenCorrectionParm[3] = screenHeight;
screenCorrectionParm[0] = float( screenWidth ) / aoScreenWidth;
screenCorrectionParm[1] = float( screenHeight ) / aoScreenHeight;
screenCorrectionParm[2] = 0.0f;
screenCorrectionParm[3] = 1.0f;
SetFragmentParm( RENDERPARM_SCREENCORRECTIONFACTOR, screenCorrectionParm ); // rpScreenCorrectionFactor
// window coord to 0.0 to 1.0 conversion
float windowCoordParm[4];
windowCoordParm[0] = 1.0f / aoScreenWidth;
windowCoordParm[1] = 1.0f / aoScreenHeight;
windowCoordParm[2] = aoScreenWidth;
windowCoordParm[3] = aoScreenHeight;
SetFragmentParm( RENDERPARM_WINDOWCOORD, windowCoordParm ); // rpWindowCoord
#if 0
// RB: set unprojection matrices so we can convert zbuffer values back to camera and world spaces
idRenderMatrix modelViewMatrix;
@ -4951,7 +4990,6 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef
#endif
SetVertexParms( RENDERPARM_MODELMATRIX_X, viewDef->unprojectionToCameraRenderMatrix[0], 4 );
float jitterTexOffset[4];
if( r_shadowMapRandomizeJitter.GetBool() )
{
@ -4987,7 +5025,6 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef
float jitterTexScale[4];
// AO blur X
#if 1
globalFramebuffers.ambientOcclusionFBO[1]->Bind();
renderProgManager.BindShader_AmbientOcclusionBlur();
@ -5003,7 +5040,6 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef
globalImages->ambientOcclusionImage[0]->Bind();
DrawElementsWithCounters( &unitSquareSurface );
#endif
// AO blur Y
if( downModulateScreen )
@ -5055,8 +5091,14 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef
}
}
//
// reset state
//
renderProgManager.Unbind();
GL_Viewport( 0, 0, screenWidth, screenHeight );
GL_Scissor( 0, 0, screenWidth, screenHeight );
GL_State( GLS_DEFAULT );
renderLog.CloseBlock();

View file

@ -2455,7 +2455,7 @@ static const cgShaderDef_t cg_renderprogs[] =
"\n"
" // calculate the screen texcoord in the 0.0 to 1.0 range\n"
" //float2 screenTexCoord = vposToScreenPosTexCoord( fragment.position.xy );\n"
" float2 screenTexCoord = fragment.position.xy * rpScreenCorrectionFactor.xy;\n"
" float2 screenTexCoord = fragment.position.xy * rpWindowCoord.xy;\n"
"\n"
" float ao = tex2D( samp4, screenTexCoord ).r;\n"
" //diffuseColor.rgb *= ao;\n"
@ -2851,7 +2851,7 @@ static const cgShaderDef_t cg_renderprogs[] =
"{\n"
" float4 P;\n"
" P.z = z * 2.0 - 1.0;\n"
" P.xy = ( S * rpScreenCorrectionFactor.xy ) * 2.0 - 1.0;\n"
" P.xy = ( S * rpWindowCoord.xy ) * 2.0 - 1.0;\n"
" P.w = 1.0;\n"
"\n"
" float4 csP;\n"
@ -3039,10 +3039,10 @@ static const cgShaderDef_t cg_renderprogs[] =
"#endif\n"
"\n"
" // Pixel being shaded\n"
" //float2 ssC = fragment.texcoord0;\n"
" //int2 issC = int2( ssC.x * rpScreenCorrectionFactor.z, ssC.y * rpScreenCorrectionFactor.w );\n"
" float2 ssC = fragment.texcoord0 * rpScreenCorrectionFactor.xy;\n"
" int2 ssP = int2( ssC.x * rpWindowCoord.z, ssC.y * rpWindowCoord.w );\n"
"\n"
" int2 ssP = int2( gl_FragCoord.xy );\n"
" //int2 ssP = int2( gl_FragCoord.xy );\n"
"\n"
" // World space point being shaded\n"
" vec3 C = getPosition( ssP, CS_Z_buffer );\n"
@ -3342,7 +3342,7 @@ static const cgShaderDef_t cg_renderprogs[] =
"{\n"
" float4 P;\n"
" P.z = z * 2.0 - 1.0;\n"
" P.xy = ( S * rpScreenCorrectionFactor.xy ) * 2.0 - 1.0;\n"
" P.xy = ( S * rpWindowCoord.xy ) * 2.0 - 1.0;\n"
" P.w = 1.0;\n"
"\n"
" float4 csP;\n"
@ -3483,6 +3483,9 @@ static const cgShaderDef_t cg_renderprogs[] =
"\n"
" int2 ssC = int2( gl_FragCoord.xy );\n"
"\n"
" //float2 ssF = fragment.texcoord0 * rpScreenCorrectionFactor.xy;\n"
" //int2 ssC = int2( ssF.x * rpWindowCoord.z, ssF.y * rpWindowCoord.w );\n"
"\n"
" float4 temp = texelFetch( source, ssC, 0 );\n"
"\n"
"#if 0\n"