From 7d96af950ebeaed56acad6b389586abcd385ca03 Mon Sep 17 00:00:00 2001 From: "Asmodean.pcsx2" Date: Sun, 9 Feb 2014 01:01:41 +0000 Subject: [PATCH] GSdx: A few small post-processing changes, to accommodate future updates. Also removed the fallback recovery ps, and replaced the compile fail catch to a simple console print. Which I think is safer, and faster. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5894 96395faa-99c1-11dd-bbfe-3dabce05a288 --- bin/GSdx_FX_Settings.ini | 20 ++++---- bin/shader.fx | 97 ++++++++++++++++--------------------- plugins/GSdx/GSDevice11.cpp | 4 +- plugins/GSdx/GSDevice9.cpp | 4 +- plugins/GSdx/res/fxaa.fx | 35 ------------- 5 files changed, 56 insertions(+), 104 deletions(-) diff --git a/bin/GSdx_FX_Settings.ini b/bin/GSdx_FX_Settings.ini index ace9e914fb..37ef63ca5b 100644 --- a/bin/GSdx_FX_Settings.ini +++ b/bin/GSdx_FX_Settings.ini @@ -14,7 +14,9 @@ || || |#################################################################################| \*===============================================================================*/ - +//NOTICE: This shader suite requires DirectX 10, or higher. +//If this file looks messy and/or text is misaligned: use another text editor instead of regular MS Notepad. +//Recommended: Notepad++ http://notepad-plus-plus.org/download/v6.5.3.html /*------------------------------------------------------------------------------ [DEFINITIONS & ON/OFF OPTIONS] ------------------------------------------------------------------------------*/ @@ -68,14 +70,14 @@ //-[BLOOM OPTIONS] #define BloomType BlendBloom //[BlendBloom, BlendScreen, BlendOverlay, BlendAddLight] The type of blend for the bloom (Default: BlendScreen). If using BlendOverlay set ToneAmount to 2.20, or it may be too dark. -#define BloomPower 0.250 //[0.000 to 2.000] Strength of the bloom. You may need to readjust for each blend type. +#define BloomPower 0.200 //[0.000 to 2.000] Strength of the bloom. You may need to readjust for each blend type. #define BlendPower 1.000 //[0.000 to 1.500] Strength of the bloom blend. Lower for less blending, higher for more. Default is 1.000. #define BlendSpread 4.000 //[0.000 to 8.000] Width of the bloom glow spread. Scales with BloomPower. Raising SharpenClamp affects this. 0.000 = off. #define BloomMixType 1 //[1|2|3] The interpolation mix type between the base colour, and bloom. (Default is 1) BloomPower/BlendSpread may need re-adjusting depending on type. //-[TONEMAP OPTIONS] #define TonemapType 1 //[1 or 2] Type of tone mapping. 1 is Natural(default), 2 is Filmic(cinematic) You might want to increase/decrease ToneAmount to compensate for diff types. -#define ToneAmount 2.02 //[1.00 to 4.00] Tonemapping & Gamma curve (Tonemapping/Shadow correction). Lower values for darker tones, Higher values for lighter tones. Default: 2.20 +#define ToneAmount 2.15 //[1.00 to 4.00] Tonemapping & Gamma curve (Tonemapping/Shadow correction). Lower values for darker tones, Higher values for lighter tones. Default: 2.20 #define Luminance 1.00 //[0.10 to 2.00] Luminance Average (luminance correction) Higher values to decrease luminance average, lower values to increase luminance. Adjust by small amounts, eg: increments of 0.1 #define Exposure 1.00 //[0.10 to 2.00] White Correction (brightness) Higher values = more Exposure, lower = less Exposure. Adjust by small amounts, eg: increments of 0.1 #define WhitePoint 1.00 //[0.10 to 2.00] Whitepoint Avg (lum correction) Adjust by small amounts, eg: increments of 0.01. Generally it's best left at 1.00. @@ -117,16 +119,16 @@ #define ColorRounding 0 //[0 or 1] Uses rounding methods on colors. This can emphasise shaded toon colors. Looks good in some games, and odd in others. Try it in-game and see. //-[SCANLINE OPTIONS] -#define ScanlineType 3 //[0|1|2|3] The type & orientation of the scanlines. 0 is x(horizontal), 1 is y(vertical), 2 is both(xy), ScanlineType 3 is a different algorithm, to work around PCSX2's IR scaling. -#define ScanlineScale 1.00 //[0.20 to 2.00] The scaling & thickness of the scanlines. Changing this can help with PCSX2 IR scaling problems. Defaults: 0.50 for ScanlineType 0|1|2, (1.20 for ScanlineType 3, use 1.0 with low IR (lower than 3x)). -#define ScanlineIntensity 0.50 //[0.10 to 1.00] The intensity of the scanlines. Defaults: 0.20 for ScanlineType 0|1|2, 0.50 for ScanlineType 3. -#define ScanlineBrightness 1.50 //[0.50 to 2.00] The brightness of the scanlines. Defaults: 1.75 for ScanlineType 0|1|2, 1.50 for ScanlineType 3. +#define ScanlineType 0 //[0|1|2|3] The type & orientation of the scanlines. 0 is x(horizontal), 1 is y(vertical), 2 is both(xy), ScanlineType 3 is a different algorithm, to work around PCSX2's IR scaling. +#define ScanlineScale 0.50 //[0.20 to 2.00] The scaling & thickness of the scanlines. Changing this can help with PCSX2 IR scaling problems. Defaults: 0.50 for ScanlineType 0|1|2, (1.20 for ScanlineType 3, use 1.0 with low IR (lower than 3x)). +#define ScanlineIntensity 0.18 //[0.10 to 1.00] The intensity of the scanlines. Defaults: 0.20 for ScanlineType 0|1|2, 0.50 for ScanlineType 3. +#define ScanlineBrightness 2.00 //[0.50 to 2.00] The brightness of the scanlines. Defaults: 1.75 for ScanlineType 0|1|2, 1.50 for ScanlineType 3. //-[VIGNETTE OPTIONS] #define VignetteRatio 1.77 //[0.15 to 6.00] Sets the espect ratio of the vignette. 1.77 for 16:9, 1.60 for 16:10, 1.33 for 4:3, 1.00 for 1:1. #define VignetteRadius 1.00 //[0.50 to 3.00] Radius of the vignette effect. Lower values for stronger radial effect from center -#define VignetteAmount 0.15 //[0.00 to 2.00] Strength of black edge occlusion. Increase for higher strength, decrease for lower. -#define VignetteSlope 8 //[2|4|8|12|16] How far away from the center the vignetting will start. +#define VignetteAmount 0.25 //[0.00 to 1.00] Strength of black edge occlusion. Increase for higher strength, decrease for lower. +#define VignetteSlope 12 //[2|4|8|10|12|16] How far away from the center the vignetting will start. //-[DITHERING OPTIONS] #define DitherMethod 2 //[1 or 2] 1 is Ordering dithering(faster, lower quality), 2 is Random dithering (better dithering, but not as fast) diff --git a/bin/shader.fx b/bin/shader.fx index f8b842b30c..9e1784e71c 100644 --- a/bin/shader.fx +++ b/bin/shader.fx @@ -1,6 +1,6 @@ /*===============================================================================*\ -|######################### [GSdx FX 2.00 Revised] ########################| -|########################### By Asmodean ##########################| +|######################### [GSdx FX 2.00 Revised] #########################| +|########################### By Asmodean ##########################| || || || This program is free software; you can redistribute it and/or || || modify it under the terms of the GNU General Public License || @@ -21,14 +21,9 @@ ------------------------------------------------------------------------------*/ Texture2D Texture : register(t0); -SamplerState TextureSampler : register(s0) -{ - Filter = Anisotropic; - MaxAnisotropy = 16; - AddressU = Clamp; - AddressV = Clamp; - MipLODBias = 0; -}; + +SamplerState TextureSampler : register(s0); +SamplerState BloomSampler : register(s1); cbuffer cb0 { @@ -88,6 +83,7 @@ float RGBLuminance(float3 color) float3 RGBGammaToLinear(float3 color, float gamma) { color = abs(color); + color.r = (color.r <= 0.0404482362771082) ? saturate(color.r / 12.92) : saturate(pow((color.r + 0.055) / 1.055, gamma)); @@ -103,6 +99,7 @@ float3 RGBGammaToLinear(float3 color, float gamma) float3 LinearToRGBGamma(float3 color, float gamma) { color = abs(color); + color.r = (color.r <= 0.00313066844250063) ? saturate(color.r * 12.92) : 1.055 * saturate(pow(color.r, 1.0 / gamma)) - 0.055; @@ -158,9 +155,6 @@ float4 PreGammaPass(float4 color, float2 uv0) #elif (SHADER_MODEL >= 0x400) #define FXAA_HLSL_4 1 #define FXAA_GATHER4_ALPHA 0 -#else - #define FXAA_HLSL_3 1 - #define FXAA_GATHER4_ALPHA 0 #endif #if (FxaaQuality == 4) @@ -242,13 +236,6 @@ float4 PreGammaPass(float4 color, float2 uv0) #define FxaaTexOff(t, p, o, r) t.tex.SampleLevel(t.smpl, p, 0.0, o) #define FxaaDiscard clip(-1) #define FxaaSat(x) saturate(x) - -#elif (FXAA_HLSL_3 == 1) - #define FxaaTex sampler2D - #define int2 float2 - #define FxaaSat(x) saturate(x) - #define FxaaTexTop(t, p) tex2Dlod(t, float4(p, 0.0, 0.0)) - #define FxaaTexOff(t, p, o, r) tex2Dlod(t, float4(p + (o * r), 0, 0)) #endif float FxaaLuma(float4 rgba) @@ -296,11 +283,11 @@ float4 FxaaPixelShader(float2 pos, FxaaTex tex, float2 fxaaRcpFrame, float fxaaS float minWN = min(lumaN, lumaW); float rangeMax = max(maxWN, maxESM); float rangeMin = min(minWN, minESM); - float rangeMaxScaled = rangeMax * fxaaEdgeThreshold; float range = rangeMax - rangeMin; + float rangeMaxScaled = rangeMax * fxaaEdgeThreshold; float rangeMaxClamped = max(fxaaEdgeThresholdMin, rangeMaxScaled); - bool earlyExit = range < rangeMaxClamped; + bool earlyExit = range < rangeMaxClamped; #if (FxaaEarlyExit == 1) if(earlyExit) { return rgbyM; } @@ -364,7 +351,6 @@ float4 FxaaPixelShader(float2 pos, FxaaTex tex, float2 fxaaRcpFrame, float fxaaS offNP.y = ( horzSpan) ? 0.0 : fxaaRcpFrame.y; if(!horzSpan) posB.x += lengthSign * 0.5; if( horzSpan) posB.y += lengthSign * 0.5; - float2 posN; posN.x = posB.x - offNP.x * FXAA_QUALITY__P0; posN.y = posB.y - offNP.y * FXAA_QUALITY__P0; @@ -381,7 +367,6 @@ float4 FxaaPixelShader(float2 pos, FxaaTex tex, float2 fxaaRcpFrame, float fxaaS float lumaMM = lumaM - lumaNN * 0.5; float subpixF = subpixD * subpixE; bool lumaMLTZero = lumaMM < 0.0; - lumaEndN -= lumaNN * 0.5; lumaEndP -= lumaNN * 0.5; bool doneN = abs(lumaEndN) >= gradientScaled; @@ -565,7 +550,6 @@ float4 FxaaPixelShader(float2 pos, FxaaTex tex, float2 fxaaRcpFrame, float fxaaS } #endif } - float dstN = posM.x - posN.x; float dstP = posP.x - posM.x; if(!horzSpan) dstN = posM.y - posN.y; @@ -921,7 +905,6 @@ float4 SampleBiCubic(SamplerState texSample, float2 uv0) float4 TexSharpenPass(float4 color : COLOR0, float2 uv0 : TEXCOORD0) : SV_Target0 { float3 calcSharpen = (SLumCoeff * SharpenStrength); - float4 blurredColor = SampleBiCubic(TextureSampler, uv0); float3 sharpenedColor = (color.rgb - blurredColor.rgb); @@ -1029,7 +1012,9 @@ float3 BlendOverlay(float3 color, float3 bloom) float4 BloomPass(float4 color : COLOR0, float2 uv0 : TEXCOORD0) : SV_Target0 { - float4 bloom; + float4 bloom = Texture.Sample(BloomSampler, uv0); + + Texture.GetDimensions(PixelSize.x, PixelSize.y); float2 dx = float2(1.0 / PixelSize.x * BlendSpread, 0.0); float2 dy = float2(0.0, 1.0 / PixelSize.y * BlendSpread); @@ -1037,36 +1022,36 @@ float4 BloomPass(float4 color : COLOR0, float2 uv0 : TEXCOORD0) : SV_Target0 float2 dx2 = 2.0 * dx; float2 dy2 = 2.0 * dy; - float4 bloomBlend = color * 0.22520613262190495; + float4 bloomBlend = bloom * 0.22520613262190495; - bloomBlend += 0.002589001911021066 * Texture.Sample(TextureSampler, uv0 -dx2 +dy2); - bloomBlend += 0.010778807494659370 * Texture.Sample(TextureSampler, uv0 -dx +dy2); - bloomBlend += 0.024146616900339800 * Texture.Sample(TextureSampler, uv0 +dy2); - bloomBlend += 0.010778807494659370 * Texture.Sample(TextureSampler, uv0 +dx +dy2); - bloomBlend += 0.002589001911021066 * Texture.Sample(TextureSampler, uv0 +dx2 +dy2); + bloomBlend += 0.002589001911021066 * Texture.Sample(BloomSampler, uv0 -dx2 +dy2); + bloomBlend += 0.010778807494659370 * Texture.Sample(BloomSampler, uv0 -dx +dy2); + bloomBlend += 0.024146616900339800 * Texture.Sample(BloomSampler, uv0 +dy2); + bloomBlend += 0.010778807494659370 * Texture.Sample(BloomSampler, uv0 +dx +dy2); + bloomBlend += 0.002589001911021066 * Texture.Sample(BloomSampler, uv0 +dx2 +dy2); - bloomBlend += 0.010778807494659370 * Texture.Sample(TextureSampler, uv0 -dx2 +dy); - bloomBlend += 0.044875475183061630 * Texture.Sample(TextureSampler, uv0 -dx +dy); - bloomBlend += 0.100529757860782610 * Texture.Sample(TextureSampler, uv0 +dy); - bloomBlend += 0.044875475183061630 * Texture.Sample(TextureSampler, uv0 +dx +dy); - bloomBlend += 0.010778807494659370 * Texture.Sample(TextureSampler, uv0 +dx2 +dy); + bloomBlend += 0.010778807494659370 * Texture.Sample(BloomSampler, uv0 -dx2 +dy); + bloomBlend += 0.044875475183061630 * Texture.Sample(BloomSampler, uv0 -dx +dy); + bloomBlend += 0.100529757860782610 * Texture.Sample(BloomSampler, uv0 +dy); + bloomBlend += 0.044875475183061630 * Texture.Sample(BloomSampler, uv0 +dx +dy); + bloomBlend += 0.010778807494659370 * Texture.Sample(BloomSampler, uv0 +dx2 +dy); - bloomBlend += 0.024146616900339800 * Texture.Sample(TextureSampler, uv0 -dx2); - bloomBlend += 0.100529757860782610 * Texture.Sample(TextureSampler, uv0 -dx); - bloomBlend += 0.100529757860782610 * Texture.Sample(TextureSampler, uv0 +dx); - bloomBlend += 0.024146616900339800 * Texture.Sample(TextureSampler, uv0 +dx2); + bloomBlend += 0.024146616900339800 * Texture.Sample(BloomSampler, uv0 -dx2); + bloomBlend += 0.100529757860782610 * Texture.Sample(BloomSampler, uv0 -dx); + bloomBlend += 0.100529757860782610 * Texture.Sample(BloomSampler, uv0 +dx); + bloomBlend += 0.024146616900339800 * Texture.Sample(BloomSampler, uv0 +dx2); - bloomBlend += 0.010778807494659370 * Texture.Sample(TextureSampler, uv0 -dx2 -dy); - bloomBlend += 0.044875475183061630 * Texture.Sample(TextureSampler, uv0 -dx -dy); - bloomBlend += 0.100529757860782610 * Texture.Sample(TextureSampler, uv0 -dy); - bloomBlend += 0.044875475183061630 * Texture.Sample(TextureSampler, uv0 +dx -dy); - bloomBlend += 0.010778807494659370 * Texture.Sample(TextureSampler, uv0 +dx2 -dy); + bloomBlend += 0.010778807494659370 * Texture.Sample(BloomSampler, uv0 -dx2 -dy); + bloomBlend += 0.044875475183061630 * Texture.Sample(BloomSampler, uv0 -dx -dy); + bloomBlend += 0.100529757860782610 * Texture.Sample(BloomSampler, uv0 -dy); + bloomBlend += 0.044875475183061630 * Texture.Sample(BloomSampler, uv0 +dx -dy); + bloomBlend += 0.010778807494659370 * Texture.Sample(BloomSampler, uv0 +dx2 -dy); - bloomBlend += 0.002589001911021066 * Texture.Sample(TextureSampler, uv0 -dx2 -dy2); - bloomBlend += 0.010778807494659370 * Texture.Sample(TextureSampler, uv0 -dx -dy2); - bloomBlend += 0.024146616900339800 * Texture.Sample(TextureSampler, uv0 -dy2); - bloomBlend += 0.010778807494659370 * Texture.Sample(TextureSampler, uv0 +dx -dy2); - bloomBlend += 0.002589001911021066 * Texture.Sample(TextureSampler, uv0 +dx2 -dy2); + bloomBlend += 0.002589001911021066 * Texture.Sample(BloomSampler, uv0 -dx2 -dy2); + bloomBlend += 0.010778807494659370 * Texture.Sample(BloomSampler, uv0 -dx -dy2); + bloomBlend += 0.024146616900339800 * Texture.Sample(BloomSampler, uv0 -dy2); + bloomBlend += 0.010778807494659370 * Texture.Sample(BloomSampler, uv0 +dx -dy2); + bloomBlend += 0.002589001911021066 * Texture.Sample(BloomSampler, uv0 +dx2 -dy2); bloomBlend = lerp(color, bloomBlend, BlendPower); bloom.rgb = BloomType(color.rgb, bloomBlend.rgb); @@ -1497,11 +1482,11 @@ float4 ScanlinesPass(float4 color : COLOR0, float2 uv0 : TEXCOORD0, float4 FragC float4 intensity; #if (ScanlineType == 0) - if (frac(FragCoord.y * 0.25) > ScanlineScale) + if (frac(FragCoord.y * 0.5) > ScanlineScale) #elif (ScanlineType == 1) - if (frac(FragCoord.x * 0.25) > ScanlineScale) + if (frac(FragCoord.x * 0.5) > ScanlineScale) #elif (ScanlineType == 2) - if (frac(FragCoord.x * 0.25) > ScanlineScale && frac(FragCoord.y * 0.25) > ScanlineScale) + if (frac(FragCoord.x * 0.5) > ScanlineScale && frac(FragCoord.y * 0.5) > ScanlineScale) #endif { intensity = float4(0.0, 0.0, 0.0, 0.0); @@ -1536,7 +1521,7 @@ float4 VignettePass(float4 color : COLOR0, float2 uv0 : TEXCOORD0) : SV_Target float v = dot(tc, tc); - color.rgb *= (1.0 + pow(v, VignetteSlope * 0.5) * -VignetteAmount); + color.rgb *= (1.0 + pow(v, VignetteSlope * 0.25) * -VignetteAmount); return color; } diff --git a/plugins/GSdx/GSDevice11.cpp b/plugins/GSdx/GSDevice11.cpp index b14b1bd8ff..85a16bc1d7 100644 --- a/plugins/GSdx/GSDevice11.cpp +++ b/plugins/GSdx/GSDevice11.cpp @@ -745,7 +745,7 @@ void GSDevice11::InitExternalFX() CompileShader("shader.fx", "ps_main", NULL, &m_shaderfx.ps); } catch (GSDXRecoverableError) { - CompileShader(IDR_FXAA_FX, "ps_recover", NULL, &m_fxaa.ps); + printf("GSdx: failed to compile external post-processing shader. \n"); } ExShader_Compiled = true; } @@ -780,7 +780,7 @@ void GSDevice11::InitFXAA() CompileShader(IDR_FXAA_FX, "ps_main", NULL, &m_fxaa.ps); } catch (GSDXRecoverableError) { - CompileShader(IDR_FXAA_FX, "ps_recover", NULL, &m_fxaa.ps); + printf("GSdx: failed to compile fxaa shader.\n"); } FXAA_Compiled = true; } diff --git a/plugins/GSdx/GSDevice9.cpp b/plugins/GSdx/GSDevice9.cpp index b8446869fd..b6f64c8d03 100644 --- a/plugins/GSdx/GSDevice9.cpp +++ b/plugins/GSdx/GSDevice9.cpp @@ -933,7 +933,7 @@ void GSDevice9::InitExternalFX() CompileShader("shader.fx", "ps_main", NULL, &m_shaderfx.ps); } catch (GSDXRecoverableError) { - CompileShader(IDR_FXAA_FX, "ps_recover", NULL, &m_fxaa.ps); + printf("GSdx: failed to compile external post-processing shader. \n"); } ExShader_Compiled = true; } @@ -964,7 +964,7 @@ void GSDevice9::InitFXAA() CompileShader(IDR_FXAA_FX, "ps_main", NULL, &m_fxaa.ps); } catch (GSDXRecoverableError) { - CompileShader(IDR_FXAA_FX, "ps_recover", NULL, &m_fxaa.ps); + printf("GSdx: Failed to compile fxaa shader.\n"); } FXAA_Compiled = true; } diff --git a/plugins/GSdx/res/fxaa.fx b/plugins/GSdx/res/fxaa.fx index 69ac45554c..fa0fbafe38 100644 --- a/plugins/GSdx/res/fxaa.fx +++ b/plugins/GSdx/res/fxaa.fx @@ -1,19 +1,3 @@ -/*===============================================================================*\ -|####################### [GSdx FXAA 2.00] ########################| -|######################## By Asmodean #########################| -|| || -|| This program 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 2 || -|| of the License, or (at your option) any later version. || -|| || -|| This program 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. (c)2014 || -|| || -|#################################################################################| -\*===============================================================================*/ #ifdef SHADER_MODEL #define UHQ_FXAA 1 //High Quality Fast Approximate Anti Aliasing. Adapted for GSdx from Timothy Lottes FXAA 3.11. @@ -530,23 +514,4 @@ PS_OUTPUT ps_main(VS_OUTPUT input) return output; } - -/*------------------------------------------------------------------------------ - [RECOVERY PS CODE SECTION] -------------------------------------------------------------------------------*/ - -PS_OUTPUT ps_recover(VS_OUTPUT input) -{ - PS_OUTPUT output; - - #if (SHADER_MODEL >= 0x400) - float4 color = Texture.Sample(TextureSampler, input.t); - #else - float4 color = tex2D(TextureSampler, input.t); - #endif - - output.c = color; - - return output; -} #endif