mirror of https://github.com/PCSX2/pcsx2.git
GSdx: Some post-processing fixes & add shaders directory.
This commit is contained in:
parent
5b3867dd60
commit
c72af82f73
|
@ -617,17 +617,17 @@ float Triangular(float x)
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Cubic(float x)
|
float Cubic(float coeff)
|
||||||
{
|
{
|
||||||
float x2 = x * x;
|
float4 n = float4(1.0, 2.0, 3.0, 4.0) - coeff;
|
||||||
float x3 = x2 * x;
|
float4 s = n * n * n;
|
||||||
|
|
||||||
float cx = -x3 + 3.0 * x2 - 3.0 * x + 1.0;
|
float x = s.x;
|
||||||
float cy = 3.0 * x3 - 6.0 * x2 + 4.0;
|
float y = s.y - 4.0 * s.x;
|
||||||
float cz = -3.0 * x3 + 3.0 * x2 + 3.0 * x + 1.0;
|
float z = s.z - 4.0 * s.y + 6.0 * s.x;
|
||||||
float cw = x3;
|
float w = 6.0 - x - y - z;
|
||||||
|
|
||||||
return (lerp(cx, cy, 0.5) + lerp(cz, cw, 0.5)) / 6.0;
|
return (x + y + z + w) / 4.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
|
@ -637,12 +637,6 @@ float Cubic(float x)
|
||||||
#if (BILINEAR_FILTERING == 1)
|
#if (BILINEAR_FILTERING == 1)
|
||||||
float4 SampleBiLinear(SamplerState texSample, float2 texcoord)
|
float4 SampleBiLinear(SamplerState texSample, float2 texcoord)
|
||||||
{
|
{
|
||||||
if (screenSize.x < 1024 || screenSize.y < 1024)
|
|
||||||
{
|
|
||||||
pixelSize.x /= 2.0;
|
|
||||||
pixelSize.y /= 2.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
float texelSizeX = pixelSize.x;
|
float texelSizeX = pixelSize.x;
|
||||||
float texelSizeY = pixelSize.y;
|
float texelSizeY = pixelSize.y;
|
||||||
|
|
||||||
|
@ -686,12 +680,6 @@ float4 BiLinearPass(float4 color, float2 texcoord)
|
||||||
#if (BICUBIC_FILTERING == 1)
|
#if (BICUBIC_FILTERING == 1)
|
||||||
float4 BicubicFilter(SamplerState texSample, float2 texcoord)
|
float4 BicubicFilter(SamplerState texSample, float2 texcoord)
|
||||||
{
|
{
|
||||||
if (screenSize.x < 1024 || screenSize.y < 1024)
|
|
||||||
{
|
|
||||||
pixelSize.x /= 2.0;
|
|
||||||
pixelSize.y /= 2.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
float texelSizeX = pixelSize.x;
|
float texelSizeX = pixelSize.x;
|
||||||
float texelSizeY = pixelSize.y;
|
float texelSizeY = pixelSize.y;
|
||||||
|
|
||||||
|
@ -1049,6 +1037,7 @@ float4 VibrancePass(float4 color, float2 texcoord)
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
[BLENDED BLOOM CODE SECTION]
|
[BLENDED BLOOM CODE SECTION]
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#if (BLENDED_BLOOM == 1)
|
#if (BLENDED_BLOOM == 1)
|
||||||
float3 BlendAddLight(float3 color, float3 bloom)
|
float3 BlendAddLight(float3 color, float3 bloom)
|
||||||
{
|
{
|
||||||
|
@ -1192,14 +1181,14 @@ float3 ColorShift(float3 color)
|
||||||
colMood.b = float(BlueShift);
|
colMood.b = float(BlueShift);
|
||||||
|
|
||||||
float fLum = RGBLuminance(color.rgb);
|
float fLum = RGBLuminance(color.rgb);
|
||||||
#if (GLSL == 1)
|
#if (GLSL == 1)
|
||||||
// Is HLSL float3(x) equivalent to float3(x,x,x) ?
|
// Is HLSL float3(x) equivalent to float3(x,x,x) ?
|
||||||
colMood = lerp(float3(0.0), colMood, saturate(fLum * 2.0));
|
colMood = lerp(float3(0.0), colMood, saturate(fLum * 2.0));
|
||||||
colMood = lerp(colMood, float3(1.0), saturate(fLum - 0.5) * 2.0);
|
colMood = lerp(colMood, float3(1.0), saturate(fLum - 0.5) * 2.0);
|
||||||
#else
|
#else
|
||||||
colMood = lerp(0.0, colMood, saturate(fLum * 2.0));
|
colMood = lerp(0.0, colMood, saturate(fLum * 2.0));
|
||||||
colMood = lerp(colMood, 1.0, saturate(fLum - 0.5) * 2.0);
|
colMood = lerp(colMood, 1.0, saturate(fLum - 0.5) * 2.0);
|
||||||
#endif
|
#endif
|
||||||
float3 colOutput = lerp(color, colMood, saturate(fLum * float(ShiftRatio)));
|
float3 colOutput = lerp(color, colMood, saturate(fLum * float(ShiftRatio)));
|
||||||
|
|
||||||
return colOutput;
|
return colOutput;
|
||||||
|
@ -1228,25 +1217,22 @@ float4 TonemapPass(float4 color, float2 texcoord)
|
||||||
if (FilmicProcess == 0) { color.rgb = FilmicTonemap(color.rgb); }
|
if (FilmicProcess == 0) { color.rgb = FilmicTonemap(color.rgb); }
|
||||||
|
|
||||||
// RGB -> XYZ conversion
|
// RGB -> XYZ conversion
|
||||||
#if (GLSL == 1)
|
#if (GLSL == 1)
|
||||||
// GLSL is column major whereas HLSL is row major ...
|
// GLSL is column major whereas HLSL is row major ...
|
||||||
const mat3 RGB2XYZ = mat3 (
|
const mat3 RGB2XYZ = mat3 ( 0.4124564, 0.2126729, 0.0193339, // first column (not row)
|
||||||
0.4124564, 0.2126729, 0.0193339, // first column (not row)
|
0.3575761, 0.7151522, 0.1191920, // 2nd column
|
||||||
0.3575761, 0.7151522, 0.1191920, // 2nd column
|
0.1804375, 0.0721750, 0.9503041 ); // 3rd column
|
||||||
0.1804375, 0.0721750, 0.9503041 // 3rd column
|
#else
|
||||||
);
|
|
||||||
#else
|
|
||||||
const float3x3 RGB2XYZ = { 0.4124564, 0.3575761, 0.1804375,
|
const float3x3 RGB2XYZ = { 0.4124564, 0.3575761, 0.1804375,
|
||||||
0.2126729, 0.7151522, 0.0721750,
|
0.2126729, 0.7151522, 0.0721750,
|
||||||
0.0193339, 0.1191920, 0.9503041 };
|
0.0193339, 0.1191920, 0.9503041 };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (GLSL == 1)
|
#if (GLSL == 1)
|
||||||
float3 XYZ = RGB2XYZ * color.rgb;
|
float3 XYZ = RGB2XYZ * color.rgb;
|
||||||
#else
|
#else
|
||||||
float3 XYZ = mul(RGB2XYZ, color.rgb);
|
float3 XYZ = mul(RGB2XYZ, color.rgb);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// XYZ -> Yxy conversion
|
// XYZ -> Yxy conversion
|
||||||
float3 Yxy;
|
float3 Yxy;
|
||||||
|
@ -1278,25 +1264,22 @@ float4 TonemapPass(float4 color, float2 texcoord)
|
||||||
if (CorrectionPalette == 3) { XYZ.rgb = ColorCorrection(XYZ.rgb); }
|
if (CorrectionPalette == 3) { XYZ.rgb = ColorCorrection(XYZ.rgb); }
|
||||||
|
|
||||||
// XYZ -> RGB conversion
|
// XYZ -> RGB conversion
|
||||||
#if (GLSL == 1)
|
#if (GLSL == 1)
|
||||||
// GLSL is column major whereas HLSL is row major ...
|
// GLSL is column major whereas HLSL is row major ...
|
||||||
const mat3 XYZ2RGB = mat3 (
|
const mat3 XYZ2RGB = mat3 ( 3.2404542, -0.9692660, 0.0556434, // first column (not row)
|
||||||
3.2404542, -0.9692660, 0.0556434, // first column (not row)
|
-1.5371385, 1.8760108, -0.2040259, // 2nd column
|
||||||
-1.5371385, 1.8760108, -0.2040259, // 2nd column
|
-0.4985314, 0.0415560, 1.0572252 ); // 3rd column
|
||||||
-0.4985314, 0.0415560, 1.0572252 // 3rd column
|
#else
|
||||||
);
|
|
||||||
#else
|
|
||||||
const float3x3 XYZ2RGB = { 3.2404542,-1.5371385,-0.4985314,
|
const float3x3 XYZ2RGB = { 3.2404542,-1.5371385,-0.4985314,
|
||||||
-0.9692660, 1.8760108, 0.0415560,
|
-0.9692660, 1.8760108, 0.0415560,
|
||||||
0.0556434,-0.2040259, 1.0572252 };
|
0.0556434,-0.2040259, 1.0572252 };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (GLSL == 1)
|
||||||
#if (GLSL == 1)
|
|
||||||
color.rgb = XYZ2RGB * XYZ;
|
color.rgb = XYZ2RGB * XYZ;
|
||||||
#else
|
#else
|
||||||
color.rgb = mul(XYZ2RGB, XYZ);
|
color.rgb = mul(XYZ2RGB, XYZ);
|
||||||
#endif
|
#endif
|
||||||
color.a = RGBLuminance(color.rgb);
|
color.a = RGBLuminance(color.rgb);
|
||||||
|
|
||||||
return saturate(color);
|
return saturate(color);
|
||||||
|
@ -1367,57 +1350,54 @@ float4 ContrastPass(float4 color, float2 texcoord)
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#if (CEL_SHADING == 1)
|
#if (CEL_SHADING == 1)
|
||||||
float3 GetYUV(float3 rgb)
|
float3 GetYUV(float3 RGB)
|
||||||
{
|
{
|
||||||
#if (GLSL == 1)
|
#if (GLSL == 1)
|
||||||
mat3 RGB2YUV = mat3(
|
const mat3 RGB2YUV = mat3(0.2126, 0.7152, 0.0722,
|
||||||
0.2126, 0.7152, 0.0722,
|
-0.09991,-0.33609, 0.436,
|
||||||
-0.09991, -0.33609, 0.436,
|
0.615, -0.55861, -0.05639);
|
||||||
0.615, -0.55861, -0.05639);
|
|
||||||
|
|
||||||
return (rgb * RGB2YUV);
|
return (RGB * RGB2YUV);
|
||||||
#else
|
#else
|
||||||
float3x3 RGB2YUV = {
|
const float3x3 RGB2YUV = { 0.2126, 0.7152, 0.0722,
|
||||||
0.2126, 0.7152, 0.0722,
|
-0.09991,-0.33609, 0.436,
|
||||||
-0.09991, -0.33609, 0.436,
|
0.615, -0.55861, -0.05639 };
|
||||||
0.615, -0.55861, -0.05639 };
|
|
||||||
|
|
||||||
return mul(RGB2YUV, rgb);
|
return mul(RGB2YUV, RGB);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
float3 GetRGB(float3 yuv)
|
float3 GetRGB(float3 YUV)
|
||||||
{
|
{
|
||||||
#if (GLSL == 1)
|
#if (GLSL == 1)
|
||||||
mat3 YUV2RGB = mat3(
|
const mat3 YUV2RGB = mat3(1.000, 0.000, 1.28033,
|
||||||
1.000, 0.000, 1.28033,
|
1.000,-0.21482,-0.38059,
|
||||||
1.000, -0.21482, -0.38059,
|
1.000, 2.12798, 0.000);
|
||||||
1.000, 2.12798, 0.000);
|
|
||||||
|
|
||||||
return (yuv * YUV2RGB);
|
return (YUV * YUV2RGB);
|
||||||
#else
|
#else
|
||||||
float3x3 YUV2RGB = {
|
const float3x3 YUV2RGB = { 1.000, 0.000, 1.28033,
|
||||||
1.000, 0.000, 1.28033,
|
1.000,-0.21482,-0.38059,
|
||||||
1.000, -0.21482, -0.38059,
|
1.000, 2.12798, 0.000 };
|
||||||
1.000, 2.12798, 0.000 };
|
|
||||||
|
|
||||||
return mul(YUV2RGB, yuv);
|
return mul(YUV2RGB, YUV);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
float4 CelPass(float4 color, float2 texcoord)
|
float4 CelPass(float4 color, float2 texcoord)
|
||||||
{
|
{
|
||||||
float3 yuv;
|
float3 yuv;
|
||||||
float3 sum = color.rgb;
|
float3 sum = color.rgb;
|
||||||
float2 pixel = pixelSize * EdgeThickness;
|
|
||||||
|
|
||||||
const float2 RoundingOffset = float2(0.20, 0.40);
|
|
||||||
const float3 thresholds = float3(5.0, 8.0, 6.0);
|
|
||||||
|
|
||||||
const int NUM = 9;
|
const int NUM = 9;
|
||||||
float2 c[NUM] = {
|
const float2 RoundingOffset = float2(0.25, 0.25);
|
||||||
|
const float3 thresholds = float3(9.0, 8.0, 6.0);
|
||||||
|
|
||||||
|
float lum[NUM];
|
||||||
|
float3 col[NUM];
|
||||||
|
float2 set[NUM] = {
|
||||||
float2(-0.0078125, -0.0078125),
|
float2(-0.0078125, -0.0078125),
|
||||||
float2(0.00, -0.0078125),
|
float2(0.00, -0.0078125),
|
||||||
float2(0.0078125, -0.0078125),
|
float2(0.0078125, -0.0078125),
|
||||||
|
@ -1428,32 +1408,31 @@ float4 CelPass(float4 color, float2 texcoord)
|
||||||
float2(0.00, 0.0078125),
|
float2(0.00, 0.0078125),
|
||||||
float2(0.0078125, 0.0078125) };
|
float2(0.0078125, 0.0078125) };
|
||||||
|
|
||||||
float3 col[NUM];
|
|
||||||
float lum[NUM];
|
|
||||||
|
|
||||||
for (int i = 0; i < NUM; i++)
|
for (int i = 0; i < NUM; i++)
|
||||||
{
|
{
|
||||||
col[i] = sample_tex(TextureSampler, texcoord + c[i] * RoundingOffset).rgb;
|
col[i] = sample_tex(TextureSampler, texcoord + set[i] * RoundingOffset).rgb;
|
||||||
|
|
||||||
#if (ColorRounding == 1)
|
#if (ColorRounding == 1)
|
||||||
col[i].r = saturate(round(col[i].r * thresholds.r) / thresholds.r);
|
col[i].r = round(col[i].r * thresholds.r) / thresholds.r;
|
||||||
col[i].g = saturate(round(col[i].g * thresholds.g) / thresholds.g);
|
col[i].g = round(col[i].g * thresholds.g) / thresholds.g;
|
||||||
col[i].b = saturate(round(col[i].b * thresholds.b) / thresholds.b);
|
col[i].b = round(col[i].b * thresholds.b) / thresholds.b;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
lum[i] = RGBLuminance(col[i].xyz);
|
lum[i] = RGBLuminance(col[i].xyz);
|
||||||
yuv = GetYUV(col[i]);
|
yuv = GetYUV(col[i]);
|
||||||
|
|
||||||
if (UseYuvLuma == 0)
|
#if (UseYuvLuma == 0)
|
||||||
{ yuv.r = saturate(round(yuv.r * lum[i]) / thresholds.r + lum[i]); }
|
yuv.r = round(yuv.r * thresholds.r) / thresholds.r;
|
||||||
else
|
#else
|
||||||
{ yuv.r = saturate(round(yuv.r * thresholds.r) / thresholds.r + lum[i] / (255.0 / 5.0)); }
|
yuv.r = saturate(round(yuv.r * lum[i]) / thresholds.r + lum[i]);
|
||||||
|
#endif
|
||||||
|
|
||||||
yuv = GetRGB(yuv);
|
yuv = GetRGB(yuv);
|
||||||
sum += yuv;
|
sum += yuv;
|
||||||
}
|
}
|
||||||
|
|
||||||
float3 shadedColor = (sum / NUM);
|
float3 shadedColor = (sum / NUM);
|
||||||
|
float2 pixel = float2(pixelSize.x * EdgeThickness, pixelSize.y * EdgeThickness);
|
||||||
|
|
||||||
float edgeX = dot(sample_tex(TextureSampler, texcoord + pixel).rgb, lumCoeff);
|
float edgeX = dot(sample_tex(TextureSampler, texcoord + pixel).rgb, lumCoeff);
|
||||||
edgeX = dot(float4(sample_tex(TextureSampler, texcoord - pixel).rgb, edgeX), float4(lumCoeff, -1.0));
|
edgeX = dot(float4(sample_tex(TextureSampler, texcoord - pixel).rgb, edgeX), float4(lumCoeff, -1.0));
|
||||||
|
@ -1466,7 +1445,7 @@ float4 CelPass(float4 color, float2 texcoord)
|
||||||
#if (PaletteType == 1)
|
#if (PaletteType == 1)
|
||||||
color.rgb = lerp(color.rgb, color.rgb + pow(edge, EdgeFilter) * -EdgeStrength, EdgeStrength);
|
color.rgb = lerp(color.rgb, color.rgb + pow(edge, EdgeFilter) * -EdgeStrength, EdgeStrength);
|
||||||
#elif (PaletteType == 2)
|
#elif (PaletteType == 2)
|
||||||
color.rgb = lerp(color.rgb + pow(edge, EdgeFilter) * -EdgeStrength, shadedColor, 0.25);
|
color.rgb = lerp(color.rgb + pow(edge, EdgeFilter) * -EdgeStrength, shadedColor, 0.30);
|
||||||
#elif (PaletteType == 3)
|
#elif (PaletteType == 3)
|
||||||
color.rgb = lerp(shadedColor + edge * -EdgeStrength, pow(edge, EdgeFilter) * -EdgeStrength + color.rgb, 0.5);
|
color.rgb = lerp(shadedColor + edge * -EdgeStrength, pow(edge, EdgeFilter) * -EdgeStrength + color.rgb, 0.5);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1540,17 +1519,11 @@ float HueLerp(float h1, float h2, float v)
|
||||||
float d = abs(h1 - h2);
|
float d = abs(h1 - h2);
|
||||||
|
|
||||||
if (d <= 0.5)
|
if (d <= 0.5)
|
||||||
{
|
{ return lerp(h1, h2, v); }
|
||||||
return lerp(h1, h2, v);
|
|
||||||
}
|
|
||||||
else if (h1 < h2)
|
else if (h1 < h2)
|
||||||
{
|
{ return frac(lerp((h1 + 1.0), h2, v)); }
|
||||||
return frac(lerp((h1 + 1.0), h2, v));
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{ return frac(lerp(h1, (h2 + 1.0), v)); }
|
||||||
return frac(lerp(h1, (h2 + 1.0), v));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float4 ColorGrading(float4 color, float2 texcoord)
|
float4 ColorGrading(float4 color, float2 texcoord)
|
||||||
|
@ -1698,13 +1671,13 @@ float4 BorderPass(float4 colorInput, float2 tex)
|
||||||
float2 border = (_rcpFrame.xy * BorderWidth);
|
float2 border = (_rcpFrame.xy * BorderWidth);
|
||||||
float2 within_border = saturate((-tex * tex + tex) - (-border * border + border));
|
float2 within_border = saturate((-tex * tex + tex) - (-border * border + border));
|
||||||
|
|
||||||
#if (GLSL == 1)
|
#if (GLSL == 1)
|
||||||
// FIXME GLSL any only support bvec so try to mix it with notEqual
|
// FIXME GLSL any only support bvec so try to mix it with notEqual
|
||||||
bvec2 cond = notEqual( within_border, vec2(0.0f) );
|
bvec2 cond = notEqual( within_border, vec2(0.0f) );
|
||||||
colorInput.rgb = all(cond) ? colorInput.rgb : border_color_float; //
|
colorInput.rgb = all(cond) ? colorInput.rgb : border_color_float;
|
||||||
#else
|
#else
|
||||||
colorInput.rgb = all(within_border) ? colorInput.rgb : border_color_float; //
|
colorInput.rgb = all(within_border) ? colorInput.rgb : border_color_float;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return colorInput;
|
return colorInput;
|
||||||
|
|
||||||
|
@ -1720,17 +1693,17 @@ void ps_main()
|
||||||
PS_OUTPUT ps_main(VS_OUTPUT input)
|
PS_OUTPUT ps_main(VS_OUTPUT input)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if (GLSL == 1)
|
#if (GLSL == 1)
|
||||||
float2 texcoord = PSin.t;
|
float2 texcoord = PSin.t;
|
||||||
float4 position = PSin.p;
|
float4 position = PSin.p;
|
||||||
float4 color = texture(TextureSampler, texcoord);
|
float4 color = texture(TextureSampler, texcoord);
|
||||||
#else
|
#else
|
||||||
PS_OUTPUT output;
|
PS_OUTPUT output;
|
||||||
|
|
||||||
float2 texcoord = input.t;
|
float2 texcoord = input.t;
|
||||||
float4 position = input.p;
|
float4 position = input.p;
|
||||||
float4 color = sample_tex(TextureSampler, texcoord);
|
float4 color = sample_tex(TextureSampler, texcoord);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (BILINEAR_FILTERING == 1)
|
#if (BILINEAR_FILTERING == 1)
|
||||||
color = BiLinearPass(color, texcoord);
|
color = BiLinearPass(color, texcoord);
|
||||||
|
@ -1796,19 +1769,19 @@ PS_OUTPUT ps_main(VS_OUTPUT input)
|
||||||
color = VignettePass(color, texcoord);
|
color = VignettePass(color, texcoord);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (DITHERING == 1)
|
|
||||||
color = DitherPass(color, texcoord);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (PX_BORDER == 1)
|
#if (PX_BORDER == 1)
|
||||||
color = BorderPass(color, texcoord);
|
color = BorderPass(color, texcoord);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (GLSL == 1)
|
#if (DITHERING == 1)
|
||||||
|
color = DitherPass(color, texcoord);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (GLSL == 1)
|
||||||
SV_Target0 = color;
|
SV_Target0 = color;
|
||||||
#else
|
#else
|
||||||
output.c = color;
|
output.c = color;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
Loading…
Reference in New Issue