Added ContourPoints and Threshold filters
This commit is contained in:
@@ -12,10 +12,14 @@ class JumpFlood : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/jumpflood
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PixelDistance : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/pixel-distance.frag")))
|
class PixelDistance : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/pixel-distance.frag")))
|
||||||
|
class ContourPoints : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/contour-points.frag")))
|
||||||
|
class Threshold : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/threshold.frag")))
|
||||||
|
|
||||||
val encodePoints by lazy { EncodePoints() }
|
val encodePoints by lazy { EncodePoints() }
|
||||||
val jumpFlood by lazy { JumpFlood() }
|
val jumpFlood by lazy { JumpFlood() }
|
||||||
val pixelDistance by lazy { PixelDistance() }
|
val pixelDistance by lazy { PixelDistance() }
|
||||||
|
val contourPoints by lazy { ContourPoints() }
|
||||||
|
val threshold by lazy { Threshold() }
|
||||||
|
|
||||||
/** [points] is square and power of 2 */
|
/** [points] is square and power of 2 */
|
||||||
fun jumpFlood(points: ColorBuffer, coordinates: List<ColorBuffer>) {
|
fun jumpFlood(points: ColorBuffer, coordinates: List<ColorBuffer>) {
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
uniform sampler2D tex0;
|
||||||
|
in vec2 v_texCoord0;
|
||||||
|
|
||||||
|
out vec4 o_color;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec2 step = 1.0 / textureSize(tex0, 0);
|
||||||
|
float ref = step(0.5 , texture(tex0, v_texCoord0).r);
|
||||||
|
vec4 outc = vec4(-1.0, -1.0, 0.0, 1.0);
|
||||||
|
|
||||||
|
float contour = 0.0;
|
||||||
|
for (int y = -1; y <= 1; ++y) {
|
||||||
|
for (int x = -1; x <= 1; ++x) {
|
||||||
|
float smp = step(0.5, texture(tex0, v_texCoord0 + vec2(x,y) * step).r);
|
||||||
|
if (smp != ref) {
|
||||||
|
contour = 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
o_color = vec4(contour, contour, contour, 1.0);
|
||||||
|
}
|
||||||
13
orx-jumpflood/src/main/resources/shaders/gl3/threshold.frag
Normal file
13
orx-jumpflood/src/main/resources/shaders/gl3/threshold.frag
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
uniform sampler2D tex0;
|
||||||
|
in vec2 v_texCoord0;
|
||||||
|
uniform float threshold;
|
||||||
|
out vec4 o_color;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
float ref = step(threshold , dot( vec3(1.0/3.0), texture(tex0, v_texCoord0).rgb ));
|
||||||
|
|
||||||
|
|
||||||
|
o_color = vec4(ref, ref, ref, 1.0);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user