GSdx: Some post-processing fixes & add shaders directory.

This commit is contained in:
Asmodean- 2014-11-15 21:37:05 +00:00
parent 5b3867dd60
commit c72af82f73
2 changed files with 1942 additions and 1969 deletions

View File

@ -617,17 +617,17 @@ float Triangular(float x)
return 0.0;
}
float Cubic(float x)
float Cubic(float coeff)
{
float x2 = x * x;
float x3 = x2 * x;
float4 n = float4(1.0, 2.0, 3.0, 4.0) - coeff;
float4 s = n * n * n;
float cx = -x3 + 3.0 * x2 - 3.0 * x + 1.0;
float cy = 3.0 * x3 - 6.0 * x2 + 4.0;
float cz = -3.0 * x3 + 3.0 * x2 + 3.0 * x + 1.0;
float cw = x3;
float x = s.x;
float y = s.y - 4.0 * s.x;
float z = s.z - 4.0 * s.y + 6.0 * s.x;
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)
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 texelSizeY = pixelSize.y;
@ -686,12 +680,6 @@ float4 BiLinearPass(float4 color, float2 texcoord)
#if (BICUBIC_FILTERING == 1)
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 texelSizeY = pixelSize.y;
@ -1049,6 +1037,7 @@ float4 VibrancePass(float4 color, float2 texcoord)
/*------------------------------------------------------------------------------
[BLENDED BLOOM CODE SECTION]
------------------------------------------------------------------------------*/
#if (BLENDED_BLOOM == 1)
float3 BlendAddLight(float3 color, float3 bloom)
{
@ -1230,11 +1219,9 @@ float4 TonemapPass(float4 color, float2 texcoord)
// RGB -> XYZ conversion
#if (GLSL == 1)
// GLSL is column major whereas HLSL is row major ...
const mat3 RGB2XYZ = mat3 (
0.4124564, 0.2126729, 0.0193339, // first column (not row)
const mat3 RGB2XYZ = mat3 ( 0.4124564, 0.2126729, 0.0193339, // first column (not row)
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
const float3x3 RGB2XYZ = { 0.4124564, 0.3575761, 0.1804375,
0.2126729, 0.7151522, 0.0721750,
@ -1247,7 +1234,6 @@ float4 TonemapPass(float4 color, float2 texcoord)
float3 XYZ = mul(RGB2XYZ, color.rgb);
#endif
// XYZ -> Yxy conversion
float3 Yxy;
@ -1280,18 +1266,15 @@ float4 TonemapPass(float4 color, float2 texcoord)
// XYZ -> RGB conversion
#if (GLSL == 1)
// GLSL is column major whereas HLSL is row major ...
const mat3 XYZ2RGB = mat3 (
3.2404542, -0.9692660, 0.0556434, // first column (not row)
const mat3 XYZ2RGB = mat3 ( 3.2404542, -0.9692660, 0.0556434, // first column (not row)
-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
const float3x3 XYZ2RGB = { 3.2404542,-1.5371385,-0.4985314,
-0.9692660, 1.8760108, 0.0415560,
0.0556434,-0.2040259, 1.0572252 };
#endif
#if (GLSL == 1)
color.rgb = XYZ2RGB * XYZ;
#else
@ -1367,42 +1350,38 @@ float4 ContrastPass(float4 color, float2 texcoord)
------------------------------------------------------------------------------*/
#if (CEL_SHADING == 1)
float3 GetYUV(float3 rgb)
float3 GetYUV(float3 RGB)
{
#if (GLSL == 1)
mat3 RGB2YUV = mat3(
0.2126, 0.7152, 0.0722,
const mat3 RGB2YUV = mat3(0.2126, 0.7152, 0.0722,
-0.09991,-0.33609, 0.436,
0.615, -0.55861, -0.05639);
return (rgb * RGB2YUV);
return (RGB * RGB2YUV);
#else
float3x3 RGB2YUV = {
0.2126, 0.7152, 0.0722,
const float3x3 RGB2YUV = { 0.2126, 0.7152, 0.0722,
-0.09991,-0.33609, 0.436,
0.615, -0.55861, -0.05639 };
return mul(RGB2YUV, rgb);
return mul(RGB2YUV, RGB);
#endif
}
float3 GetRGB(float3 yuv)
float3 GetRGB(float3 YUV)
{
#if (GLSL == 1)
mat3 YUV2RGB = mat3(
1.000, 0.000, 1.28033,
const mat3 YUV2RGB = mat3(1.000, 0.000, 1.28033,
1.000,-0.21482,-0.38059,
1.000, 2.12798, 0.000);
return (yuv * YUV2RGB);
return (YUV * YUV2RGB);
#else
float3x3 YUV2RGB = {
1.000, 0.000, 1.28033,
const float3x3 YUV2RGB = { 1.000, 0.000, 1.28033,
1.000,-0.21482,-0.38059,
1.000, 2.12798, 0.000 };
return mul(YUV2RGB, yuv);
return mul(YUV2RGB, YUV);
#endif
}
@ -1411,13 +1390,14 @@ float4 CelPass(float4 color, float2 texcoord)
{
float3 yuv;
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;
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.00, -0.0078125),
float2(0.0078125, -0.0078125),
@ -1428,32 +1408,31 @@ float4 CelPass(float4 color, float2 texcoord)
float2(0.00, 0.0078125),
float2(0.0078125, 0.0078125) };
float3 col[NUM];
float lum[NUM];
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)
col[i].r = saturate(round(col[i].r * thresholds.r) / thresholds.r);
col[i].g = saturate(round(col[i].g * thresholds.g) / thresholds.g);
col[i].b = saturate(round(col[i].b * thresholds.b) / thresholds.b);
col[i].r = round(col[i].r * thresholds.r) / thresholds.r;
col[i].g = round(col[i].g * thresholds.g) / thresholds.g;
col[i].b = round(col[i].b * thresholds.b) / thresholds.b;
#endif
lum[i] = RGBLuminance(col[i].xyz);
yuv = GetYUV(col[i]);
if (UseYuvLuma == 0)
{ yuv.r = saturate(round(yuv.r * lum[i]) / thresholds.r + lum[i]); }
else
{ yuv.r = saturate(round(yuv.r * thresholds.r) / thresholds.r + lum[i] / (255.0 / 5.0)); }
#if (UseYuvLuma == 0)
yuv.r = round(yuv.r * thresholds.r) / thresholds.r;
#else
yuv.r = saturate(round(yuv.r * lum[i]) / thresholds.r + lum[i]);
#endif
yuv = GetRGB(yuv);
sum += yuv;
}
float3 shadedColor = (sum / NUM);
float2 pixel = float2(pixelSize.x * EdgeThickness, pixelSize.y * EdgeThickness);
float edgeX = dot(sample_tex(TextureSampler, texcoord + pixel).rgb, lumCoeff);
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)
color.rgb = lerp(color.rgb, color.rgb + pow(edge, EdgeFilter) * -EdgeStrength, EdgeStrength);
#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)
color.rgb = lerp(shadedColor + edge * -EdgeStrength, pow(edge, EdgeFilter) * -EdgeStrength + color.rgb, 0.5);
#endif
@ -1540,17 +1519,11 @@ float HueLerp(float h1, float h2, float v)
float d = abs(h1 - h2);
if (d <= 0.5)
{
return lerp(h1, h2, v);
}
{ return lerp(h1, h2, v); }
else if (h1 < h2)
{
return frac(lerp((h1 + 1.0), h2, v));
}
{ return frac(lerp((h1 + 1.0), h2, v)); }
else
{
return frac(lerp(h1, (h2 + 1.0), v));
}
{ return frac(lerp(h1, (h2 + 1.0), v)); }
}
float4 ColorGrading(float4 color, float2 texcoord)
@ -1701,9 +1674,9 @@ float4 BorderPass(float4 colorInput, float2 tex)
#if (GLSL == 1)
// FIXME GLSL any only support bvec so try to mix it with notEqual
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
colorInput.rgb = all(within_border) ? colorInput.rgb : border_color_float; //
colorInput.rgb = all(within_border) ? colorInput.rgb : border_color_float;
#endif
return colorInput;
@ -1796,14 +1769,14 @@ PS_OUTPUT ps_main(VS_OUTPUT input)
color = VignettePass(color, texcoord);
#endif
#if (DITHERING == 1)
color = DitherPass(color, texcoord);
#endif
#if (PX_BORDER == 1)
color = BorderPass(color, texcoord);
#endif
#if (DITHERING == 1)
color = DitherPass(color, texcoord);
#endif
#if (GLSL == 1)
SV_Target0 = color;
#else