diff --git a/README.md b/README.md index f3f2f612..1ec93792 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,6 @@ repositories { Add dependency: ``` dependencies { - compile 'com.github.openrndr:orx:v0.0.7' + compile 'com.github.openrndr.orx::v0.0.7' } ``` \ No newline at end of file diff --git a/build.gradle b/build.gradle index b881630f..cf28761a 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ repositories { } ext { - openrndrVersion = "0.3.26" + openrndrVersion = "0.3.27" } diff --git a/orx-jumpflood/src/main/kotlin/JumpFlood.kt b/orx-jumpflood/src/main/kotlin/JumpFlood.kt index 8c1be3ec..8589289f 100644 --- a/orx-jumpflood/src/main/kotlin/JumpFlood.kt +++ b/orx-jumpflood/src/main/kotlin/JumpFlood.kt @@ -3,6 +3,7 @@ package org.openrndr.extra.jumpfill import org.openrndr.draw.* import org.openrndr.filter.filterShaderFromUrl import org.openrndr.math.Matrix44 +import org.openrndr.math.Vector2 import org.openrndr.resourceUrl class EncodePoints : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/encode-points.frag"))) @@ -15,6 +16,7 @@ class PixelDistance : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/pixel class ContourPoints : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/contour-points.frag"))) class Threshold : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/threshold.frag"))) { var threshold by parameters + init { threshold = 0.5 } @@ -46,7 +48,25 @@ class JumpFlooder(val width: Int, val height: Int) { colorBuffer() } - fun jumpFlood(drawer: Drawer, input: ColorBuffer) { + private var contourUsed = false + private val thresholded by lazy { colorBuffer(width, height) } + private val edges by lazy { colorBuffer(width, height) } + + fun distanceToContour(drawer: Drawer, input: ColorBuffer, thresholdValue: Double = 0.5): ColorBuffer { + threshold.threshold = thresholdValue + threshold.apply(input, thresholded) + contourPoints.apply(thresholded, edges) + contourUsed = true + return jumpFlood(drawer, edges) + } + + fun directions(xRange: IntProgression = 0 until width, yRange: IntProgression = 0 until height): Array> { + result.shadow.download() + return result.shadow.mapIndexed(xRange, yRange) { _, _, r, g, _, _ -> Vector2(r, g) } + } + + + fun jumpFlood(drawer: Drawer, input: ColorBuffer): ColorBuffer { if (input.width != width || input.height != height) { throw IllegalArgumentException("dimensions mismatch") } @@ -71,6 +91,7 @@ class JumpFlooder(val width: Int, val height: Int) { drawer.model = Matrix44.IDENTITY drawer.image(coordinates[exp % 2]) } + return result } fun destroy(destroyFinal: Boolean = true) { @@ -87,6 +108,11 @@ class JumpFlooder(val width: Int, val height: Int) { final.destroy() + if (contourUsed) { + edges.destroy() + thresholded.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 index 32d2cc03..7a5c2079 100644 --- a/orx-jumpflood/src/main/resources/shaders/gl3/pixel-distance.frag +++ b/orx-jumpflood/src/main/resources/shaders/gl3/pixel-distance.frag @@ -9,7 +9,7 @@ void main() { vec2 size = textureSize(tex0, 0); vec2 pixelPosition = v_texCoord0; vec2 centroidPixelPosition = texture(tex0, v_texCoord0).xy; - vec2 pixelDistance = (centroidPixelPosition - pixelPosition) * size; + vec2 pixelDistance = (centroidPixelPosition - pixelPosition) * size * vec2(1.0, -1.0); o_color = vec4(pixelDistance, 0.0, 1.0); } \ No newline at end of file