SMAA blending weight calculation shader

This commit is contained in:
Robert Beckebans 2015-12-28 11:42:11 +01:00
parent 43b0cb2415
commit 794f9ae5e1
5 changed files with 80 additions and 24 deletions

View file

@ -28,16 +28,24 @@ If you have questions concerning this license or the applicable additional terms
*/
#include "renderprogs/global.inc"
//#include "renderprogs/SMAA.inc"
#define SMAA_INCLUDE_VS 0
#define SMAA_INCLUDE_PS 1
#include "renderprogs/SMAA.inc"
// *INDENT-OFF*
uniform sampler2D samp0 : register(s0);
uniform sampler2D samp1 : register(s1);
uniform sampler2D samp0 : register(s0); // _smaaEdges
uniform sampler2D samp1 : register(s1); // _smaaArea
uniform sampler2D samp2 : register(s2); // _smaaSearch
struct PS_IN
{
float4 position : VPOS;
float2 texcoord0 : TEXCOORD0_centroid;
float4 texcoord1 : TEXCOORD1_centroid;
float4 texcoord2 : TEXCOORD2_centroid;
float4 texcoord3 : TEXCOORD3_centroid;
float4 texcoord4 : TEXCOORD4_centroid;
};
struct PS_OUT
@ -49,12 +57,25 @@ struct PS_OUT
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 );
float2 texcoord = fragment.texcoord0;
float4 offset[3];
offset[0] = fragment.texcoord1;
offset[1] = fragment.texcoord2;
offset[2] = fragment.texcoord3;
float2 pixcoord = fragment.texcoord4.st;
// TODO
float4 subsampleIndices = float4( 0.0 );
float4 color = SMAABlendingWeightCalculationPS( texcoord,
pixcoord,
offset,
samp0,
samp1,
samp2,
subsampleIndices );
result.color = color;
}

View file

@ -3,6 +3,7 @@
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").
@ -28,7 +29,12 @@ If you have questions concerning this license or the applicable additional terms
#include "renderprogs/global.inc"
struct VS_IN {
#define SMAA_INCLUDE_VS 1
#define SMAA_INCLUDE_PS 0
#include "renderprogs/SMAA.inc"
struct VS_IN
{
float4 position : POSITION;
float2 texcoord : TEXCOORD0;
float4 normal : NORMAL;
@ -36,17 +42,29 @@ struct VS_IN {
float4 color : COLOR0;
};
struct VS_OUT {
struct VS_OUT
{
float4 position : POSITION;
float2 texcoord0 : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
float4 texcoord2 : TEXCOORD2;
float4 texcoord3 : TEXCOORD3;
float4 texcoord4 : TEXCOORD4;
};
void main( VS_IN vertex, out VS_OUT result ) {
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;
float4 offset[3];
float2 pixcoord;
SMAABlendingWeightCalculationVS( vertex.texcoord, pixcoord, offset );
result.texcoord1 = offset[0];
result.texcoord2 = offset[1];
result.texcoord3 = offset[2];
result.texcoord4.st = pixcoord;
}

View file

@ -57,10 +57,6 @@ 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 );
//color.rgb *= 1.0;
float4 offset[3];
offset[0] = fragment.texcoord1;
offset[1] = fragment.texcoord2;

View file

@ -55,10 +55,6 @@ 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;
float4 offset[3];

View file

@ -4989,8 +4989,6 @@ void RB_PostProcess( const void* data )
* |output|
*/
renderProgManager.BindShader_SMAA_EdgeDetection();
// set SMAA_RT_METRICS = rpScreenCorrectionFactor
float screenCorrectionParm[4];
screenCorrectionParm[0] = 1.0f / glConfig.nativeScreenWidth;
@ -4999,7 +4997,24 @@ void RB_PostProcess( const void* data )
screenCorrectionParm[3] = glConfig.nativeScreenHeight;
SetFragmentParm( RENDERPARM_SCREENCORRECTIONFACTOR, screenCorrectionParm ); // rpScreenCorrectionFactor
renderProgManager.BindShader_SMAA_EdgeDetection();
RB_DrawElementsWithCounters( &backEnd.unitSquareSurface );
globalImages->smaaEdgesImage->CopyFramebuffer( viewport.x1, viewport.y1, viewport.GetWidth(), viewport.GetHeight() );
GL_SelectTexture( 1 );
globalImages->smaaAreaImage->Bind();
GL_SelectTexture( 2 );
globalImages->smaaSearchImage->Bind();
renderProgManager.BindShader_SMAA_BlendingWeightCalculation();
RB_DrawElementsWithCounters( &backEnd.unitSquareSurface );
//globalImages->currentRenderImage->CopyFramebuffer( viewport.x1, viewport.y1, viewport.GetWidth(), viewport.GetHeight() );
}
#if 0
@ -5038,5 +5053,15 @@ void RB_PostProcess( const void* data )
#endif
globalImages->BindNull();
GL_SelectTexture( 1 );
globalImages->BindNull();
GL_SelectTexture( 0 );
globalImages->BindNull();
renderProgManager.Unbind();
renderLog.CloseBlock();
}