Cosmetic code cleanup of some GLSL shader code.

This commit is contained in:
Leon Styhre 2021-05-14 15:12:53 +02:00
parent 9e24121855
commit fddf099a74
3 changed files with 129 additions and 146 deletions

View file

@ -1,10 +1,11 @@
//
// Implementation based on the article "Efficient Gaussian blur with linear sampling"
// http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/
/* A version for MasterEffect Reborn, a standalone version, and a custom shader version for SweetFX can be
found at http://reshade.me/forum/shader-presentation/27-gaussian-blur-bloom-unsharpmask */
/*-----------------------------------------------------------.
/ Gaussian Blur settings /
'-----------------------------------------------------------*/
// A version for MasterEffect Reborn, a standalone version, and a custom shader version for SweetFX
// can be found at http://reshade.me/forum/shader-presentation/27-gaussian-blur-bloom-unsharpmask
//
// Borrowed from the RetroArch project and modified for ES-DE by Leon Styhre.
//
#define HW 1.00
@ -43,10 +44,8 @@ uniform COMPAT_PRECISION vec2 InputSize;
void main()
{
gl_Position = MVPMatrix * gl_Vertex;
// gl_Position = MVPMatrix * VertexCoord;
COL0 = COLOR;
TEX0.xy = gl_MultiTexCoord0.xy;
// TEX0.xy = TexCoord.xy;
}
#elif defined(FRAGMENT)
@ -80,18 +79,18 @@ uniform COMPAT_PRECISION vec2 InputSize;
uniform sampler2D Texture;
COMPAT_VARYING vec4 TEX0;
// compatibility #defines
// Compatibility #defines
#define Source Texture
#define vTexCoord TEX0.xy
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) // Either TextureSize or InputSize.
#define outsize vec4(OutputSize, 1.0 / OutputSize)
void main()
{
vec2 texcoord = vTexCoord;
// vec2 PIXEL_SIZE = SourceSize.zw;
vec2 PIXEL_SIZE = vec2(SourceSize.z, SourceSize.w);
#if __VERSION__ < 130
float sampleOffsets1 = 0.0;
float sampleOffsets2 = 1.4347826;
@ -109,7 +108,6 @@ void main()
vec4 color = COMPAT_TEXTURE(Source, texcoord);
color = vec4(color.rgb, 1.0) * sampleWeights1;
// unroll the loop
color += COMPAT_TEXTURE(Source, texcoord + vec2(sampleOffsets2 * HW * PIXEL_SIZE.x, 0.0)) * sampleWeights2;
color += COMPAT_TEXTURE(Source, texcoord - vec2(sampleOffsets2 * HW * PIXEL_SIZE.x, 0.0)) * sampleWeights2;
@ -127,7 +125,7 @@ void main()
float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
vec4 color = COMPAT_TEXTURE(Source, texcoord) * sampleWeights[0];
for(int i = 1; i < 5; ++i) {
for (int i = 1; i < 5; i++) {
color += COMPAT_TEXTURE(Source, texcoord + vec2(sampleOffsets[i] * HW * PIXEL_SIZE.x, 0.0)) * sampleWeights[i];
color += COMPAT_TEXTURE(Source, texcoord - vec2(sampleOffsets[i] * HW * PIXEL_SIZE.x, 0.0)) * sampleWeights[i];
}

View file

@ -1,10 +1,11 @@
//
// Implementation based on the article "Efficient Gaussian blur with linear sampling"
// http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/
/* A version for MasterEffect Reborn, a standalone version, and a custom shader version for SweetFX can be
found at http://reshade.me/forum/shader-presentation/27-gaussian-blur-bloom-unsharpmask */
/*-----------------------------------------------------------.
/ Gaussian Blur settings /
'-----------------------------------------------------------*/
// A version for MasterEffect Reborn, a standalone version, and a custom shader version for SweetFX
// can be found at http://reshade.me/forum/shader-presentation/27-gaussian-blur-bloom-unsharpmask
//
// Borrowed from the RetroArch project and modified for ES-DE by Leon Styhre.
//
#define VW 1.00
@ -31,7 +32,6 @@ COMPAT_ATTRIBUTE vec4 COLOR;
COMPAT_ATTRIBUTE vec4 TexCoord;
COMPAT_VARYING vec4 COL0;
COMPAT_VARYING vec4 TEX0;
// out variables go here as COMPAT_VARYING whatever
vec4 _oPosition1;
uniform mat4 MVPMatrix;
@ -44,10 +44,8 @@ uniform COMPAT_PRECISION vec2 InputSize;
void main()
{
gl_Position = MVPMatrix * gl_Vertex;
// gl_Position = MVPMatrix * VertexCoord;
COL0 = COLOR;
TEX0.xy = gl_MultiTexCoord0.xy;
// TEX0.xy = TexCoord.xy;
}
#elif defined(FRAGMENT)
@ -85,14 +83,14 @@ COMPAT_VARYING vec4 TEX0;
#define Source Texture
#define vTexCoord TEX0.xy
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) // Either TextureSize or InputSize.
#define outsize vec4(OutputSize, 1.0 / OutputSize)
void main()
{
vec2 texcoord = vTexCoord;
// vec2 PIXEL_SIZE = SourceSize.zw;
vec2 PIXEL_SIZE = vec2(SourceSize.z, SourceSize.w);
#if __VERSION__ < 130
float sampleOffsets1 = 0.0;
float sampleOffsets2 = 1.4347826;
@ -110,7 +108,6 @@ void main()
vec4 color = COMPAT_TEXTURE(Source, texcoord);
color = vec4(color.rgb, 1.0) * sampleWeights1;
// unroll the loop
color += COMPAT_TEXTURE(Source, texcoord + vec2(0.0, sampleOffsets2 * VW * PIXEL_SIZE.y)) * sampleWeights2;
color += COMPAT_TEXTURE(Source, texcoord - vec2(0.0, sampleOffsets2 * VW * PIXEL_SIZE.y)) * sampleWeights2;
@ -128,7 +125,7 @@ void main()
float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
vec4 color = COMPAT_TEXTURE(Source, texcoord) * sampleWeights[0];
for(int i = 1; i < 5; ++i) {
for (int i = 1; i < 5; i++) {
color += COMPAT_TEXTURE(Source, texcoord + vec2(0.0, sampleOffsets[i] * VW * PIXEL_SIZE.y)) * sampleWeights[i];
color += COMPAT_TEXTURE(Source, texcoord - vec2(0.0, sampleOffsets[i] * VW * PIXEL_SIZE.y)) * sampleWeights[i];
}

View file

@ -1,34 +1,24 @@
/*
Phosphor shader - Copyright (C) 2011 caligari.
Ported by Hyllian.
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Parameter lines go here:
// 0.5 = the spot stays inside the original pixel
// 1.0 = the spot bleeds up to the center of next pixel
// #pragma parameter SPOT_WIDTH "CRTCaligari Spot Width" 0.9 0.1 1.5 0.05
// #pragma parameter SPOT_HEIGHT "CRTCaligari Spot Height" 0.75 0.1 1.5 0.05
// Used to counteract the desaturation effect of weighting.
// #pragma parameter COLOR_BOOST "CRTCaligari Color Boost" 1.45 1.0 2.0 0.05
// Constants used with gamma correction.
// #pragma parameter InputGamma "CRTCaligari Input Gamma" 2.4 0.0 5.0 0.1
// #pragma parameter OutputGamma "CRTCaligari Output Gamma" 2.2 0.0 5.0 0.1
//
// Phosphor shader - Copyright (C) 2011 caligari.
//
// Ported by Hyllian.
//
// 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.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// Borrowed from the RetroArch project and modified for ES-DE by Leon Styhre.
//
#if defined(VERTEX)
@ -64,15 +54,13 @@ uniform COMPAT_PRECISION vec2 OutputSize;
uniform COMPAT_PRECISION vec2 TextureSize;
uniform COMPAT_PRECISION vec2 InputSize;
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) // Either TextureSize or InputSize.
void main()
{
gl_Position = MVPMatrix * gl_Vertex;
// gl_Position = MVPMatrix * VertexCoord;
COL0 = COLOR;
TEX0.xy = gl_MultiTexCoord0.xy;
// TEX0.xy = TexCoord.xy;
onex = vec2(SourceSize.z, 0.0);
oney = vec2(0.0, SourceSize.w);
}
@ -110,15 +98,15 @@ COMPAT_VARYING vec4 TEX0;
COMPAT_VARYING vec2 onex;
COMPAT_VARYING vec2 oney;
// compatibility #defines
// Compatibility #defines
#define Source Texture
#define vTexCoord TEX0.xy
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) // Either TextureSize or InputSize.
#define OutputSize vec4(OutputSize, 1.0 / OutputSize)
#ifdef PARAMETER_UNIFORM
// All parameter floats need to have COMPAT_PRECISION in front of them
// All parameter floats need to have COMPAT_PRECISION in front of them.
uniform COMPAT_PRECISION float SPOT_WIDTH;
uniform COMPAT_PRECISION float SPOT_HEIGHT;
uniform COMPAT_PRECISION float COLOR_BOOST;
@ -137,7 +125,7 @@ uniform COMPAT_PRECISION float OutputGamma;
#define TEX2D(coords) GAMMA_IN(COMPAT_TEXTURE(Source, coords))
// Macro for weights computing
// Macro for weights computing.
#define WEIGHT(w) \
if (w > 1.0) w = 1.0; \
w = 1.0 - w * w; \
@ -158,12 +146,13 @@ void main()
color *= vec4( h_weight_00, h_weight_00, h_weight_00, h_weight_00 );
// get closest horizontal neighbour to blend
// Get closest horizontal neighbour to blend.
vec2 coords01;
if (dx > 0.0) {
coords01 = onex;
dx = 1.0 - dx;
} else {
}
else {
coords01 = -onex;
dx = 1.0 + dx;
}
@ -174,8 +163,7 @@ void main()
color = color + colorNB * vec4(h_weight_01);
//////////////////////////////////////////////////////
// Vertical Blending
// Vertical blending.
float dy = coords.y - pixel_center.y;
float v_weight_00 = dy / SPOT_HEIGHT;
WEIGHT(v_weight_00);
@ -186,7 +174,8 @@ void main()
if (dy > 0.0) {
coords10 = oney;
dy = 1.0 - dy;
} else {
}
else {
coords10 = -oney;
dy = 1.0 + dy;
}
@ -195,12 +184,11 @@ void main()
float v_weight_10 = dy / SPOT_HEIGHT;
WEIGHT(v_weight_10);
color = color + colorNB * vec4( v_weight_10 * h_weight_00, v_weight_10 * h_weight_00, v_weight_10 * h_weight_00, v_weight_10 * h_weight_00 );
color = color + colorNB * vec4(v_weight_10 * h_weight_00, v_weight_10 * h_weight_00,
v_weight_10 * h_weight_00, v_weight_10 * h_weight_00);
colorNB = TEX2D(texture_coords + coords01 + coords10);
color = color + colorNB * vec4( v_weight_10 * h_weight_01, v_weight_10 * h_weight_01, v_weight_10 * h_weight_01, v_weight_10 * h_weight_01 );
color = color + colorNB * vec4(v_weight_10 * h_weight_01, v_weight_10 * h_weight_01,
v_weight_10 * h_weight_01, v_weight_10 * h_weight_01);
color *= vec4(COLOR_BOOST);
FragColor = clamp(GAMMA_OUT(color), 0.0, 1.0);