diff --git a/build.gradle b/build.gradle index 87d787a0..42ffcafb 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { allprojects { group 'org.openrndr.extra' - version '0.0.2-1' + version '0.0.5' } repositories { @@ -24,7 +24,7 @@ subprojects { mavenLocal() mavenCentral() maven { - url="https://dl.bintray.com/openrndr/openrndr" + url = "https://dl.bintray.com/openrndr/openrndr" } } diff --git a/orx-jumpflood/src/main/kotlin/JumpFlood.kt b/orx-jumpflood/src/main/kotlin/JumpFlood.kt index 8d783e08..79cb8993 100644 --- a/orx-jumpflood/src/main/kotlin/JumpFlood.kt +++ b/orx-jumpflood/src/main/kotlin/JumpFlood.kt @@ -5,29 +5,29 @@ import org.openrndr.filter.filterShaderFromUrl import org.openrndr.math.Matrix44 import org.openrndr.resourceUrl -class EncodePoints: Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/encode-points.frag"))) -class JumpFlood: Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/jumpflood.frag"))) { +class EncodePoints : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/encode-points.frag"))) +class JumpFlood : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/jumpflood.frag"))) { var maxSteps: Int by parameters var step: Int by parameters } +class PixelDistance : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/pixel-distance.frag"))) + val encodePoints by lazy { EncodePoints() } val jumpFlood by lazy { JumpFlood() } +val pixelDistance by lazy { PixelDistance() } /** [points] is square and power of 2 */ -fun jumpFlood(points:ColorBuffer, coordinates:List) { +fun jumpFlood(points: ColorBuffer, coordinates: List) { encodePoints.apply(points, coordinates[0]) val exp = Math.ceil(Math.log(points.width.toDouble()) / Math.log(2.0)).toInt() for (i in 0 until exp) { jumpFlood.step = i jumpFlood.apply(coordinates[i % 2], coordinates[(i + 1) % 2]) - } - } -fun jumpFlood(drawer: Drawer, points:ColorBuffer): ColorBuffer { - +fun jumpFlood(drawer: Drawer, points: ColorBuffer): ColorBuffer { val dimension = Math.max(points.width, points.height) val exp = Math.ceil(Math.log(dimension.toDouble()) / Math.log(2.0)).toInt() val squareDim = Math.pow(2.0, exp.toDouble()).toInt() @@ -47,6 +47,7 @@ fun jumpFlood(drawer: Drawer, points:ColorBuffer): ColorBuffer { drawer.image(points) } + jumpFlood(rt.colorBuffer(0), coordinates) // encodePoints.apply(rt.colorBuffer(0), coordinates[0]) @@ -62,14 +63,17 @@ fun jumpFlood(drawer: Drawer, points:ColorBuffer): ColorBuffer { colorBuffer(type = ColorType.FLOAT32) } + pixelDistance.apply(coordinates[exp % 2], coordinates[exp % 2]) + drawer.isolatedWithTarget(final) { drawer.ortho(final) drawer.view = Matrix44.IDENTITY drawer.model = Matrix44.IDENTITY - drawer.image(coordinates[exp%2]) - + drawer.image(coordinates[exp % 2]) } + coordinates.forEach { it.destroy() } + rt.colorBuffer(0).destroy() rt.detachColorBuffers() rt.destroy() diff --git a/orx-jumpflood/src/main/resources/shaders/gl3/pixel-distance.frag b/orx-jumpflood/src/main/resources/shaders/gl3/pixel-distance.frag new file mode 100644 index 00000000..2ad2571f --- /dev/null +++ b/orx-jumpflood/src/main/resources/shaders/gl3/pixel-distance.frag @@ -0,0 +1,15 @@ +#version 330 core + +uniform sampler2D tex0; +in vec2 v_texCoord0; + +out vec4 o_color; + +void main() { + vec2 size = textureSize(tex0, 0); + vec2 pixelPosition = v_texCoord0 * size; + vec2 centroidPixelPosition = texture(tex0, v_texCoord0).xy * size; + vec2 pixelDistance = centroidPixelPosition - pixelPosition; + + o_color = vec4(pixelDistance, 0.0, 1.0); +} \ No newline at end of file