texture2D:function is removed in Forward Compatibile context
#version 150
#define SIZE 25
// A texture is expected
uniform sampler2D Texture;
// The vertex shader fill feed this input
in vec2 FragTexCoord;
// The final color
out vec4 FragmentColor;
float matr[25];
float matg[25];
float matb[25];
vec4 get_pixel(in vec2 coords, in float x, in float y) {
return texture(Texture, coords + vec2(x, y));
}
float convolve(in float[SIZE] kernel, in float[SIZE] matrix) {
float res = 0.0;
for (int i = 0; i < 25; i++)
res += kernel[i] * matrix[i];
return clamp(res, 0.0, 1.0);
}
void fill_matrix() {
float dxtex = 1.0 / float(textureSize(Texture, 0));
float dytex = 1.0 / float(textureSize(Texture, 0));
float[25] mat;
for (int i = 0; i < 5; i++)
for(int j = 0; j < 5; j++) {
vec4 pixel = get_pixel(FragTexCoord,float(i - 2) * dxtex, float(j - 2) * dytex);
matr[i * 5 + j] = pixel[0];
matg[i * 5 + j] = pixel[1];
matb[i * 5 + j] = pixel[2];
}
}
void main() {
float[SIZE] ker_edge_detection = float[SIZE] (
.0,.0, -1., .0, .0,
.0, .0,-1., .0, .0,
.0, .0, 4., .0, .0,
.0, .0, -1., .0,.0,
.0, .0, -1., .0, .0
);
fill_matrix();
FragmentColor = vec4(convolve(ker_edge_detection,matr), convolve(ker_edge_detection,matg), convolve(ker_edge_detection,matb), 1.0);
}
Are there any code examples left?
New code examples in category Other
-
Other 2023-03-27 22:50:10 how to select the whole line in vscode with keyboard shortcut
-
Other 2022-03-27 22:45:24 income of a web developer
-
Other 2022-03-27 22:35:01 \pyrcc_main.py: File does not exist 'resources.qrc'
-
Other 2022-03-27 22:30:45 rick roll embed code
-
Other 2022-03-27 22:20:08 Circuit_04_Potentiometer
-
Other 2022-03-27 22:20:05 iterative power
-
Other 2022-03-27 22:15:11 flutter run all
-
Other 2022-03-27 22:10:05 when is karlson release
-
Other 2022-03-27 22:10:02 wp .htaccess example
-
Other 2022-03-27 22:00:08 bash pause in file read line by line