Pixel-Composer/shaders/sh_convolution/sh_convolution.fsh

46 lines
1.3 KiB
Text
Raw Normal View History

2023-01-04 02:30:04 +01:00
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
uniform float kernel[9];
2023-01-17 08:11:55 +01:00
uniform int sampleMode;
vec4 sampleTexture(vec2 pos) {
if(pos.x >= 0. && pos.y >= 0. && pos.x <= 1. && pos.y <= 1.)
return texture2D(gm_BaseTexture, pos);
if(sampleMode == 0)
return vec4(0.);
2024-02-15 14:23:26 +01:00
else if(sampleMode == 1)
2023-01-17 08:11:55 +01:00
return texture2D(gm_BaseTexture, clamp(pos, 0., 1.));
2024-02-15 14:23:26 +01:00
else if(sampleMode == 2)
2023-01-17 08:11:55 +01:00
return texture2D(gm_BaseTexture, fract(pos));
2024-02-15 14:23:26 +01:00
else if(sampleMode == 3)
return vec4(vec3(0.), 1.);
2023-01-17 08:11:55 +01:00
return vec4(0.);
}
2023-01-04 02:30:04 +01:00
void main() {
vec2 tex = 1. / dimension;
2023-01-17 08:11:55 +01:00
vec4 c = + kernel[0] * sampleTexture( v_vTexcoord + vec2(-tex.x, -tex.y) )
+ kernel[1] * sampleTexture( v_vTexcoord + vec2( 0., -tex.y) )
+ kernel[2] * sampleTexture( v_vTexcoord + vec2( tex.x, -tex.y) )
2023-01-04 02:30:04 +01:00
2023-01-17 08:11:55 +01:00
+ kernel[3] * sampleTexture( v_vTexcoord + vec2(-tex.x, 0.) )
+ kernel[4] * sampleTexture( v_vTexcoord + vec2( 0., 0.) )
+ kernel[5] * sampleTexture( v_vTexcoord + vec2( tex.x, 0.) )
2023-01-04 02:30:04 +01:00
2023-01-17 08:11:55 +01:00
+ kernel[6] * sampleTexture( v_vTexcoord + vec2(-tex.x, tex.y) )
+ kernel[7] * sampleTexture( v_vTexcoord + vec2( 0., tex.y) )
+ kernel[8] * sampleTexture( v_vTexcoord + vec2( tex.x, tex.y) );
2023-01-04 02:30:04 +01:00
2023-01-09 03:14:20 +01:00
gl_FragColor = vec4(c.rgb, 1.);
2023-01-04 02:30:04 +01:00
}