Pixel-Composer/shaders/sh_find_boundary/sh_find_boundary.fsh

57 lines
1.1 KiB
Plaintext
Raw Normal View History

2023-03-05 07:16:44 +01:00
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
2023-06-13 14:42:06 +02:00
uniform vec4 bbox;
2023-03-05 07:16:44 +01:00
uniform int mode;
2023-06-10 13:59:45 +02:00
uniform sampler2D texture;
2023-03-05 07:16:44 +01:00
void main() {
2023-06-10 13:59:45 +02:00
float _w = dimension.x;
float _h = dimension.y;
vec4 col;
float i, j;
2023-03-05 07:16:44 +01:00
2023-06-13 14:42:06 +02:00
if(mode == 0) { //minx
for( i = 0.; i < _w; i++ )
for( j = 0.; j < _h; j++ ) {
col = texture2D( texture, vec2(i, j) / dimension);
2023-06-10 13:59:45 +02:00
if(col.r > 0.) {
2023-06-13 14:42:06 +02:00
gl_FragColor = vec4(i);
return;
2023-06-10 13:59:45 +02:00
}
}
2023-06-13 14:42:06 +02:00
} else if(mode == 1) { //miny
for( i = 0.; i < _h; i++ )
for( j = bbox.x; j < _w; j++ ) {
2023-06-10 13:59:45 +02:00
col = texture2D( texture, vec2(j, i) / dimension);
if(col.r > 0.) {
2023-06-13 14:42:06 +02:00
gl_FragColor = vec4(i);
return;
2023-06-10 13:59:45 +02:00
}
}
2023-06-13 14:42:06 +02:00
} else if(mode == 2) { //maxx
for( i = _w; i > bbox.x; i-- )
for( j = bbox.y; j < _h; j++ ) {
col = texture2D( texture, vec2(i, j) / dimension);
2023-06-10 13:59:45 +02:00
if(col.r > 0.) {
2023-06-13 14:42:06 +02:00
gl_FragColor = vec4(i);
return;
2023-06-10 13:59:45 +02:00
}
}
2023-06-13 14:42:06 +02:00
} else if(mode == 3) { //maxy
for( i = _h; i > bbox.y; i-- )
for( j = bbox.x; j < bbox.z; j++ ) {
2023-06-10 13:59:45 +02:00
col = texture2D( texture, vec2(j, i) / dimension);
if(col.r > 0.) {
2023-06-13 14:42:06 +02:00
gl_FragColor = vec4(i);
return;
2023-06-10 13:59:45 +02:00
}
}
2023-06-13 14:42:06 +02:00
}
2023-03-05 07:16:44 +01:00
}