SMAA step one

This commit is contained in:
Robert Beckebans 2015-12-26 16:11:47 +01:00
parent 65589354c5
commit e332dd07d6
13 changed files with 412 additions and 6 deletions

View file

@ -0,0 +1,58 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2015 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "renderprogs/global.inc"
//#include "renderprogs/SMAA.inc"
// *INDENT-OFF*
uniform sampler2D samp0 : register(s0);
uniform sampler2D samp1 : register(s1);
struct PS_IN
{
float4 position : VPOS;
float2 texcoord0 : TEXCOORD0_centroid;
};
struct PS_OUT
{
float4 color : COLOR;
};
// *INDENT-ON*
void main( PS_IN fragment, out PS_OUT result )
{
float2 tCoords = fragment.texcoord0;
// base color with tone mapping and other post processing applied
float4 color = tex2D( samp0, tCoords );
result.color = color;
}

View file

@ -0,0 +1,52 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "renderprogs/global.inc"
struct VS_IN {
float4 position : POSITION;
float2 texcoord : TEXCOORD0;
float4 normal : NORMAL;
float4 tangent : TANGENT;
float4 color : COLOR0;
};
struct VS_OUT {
float4 position : POSITION;
float2 texcoord0 : TEXCOORD0;
};
void main( VS_IN vertex, out VS_OUT result ) {
result.position = vertex.position;
//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;
}

View file

@ -0,0 +1,58 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2015 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "renderprogs/global.inc"
//#include "renderprogs/SMAA.inc"
// *INDENT-OFF*
uniform sampler2D samp0 : register(s0);
uniform sampler2D samp1 : register(s1);
struct PS_IN
{
float4 position : VPOS;
float2 texcoord0 : TEXCOORD0_centroid;
};
struct PS_OUT
{
float4 color : COLOR;
};
// *INDENT-ON*
void main( PS_IN fragment, out PS_OUT result )
{
float2 tCoords = fragment.texcoord0;
// base color with tone mapping and other post processing applied
float4 color = tex2D( samp0, tCoords );
result.color = color;
}

View file

@ -0,0 +1,52 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "renderprogs/global.inc"
struct VS_IN {
float4 position : POSITION;
float2 texcoord : TEXCOORD0;
float4 normal : NORMAL;
float4 tangent : TANGENT;
float4 color : COLOR0;
};
struct VS_OUT {
float4 position : POSITION;
float2 texcoord0 : TEXCOORD0;
};
void main( VS_IN vertex, out VS_OUT result ) {
result.position = vertex.position;
//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;
}

View file

@ -0,0 +1,58 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2015 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "renderprogs/global.inc"
//#include "renderprogs/SMAA.inc"
// *INDENT-OFF*
uniform sampler2D samp0 : register(s0);
uniform sampler2D samp1 : register(s1);
struct PS_IN
{
float4 position : VPOS;
float2 texcoord0 : TEXCOORD0_centroid;
};
struct PS_OUT
{
float4 color : COLOR;
};
// *INDENT-ON*
void main( PS_IN fragment, out PS_OUT result )
{
float2 tCoords = fragment.texcoord0;
// base color with tone mapping and other post processing applied
float4 color = tex2D( samp0, tCoords );
result.color = color;
}

View file

@ -0,0 +1,52 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "renderprogs/global.inc"
struct VS_IN {
float4 position : POSITION;
float2 texcoord : TEXCOORD0;
float4 normal : NORMAL;
float4 tangent : TANGENT;
float4 color : COLOR0;
};
struct VS_OUT {
float4 position : POSITION;
float2 texcoord0 : TEXCOORD0;
};
void main( VS_IN vertex, out VS_OUT result ) {
result.position = vertex.position;
//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;
}

View file

@ -2,7 +2,7 @@
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 2014 Robert Beckebans
Copyright (C) 2014-2015 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -150,6 +150,21 @@ void Framebuffer::Init()
globalFramebuffers.bloomRenderFBO[i]->Check();
}
// SMSAA
/*
globalFramebuffers.smaaEdgesFBO = new Framebuffer( "_smaaEdges", glConfig.nativeScreenWidth, glConfig.nativeScreenHeight );
globalFramebuffers.smaaEdgesFBO->Bind();
globalFramebuffers.smaaEdgesFBO->AddColorBuffer( GL_RGBA8, 0 );
globalFramebuffers.smaaEdgesFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->smaaEdgesImage, 0 );
globalFramebuffers.smaaEdgesFBO->Check();
globalFramebuffers.smaaBlendFBO = new Framebuffer( "_smaaBlend", glConfig.nativeScreenWidth, glConfig.nativeScreenHeight );
globalFramebuffers.smaaBlendFBO->Bind();
globalFramebuffers.smaaBlendFBO->AddColorBuffer( GL_RGBA8, 0 );
globalFramebuffers.smaaBlendFBO->AttachImage2D( GL_TEXTURE_2D, globalImages->smaaBlendImage, 0 );
globalFramebuffers.smaaBlendFBO->Check();
*/
Unbind();
}

View file

@ -2,7 +2,7 @@
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 2014 Robert Beckebans
Copyright (C) 2014-2015 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -125,6 +125,8 @@ struct globalFramebuffers_t
// Framebuffer* hdrQuarterFBO;
Framebuffer* hdr64FBO;
Framebuffer* bloomRenderFBO[MAX_BLOOM_BUFFERS];
// Framebuffer* smaaEdgesFBO;
// Framebuffer* smaaBlendFBO;
};
extern globalFramebuffers_t globalFramebuffers;

View file

@ -360,6 +360,8 @@ public:
idImage* heatmap7Image;
idImage* smaaAreaImage;
idImage* smaaSearchImage;
idImage* smaaEdgesImage;
idImage* smaaBlendImage;
// RB end
idImage* scratchImage;
idImage* scratchImage2;

View file

@ -181,6 +181,11 @@ static void R_HDR_RGBA16FImage_Res64( idImage* image )
{
image->GenerateImage( NULL, 64, 64, TF_NEAREST, TR_CLAMP, TD_RGBA16F );
}
static void R_SMAAImage_ResNative( idImage* image )
{
image->GenerateImage( NULL, glConfig.nativeScreenWidth, glConfig.nativeScreenHeight, TF_NEAREST, TR_CLAMP, TD_LOOKUP_TABLE_RGBA );
}
// RB end
static void R_AlphaNotchImage( idImage* image )
@ -744,7 +749,7 @@ static void R_CreateSMAAAreaImage( idImage* image )
}
}
image->GenerateImage( ( byte* )data, AREATEX_WIDTH, AREATEX_HEIGHT, TF_NEAREST, TR_REPEAT, TD_LOOKUP_TABLE_RGBA );
image->GenerateImage( ( byte* )data, AREATEX_WIDTH, AREATEX_HEIGHT, TF_LINEAR, TR_CLAMP, TD_LOOKUP_TABLE_RGBA );
}
static void R_CreateSMAASearchImage( idImage* image )
@ -764,7 +769,7 @@ static void R_CreateSMAASearchImage( idImage* image )
}
}
image->GenerateImage( ( byte* )data, SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT, TF_NEAREST, TR_REPEAT, TD_LOOKUP_TABLE_MONO );
image->GenerateImage( ( byte* )data, SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT, TF_LINEAR, TR_CLAMP, TD_LOOKUP_TABLE_MONO );
}
// RB end
@ -812,8 +817,12 @@ void idImageManager::CreateIntrinsicImages()
heatmap7Image = ImageFromFunction( "_heatmap7", R_CreateHeatmap7ColorsImage );
grainImage1 = globalImages->ImageFromFunction( "_grain1", R_CreateGrainImage1 );
smaaAreaImage = globalImages->ImageFromFunction( "_smaaArea", R_CreateSMAAAreaImage );
smaaSearchImage = globalImages->ImageFromFunction( "_smaaSearch", R_CreateSMAASearchImage );
smaaEdgesImage = globalImages->ImageFromFunction( "_smaaEdges", R_SMAAImage_ResNative );
smaaBlendImage = globalImages->ImageFromFunction( "_smaaBlend", R_SMAAImage_ResNative );
// RB end
// scratchImage is used for screen wipes/doublevision etc..

View file

@ -141,6 +141,10 @@ void idRenderProgManager::Init()
{ BUILTIN_BRIGHTPASS, "tonemap", "_brightpass", BIT( BRIGHTPASS ), false },
{ BUILTIN_HDR_GLARE_CHROMATIC, "hdr_glare_chromatic", "", 0, false },
{ BUILTIN_HDR_DEBUG, "tonemap", "_debug", BIT( HDR_DEBUG ), false },
{ BUILTIN_SMAA_EDGE_DETECTION, "SMAA_edge_detection", "", 0, false },
{ BUILTIN_SMAA_BLENDING_WEIGHT_CALCULATION, "SMAA_blending_weight_calc", "", 0, false },
{ BUILTIN_SMAA_NEIGHBORHOOD_BLENDING, "SMAA_final", "", 0, false },
// RB end
{ BUILTIN_STEREO_DEGHOST, "stereoDeGhost.vfp", 0, false },
{ BUILTIN_STEREO_WARP, "stereoWarp.vfp", 0, false },

View file

@ -428,6 +428,21 @@ public:
BindShader_Builtin( BUILTIN_HDR_DEBUG );
}
void BindShader_SMAA_EdgeDetection()
{
BindShader_Builtin( BUILTIN_SMAA_EDGE_DETECTION );
}
void BindShader_SMAA_BlendingWeightCalculation()
{
BindShader_Builtin( BUILTIN_SMAA_BLENDING_WEIGHT_CALCULATION );
}
void BindShader_SMAA_NeighborhoodBlending()
{
BindShader_Builtin( BUILTIN_SMAA_NEIGHBORHOOD_BLENDING );
}
#if 0
void BindShader_ZCullReconstruct()
{
@ -544,6 +559,10 @@ protected:
BUILTIN_BRIGHTPASS,
BUILTIN_HDR_GLARE_CHROMATIC,
BUILTIN_HDR_DEBUG,
BUILTIN_SMAA_EDGE_DETECTION,
BUILTIN_SMAA_BLENDING_WEIGHT_CALCULATION,
BUILTIN_SMAA_NEIGHBORHOOD_BLENDING,
// RB end
BUILTIN_STEREO_DEGHOST,
BUILTIN_STEREO_WARP,

View file

@ -3,7 +3,7 @@
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2013-2014 Robert Beckebans
Copyright (C) 2013-2015 Robert Beckebans
Copyright (C) 2014 Carl Kenner
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -4944,7 +4944,7 @@ void RB_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_useFilmicPostProcessEffects.GetBool() )
if( rs_enable.GetInteger() == 0 && !r_useFilmicPostProcessEffects.GetBool() ) //&& !r_useSMAA.GetInteger() )
{
return;
}
@ -4969,6 +4969,31 @@ void RB_PostProcess( const void* data )
GL_SelectTexture( 0 );
globalImages->currentRenderImage->Bind();
// SMAA
{
/*
* The shader has three passes, chained together as follows:
*
* |input|------------------·
* v |
* [ SMAA*EdgeDetection ] |
* v |
* |edgesTex| |
* v |
* [ SMAABlendingWeightCalculation ] |
* v |
* |blendTex| |
* v |
* [ SMAANeighborhoodBlending ] <------·
* v
* |output|
*/
renderProgManager.BindShader_SMAA_EdgeDetection();
RB_DrawElementsWithCounters( &backEnd.unitSquareSurface );
}
GL_SelectTexture( 1 );
globalImages->grainImage1->Bind();