75 lines
1.8 KiB
Plaintext
75 lines
1.8 KiB
Plaintext
// __multiversion__
|
|
// This signals the loading code to prepend either #version 100 or #version 300 es as apropriate.
|
|
|
|
// To use centroid sampling we need to have version 300 es shaders, which requires changing:
|
|
// attribute to in
|
|
// varying to out when in vertex shaders or in when in fragment shaders
|
|
// defining an out vec4 FragColor and replacing uses of gl_FragColor with FragColor
|
|
// texture2D to texture
|
|
#if __VERSION__ >= 300
|
|
|
|
// version 300 code
|
|
|
|
#ifdef MSAA_FRAMEBUFFER_ENABLED
|
|
#define _centroid centroid
|
|
#else
|
|
#define _centroid
|
|
#endif
|
|
|
|
_centroid in vec2 uv;
|
|
#define varying in
|
|
#define texture2D texture
|
|
out vec4 FragColor;
|
|
#define gl_FragColor FragColor
|
|
|
|
#else
|
|
// version 100 code
|
|
varying vec2 uv;
|
|
#endif
|
|
|
|
|
|
#ifndef BLUR_RADIUS
|
|
#define BLUR_RADIUS 1 //base size
|
|
#endif
|
|
|
|
//HACK do not build higher res versions on gles2
|
|
#if __VERSION__ < 300 && BLUR_RADIUS > 2
|
|
#undef BLUR_RADIUS
|
|
#define BLUR_RADIUS 2
|
|
#endif
|
|
|
|
const int R = BLUR_RADIUS / 2;
|
|
|
|
uniform vec3 TEXTURE_DIMENSIONS;
|
|
uniform vec4 CURRENT_COLOR;
|
|
uniform sampler2D TEXTURE_0;
|
|
|
|
void main()
|
|
{
|
|
vec2 pixelSide = vec2(1.0 / TEXTURE_DIMENSIONS.xy);
|
|
|
|
#if BLUR_RADIUS == 1
|
|
vec4 color = texture2D( TEXTURE_0, uv);
|
|
#else
|
|
vec4 color = vec4(0.0);
|
|
for(int i = -R; i < R; ++i) {
|
|
for(int j = -R; j < R; ++j) {
|
|
vec2 sampleUV = uv + pixelSide * vec2(j, i);
|
|
sampleUV = mod(sampleUV, vec2(1.0));
|
|
|
|
color += texture2D( TEXTURE_0, sampleUV);
|
|
}
|
|
}
|
|
|
|
color /= float(BLUR_RADIUS * BLUR_RADIUS);
|
|
#endif
|
|
|
|
color.rgb = mix(color.rgb, CURRENT_COLOR.rgb * color.rgb, color.a * CURRENT_COLOR.a);
|
|
if(CURRENT_COLOR.a > 0.0) {
|
|
//the alpha in diffuse is a mask
|
|
color.a = 1.0;
|
|
}
|
|
|
|
gl_FragColor = color;
|
|
}
|