mirror of
https://github.com/libretro/glsl-shaders.git
synced 2024-12-11 17:42:10 +00:00
110 lines
3.0 KiB
Plaintext
110 lines
3.0 KiB
Plaintext
|
// 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 /
|
||
|
'-----------------------------------------------------------*/
|
||
|
|
||
|
#define VW 1.00
|
||
|
|
||
|
#if defined(VERTEX)
|
||
|
|
||
|
#if __VERSION__ >= 130
|
||
|
#define COMPAT_VARYING out
|
||
|
#define COMPAT_ATTRIBUTE in
|
||
|
#define COMPAT_TEXTURE texture
|
||
|
#else
|
||
|
#define COMPAT_VARYING varying
|
||
|
#define COMPAT_ATTRIBUTE attribute
|
||
|
#define COMPAT_TEXTURE texture2D
|
||
|
#endif
|
||
|
|
||
|
#ifdef GL_ES
|
||
|
#define COMPAT_PRECISION mediump
|
||
|
#else
|
||
|
#define COMPAT_PRECISION
|
||
|
#endif
|
||
|
|
||
|
COMPAT_ATTRIBUTE vec4 VertexCoord;
|
||
|
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;
|
||
|
uniform int FrameDirection;
|
||
|
uniform int FrameCount;
|
||
|
uniform COMPAT_PRECISION vec2 OutputSize;
|
||
|
uniform COMPAT_PRECISION vec2 TextureSize;
|
||
|
uniform COMPAT_PRECISION vec2 InputSize;
|
||
|
|
||
|
void main()
|
||
|
{
|
||
|
gl_Position = MVPMatrix * VertexCoord;
|
||
|
COL0 = COLOR;
|
||
|
TEX0.xy = TexCoord.xy;
|
||
|
// Paste vertex contents here:
|
||
|
|
||
|
}
|
||
|
|
||
|
#elif defined(FRAGMENT)
|
||
|
|
||
|
#if __VERSION__ >= 130
|
||
|
#define COMPAT_VARYING in
|
||
|
#define COMPAT_TEXTURE texture
|
||
|
out vec4 FragColor;
|
||
|
#else
|
||
|
#define COMPAT_VARYING varying
|
||
|
#define FragColor gl_FragColor
|
||
|
#define COMPAT_TEXTURE texture2D
|
||
|
#endif
|
||
|
|
||
|
#ifdef GL_ES
|
||
|
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
||
|
precision highp float;
|
||
|
#else
|
||
|
precision mediump float;
|
||
|
#endif
|
||
|
#define COMPAT_PRECISION mediump
|
||
|
#else
|
||
|
#define COMPAT_PRECISION
|
||
|
#endif
|
||
|
|
||
|
uniform int FrameDirection;
|
||
|
uniform int FrameCount;
|
||
|
uniform COMPAT_PRECISION vec2 OutputSize;
|
||
|
uniform COMPAT_PRECISION vec2 TextureSize;
|
||
|
uniform COMPAT_PRECISION vec2 InputSize;
|
||
|
uniform sampler2D Texture;
|
||
|
COMPAT_VARYING vec4 TEX0;
|
||
|
// in variables go here as COMPAT_VARYING whatever
|
||
|
|
||
|
// compatibility #defines
|
||
|
#define Source Texture
|
||
|
#define vTexCoord TEX0.xy
|
||
|
#define texture(c, d) COMPAT_TEXTURE(c, d)
|
||
|
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
|
||
|
#define OutputSize vec4(OutputSize, 1.0 / OutputSize)
|
||
|
|
||
|
// delete all 'params.' or 'registers.' or whatever in the fragment
|
||
|
|
||
|
void main()
|
||
|
{
|
||
|
vec2 texcoord = vTexCoord;
|
||
|
vec2 PIXEL_SIZE = SourceSize.zw;
|
||
|
|
||
|
float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
|
||
|
float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
|
||
|
|
||
|
vec4 color = texture(Source, texcoord) * sampleWeights[0];
|
||
|
for(int i = 1; i < 5; ++i) {
|
||
|
color += texture(Source, texcoord + vec2(0.0, sampleOffsets[i]*VW * PIXEL_SIZE.y)) * sampleWeights[i];
|
||
|
color += texture(Source, texcoord - vec2(0.0, sampleOffsets[i]*VW * PIXEL_SIZE.y)) * sampleWeights[i];
|
||
|
}
|
||
|
FragColor = vec4(color);
|
||
|
}
|
||
|
#endif
|