Fix vertical direction
This commit is contained in:
@@ -19,6 +19,6 @@ repositories {
|
|||||||
Add dependency:
|
Add dependency:
|
||||||
```
|
```
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.github.openrndr:orx:v0.0.7'
|
compile 'com.github.openrndr.orx:<orx-artifact>:v0.0.7'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -12,7 +12,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
openrndrVersion = "0.3.26"
|
openrndrVersion = "0.3.27"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.openrndr.extra.jumpfill
|
|||||||
import org.openrndr.draw.*
|
import org.openrndr.draw.*
|
||||||
import org.openrndr.filter.filterShaderFromUrl
|
import org.openrndr.filter.filterShaderFromUrl
|
||||||
import org.openrndr.math.Matrix44
|
import org.openrndr.math.Matrix44
|
||||||
|
import org.openrndr.math.Vector2
|
||||||
import org.openrndr.resourceUrl
|
import org.openrndr.resourceUrl
|
||||||
|
|
||||||
class EncodePoints : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/encode-points.frag")))
|
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 ContourPoints : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/contour-points.frag")))
|
||||||
class Threshold : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/threshold.frag"))) {
|
class Threshold : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/threshold.frag"))) {
|
||||||
var threshold by parameters
|
var threshold by parameters
|
||||||
|
|
||||||
init {
|
init {
|
||||||
threshold = 0.5
|
threshold = 0.5
|
||||||
}
|
}
|
||||||
@@ -46,7 +48,25 @@ class JumpFlooder(val width: Int, val height: Int) {
|
|||||||
colorBuffer()
|
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<List<Vector2>> {
|
||||||
|
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) {
|
if (input.width != width || input.height != height) {
|
||||||
throw IllegalArgumentException("dimensions mismatch")
|
throw IllegalArgumentException("dimensions mismatch")
|
||||||
}
|
}
|
||||||
@@ -71,6 +91,7 @@ class JumpFlooder(val width: Int, val height: Int) {
|
|||||||
drawer.model = Matrix44.IDENTITY
|
drawer.model = Matrix44.IDENTITY
|
||||||
drawer.image(coordinates[exp % 2])
|
drawer.image(coordinates[exp % 2])
|
||||||
}
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun destroy(destroyFinal: Boolean = true) {
|
fun destroy(destroyFinal: Boolean = true) {
|
||||||
@@ -87,6 +108,11 @@ class JumpFlooder(val width: Int, val height: Int) {
|
|||||||
|
|
||||||
final.destroy()
|
final.destroy()
|
||||||
|
|
||||||
|
if (contourUsed) {
|
||||||
|
edges.destroy()
|
||||||
|
thresholded.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ void main() {
|
|||||||
vec2 size = textureSize(tex0, 0);
|
vec2 size = textureSize(tex0, 0);
|
||||||
vec2 pixelPosition = v_texCoord0;
|
vec2 pixelPosition = v_texCoord0;
|
||||||
vec2 centroidPixelPosition = texture(tex0, v_texCoord0).xy;
|
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);
|
o_color = vec4(pixelDistance, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user