From 3ec3f0bafb47711913bdf3263dd88f5889049a36 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Thu, 14 Dec 2023 17:52:09 +0100 Subject: [PATCH] [orx-fx, orx-jumpflood] Match changes to Filter --- .../kotlin/blur/ApproximateGaussianBlur.kt | 7 +++-- orx-fx/src/commonMain/kotlin/blur/Bloom.kt | 5 ++-- orx-fx/src/commonMain/kotlin/blur/BoxBlur.kt | 7 +++-- .../commonMain/kotlin/blur/DirectionalBlur.kt | 5 ++-- .../src/commonMain/kotlin/blur/FrameBlur.kt | 6 ++-- .../src/commonMain/kotlin/blur/LaserBlur.kt | 10 +++---- orx-fx/src/commonMain/kotlin/blur/LineBlur.kt | 5 ++-- orx-fx/src/commonMain/kotlin/blur/MipBloom.kt | 28 ++++++++++--------- orx-fx/src/commonMain/kotlin/blur/ZoomBlur.kt | 8 +++--- .../kotlin/color/ChromaticAberration.kt | 9 +++--- .../commonMain/kotlin/color/ColorLookup.kt | 5 ++-- .../kotlin/composite/CompositeFilter.kt | 11 ++++---- .../commonMain/kotlin/distort/BlockRepeat.kt | 5 ++-- .../kotlin/distort/DisplaceBlend.kt | 6 ++-- .../src/commonMain/kotlin/distort/Fisheye.kt | 5 ++-- .../commonMain/kotlin/distort/FluidDistort.kt | 11 ++++---- .../src/commonMain/kotlin/distort/Lenses.kt | 5 ++-- .../kotlin/distort/PerspectivePlane.kt | 5 ++-- .../src/commonMain/kotlin/distort/Perturb.kt | 5 ++-- .../kotlin/distort/PolarToRectangular.kt | 5 ++-- .../kotlin/distort/RectangularToPolar.kt | 5 ++-- .../commonMain/kotlin/distort/StackRepeat.kt | 5 ++-- .../commonMain/kotlin/distort/StretchWaves.kt | 5 ++-- orx-fx/src/commonMain/kotlin/distort/Tiles.kt | 5 ++-- orx-fx/src/commonMain/kotlin/distort/Wave.kt | 9 +++--- .../src/commonMain/kotlin/edges/EdgesWork.kt | 7 +++-- .../commonMain/kotlin/shadow/DropShadow.kt | 9 +++--- .../src/commonMain/kotlin/ClusteredField.kt | 6 ++-- .../src/commonMain/kotlin/DirectionalField.kt | 5 +++- .../src/commonMain/kotlin/DistanceField.kt | 4 ++- .../src/commonMain/kotlin/draw/SDFDraw.kt | 5 +--- .../src/commonMain/kotlin/fx/InnerBevel.kt | 7 +++-- .../src/commonMain/kotlin/fx/InnerGlow.kt | 5 ++-- .../src/commonMain/kotlin/fx/Inpaint.kt | 5 ++-- .../src/commonMain/kotlin/fx/OuterGlow.kt | 5 ++-- .../src/commonMain/kotlin/fx/Skeleton.kt | 5 +++- .../commonMain/kotlin/fx/StraightSkeleton.kt | 5 ++-- .../src/commonMain/kotlin/ops/SDFOps.kt | 25 +++++++++-------- orx-jumpflood/src/jvmMain/kotlin/ShapeSDF.kt | 5 ++-- 39 files changed, 162 insertions(+), 118 deletions(-) diff --git a/orx-fx/src/commonMain/kotlin/blur/ApproximateGaussianBlur.kt b/orx-fx/src/commonMain/kotlin/blur/ApproximateGaussianBlur.kt index 922e5eab..8f67b203 100644 --- a/orx-fx/src/commonMain/kotlin/blur/ApproximateGaussianBlur.kt +++ b/orx-fx/src/commonMain/kotlin/blur/ApproximateGaussianBlur.kt @@ -11,6 +11,7 @@ import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.extra.parameters.IntParameter import org.openrndr.math.Vector2 +import org.openrndr.shape.Rectangle /** * Approximate separated Gaussian blur @@ -50,7 +51,7 @@ class ApproximateGaussianBlur : Filter1to1(mppFilterShader(fx_approximate_gaussi sigma = 1.0 } - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { val intermediateDescription = ColorBufferDescription(target[0].width, target[0].height, target[0].contentScale, target[0].format, target[0].type) val intermediate = intermediateCache.getOrPut(intermediateDescription) { colorBuffer(target[0].width, target[0].height, target[0].contentScale, target[0].format, target[0].type) @@ -58,10 +59,10 @@ class ApproximateGaussianBlur : Filter1to1(mppFilterShader(fx_approximate_gaussi intermediate.let { parameters["blurDirection"] = Vector2(1.0, 0.0) - super.apply(source, arrayOf(it)) + super.apply(source, arrayOf(it), clip) parameters["blurDirection"] = Vector2(0.0, 1.0) - super.apply(arrayOf(it), target) + super.apply(arrayOf(it), target, clip) } } } \ No newline at end of file diff --git a/orx-fx/src/commonMain/kotlin/blur/Bloom.kt b/orx-fx/src/commonMain/kotlin/blur/Bloom.kt index 936b13dd..530e1773 100644 --- a/orx-fx/src/commonMain/kotlin/blur/Bloom.kt +++ b/orx-fx/src/commonMain/kotlin/blur/Bloom.kt @@ -9,6 +9,7 @@ import org.openrndr.extra.fx.mppFilterShader import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.extra.parameters.IntParameter +import org.openrndr.shape.Rectangle @Description("Bloom") class Bloom(blur: Filter = ApproximateGaussianBlur()) : Filter1to1(mppFilterShader(fx_bloom, "bloom")) { @@ -51,7 +52,7 @@ class Bloom(blur: Filter = ApproximateGaussianBlur()) : Filter1to1(mppFilterShad private val blendAdd = Add() - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { val src = source[0] val dest = target[0] @@ -81,7 +82,7 @@ class Bloom(blur: Filter = ApproximateGaussianBlur()) : Filter1to1(mppFilterShad blur.apply(bufferCurrA, bufferNextB) blendAdd.apply(arrayOf(bufferNextA, bufferNextB), bufferNextA) } else { - super.apply(arrayOf(src, bufferCurrA), target) + super.apply(arrayOf(src, bufferCurrA), target, clip) } } } diff --git a/orx-fx/src/commonMain/kotlin/blur/BoxBlur.kt b/orx-fx/src/commonMain/kotlin/blur/BoxBlur.kt index a080bc90..5d37a29d 100644 --- a/orx-fx/src/commonMain/kotlin/blur/BoxBlur.kt +++ b/orx-fx/src/commonMain/kotlin/blur/BoxBlur.kt @@ -10,6 +10,7 @@ import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.extra.parameters.IntParameter import org.openrndr.math.Vector2 +import org.openrndr.shape.Rectangle /** * BoxBlur implemented as a separable filter @@ -45,7 +46,7 @@ class BoxBlur : Filter1to1(mppFilterShader(fx_box_blur,"box-blur")) { gain = 1.0 } - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { val intermediateDescription = ColorBufferDescription(target[0].width, target[0].height, target[0].contentScale, target[0].format, target[0].type) val intermediate = intermediateCache.getOrPut(intermediateDescription) { colorBuffer(target[0].width, target[0].height, target[0].contentScale, target[0].format, target[0].type) @@ -55,10 +56,10 @@ class BoxBlur : Filter1to1(mppFilterShader(fx_box_blur,"box-blur")) { parameters["wrapY"] = false intermediate.let { parameters["blurDirection"] = Vector2(1.0, 0.0) - super.apply(source, arrayOf(it)) + super.apply(source, arrayOf(it), clip) parameters["blurDirection"] = Vector2(0.0, 1.0) - super.apply(arrayOf(it), target) + super.apply(arrayOf(it), target, clip) } } } \ No newline at end of file diff --git a/orx-fx/src/commonMain/kotlin/blur/DirectionalBlur.kt b/orx-fx/src/commonMain/kotlin/blur/DirectionalBlur.kt index e2c9a9e6..7f605b28 100644 --- a/orx-fx/src/commonMain/kotlin/blur/DirectionalBlur.kt +++ b/orx-fx/src/commonMain/kotlin/blur/DirectionalBlur.kt @@ -9,6 +9,7 @@ import org.openrndr.extra.parameters.BooleanParameter import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.extra.parameters.IntParameter +import org.openrndr.shape.Rectangle /** * Directional blur filter. Takes source image and direction buffer inputs @@ -56,9 +57,9 @@ class DirectionalBlur : Filter2to1(mppFilterShader(fx_directional_blur, "directi centerWindow = false } - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { parameters["wrapX"] = false parameters["wrapY"] = false - super.apply(source, target) + super.apply(source, target, clip) } } \ No newline at end of file diff --git a/orx-fx/src/commonMain/kotlin/blur/FrameBlur.kt b/orx-fx/src/commonMain/kotlin/blur/FrameBlur.kt index 058a4b84..f9dc1d3c 100644 --- a/orx-fx/src/commonMain/kotlin/blur/FrameBlur.kt +++ b/orx-fx/src/commonMain/kotlin/blur/FrameBlur.kt @@ -8,6 +8,7 @@ import org.openrndr.extra.fx.fx_frame_blur import org.openrndr.extra.fx.mppFilterShader import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter +import org.openrndr.shape.Rectangle @Description("Frame blur") class FrameBlur(val colorType: ColorType = ColorType.FLOAT16) : @@ -22,7 +23,8 @@ class FrameBlur(val colorType: ColorType = ColorType.FLOAT16) : blend = 0.5 } - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { + require(clip == null) if (source.isNotEmpty() && target.isNotEmpty()) { intermediate?.let { if (it.isEquivalentTo(target[0], ignoreFormat = true, ignoreLevels = true)) { @@ -36,7 +38,7 @@ class FrameBlur(val colorType: ColorType = ColorType.FLOAT16) : intermediate?.fill(ColorRGBa.TRANSPARENT) } - super.apply(arrayOf(source[0], intermediate!!), arrayOf(intermediate!!)) + super.apply(arrayOf(source[0], intermediate!!), arrayOf(intermediate!!), clip) intermediate!!.copyTo(target[0]) } } diff --git a/orx-fx/src/commonMain/kotlin/blur/LaserBlur.kt b/orx-fx/src/commonMain/kotlin/blur/LaserBlur.kt index a9fc7d28..6748658d 100644 --- a/orx-fx/src/commonMain/kotlin/blur/LaserBlur.kt +++ b/orx-fx/src/commonMain/kotlin/blur/LaserBlur.kt @@ -7,6 +7,7 @@ import org.openrndr.extra.fx.fx_laser_blur import org.openrndr.extra.fx.mppFilterShader import org.openrndr.extra.parameters.* import org.openrndr.math.Vector2 +import org.openrndr.shape.Rectangle import kotlin.math.pow private class LaserBlurPass : Filter(mppFilterShader(fx_laser_blur, "laser-blur")) { @@ -76,8 +77,7 @@ class LaserBlur : Filter1to1() { val intermediates = mutableListOf() - override fun apply(source: Array, target: Array) { - + override fun apply(source: Array, target: Array, clip:Rectangle?) { pass.center = center pass.radius = radius pass.amp0 = amp0 @@ -101,18 +101,18 @@ class LaserBlur : Filter1to1() { pass.linearInput = linearInput pass.linearOutput = true - pass.apply(source[0], intermediates[0]) + pass.apply(source[0], intermediates[0], clip) for (i in 0 until passes - 1) { pass.linearInput = true pass.linearOutput = true pass.radius = 1.0 + pow(exp, i + 1.0) * radius //(1.0 + simplex(0, phase + i)) / 2.0 - pass.apply(intermediates[i % 2], intermediates[(i + 1) % 2]) + pass.apply(intermediates[i % 2], intermediates[(i + 1) % 2], clip) } pass.radius = 1.0 + pow(exp, (passes) * 1.0) * radius pass.linearInput = true pass.linearOutput = linearOutput - pass.apply(intermediates[(passes + 1) % 2], target[0]) + pass.apply(intermediates[(passes + 1) % 2], target[0], clip) } } diff --git a/orx-fx/src/commonMain/kotlin/blur/LineBlur.kt b/orx-fx/src/commonMain/kotlin/blur/LineBlur.kt index e3ac9d83..a3d439a5 100644 --- a/orx-fx/src/commonMain/kotlin/blur/LineBlur.kt +++ b/orx-fx/src/commonMain/kotlin/blur/LineBlur.kt @@ -12,6 +12,7 @@ import org.openrndr.extra.parameters.IntParameter import org.openrndr.math.Vector2 import org.openrndr.math.asRadians +import org.openrndr.shape.Rectangle import kotlin.math.cos import kotlin.math.sin @@ -60,8 +61,8 @@ class LineBlur : Filter1to1(mppFilterShader(fx_box_blur, "line-blur")) { wrapY = false } - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { parameters["blurDirection"] = Vector2(cos(blurAngle.asRadians), sin(blurAngle.asRadians)) - super.apply(source, target) + super.apply(source, target, clip) } } \ No newline at end of file diff --git a/orx-fx/src/commonMain/kotlin/blur/MipBloom.kt b/orx-fx/src/commonMain/kotlin/blur/MipBloom.kt index 283ebe68..acd49ad7 100644 --- a/orx-fx/src/commonMain/kotlin/blur/MipBloom.kt +++ b/orx-fx/src/commonMain/kotlin/blur/MipBloom.kt @@ -14,6 +14,7 @@ import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.extra.parameters.IntParameter import org.openrndr.filter.color.delinearize import org.openrndr.filter.color.linearize +import org.openrndr.shape.Rectangle class BloomDownscale : Filter(mppFilterShader(fx_bloom_downscale,"bloom-downscale")) @@ -76,7 +77,8 @@ open class MipBloom(val blur: T) : Filter1to1(mppFilterShader(fx_blo val downScale = BloomDownscale() val combine = BloomCombine() - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { + require(clip == null) sourceCopy?.let { if (!it.isEquivalentTo(source[0], ignoreType = true)) { it.destroy() @@ -106,26 +108,26 @@ open class MipBloom(val blur: T) : Filter1to1(mppFilterShader(fx_blo if (sRGB) { - linearize.apply(sourceCopy!!, sourceCopy!!) + linearize.apply(sourceCopy!!, sourceCopy!!, clip) } upscale.noiseGain = noiseGain upscale.noiseSeed = noiseSeed - downScale.apply(sourceCopy!!, intermediates[0]) - blur.apply(intermediates[0], intermediates[0]) + downScale.apply(sourceCopy!!, intermediates[0], clip) + blur.apply(intermediates[0], intermediates[0], clip) for (pass in 1 until passes) { - downScale.apply(intermediates[pass - 1], intermediates[pass]) - blur.apply(intermediates[pass], intermediates[pass]) + downScale.apply(intermediates[pass - 1], intermediates[pass], clip) + blur.apply(intermediates[pass], intermediates[pass], clip) } - upscale.apply(intermediates.toTypedArray(), arrayOf(target[0])) + upscale.apply(intermediates.toTypedArray(), arrayOf(target[0]), clip) combine.gain = gain combine.pregain = pregain - combine.apply(arrayOf(sourceCopy!!, target[0]), target) + combine.apply(arrayOf(sourceCopy!!, target[0]), target, clip) if (sRGB) { - delinearize.apply(target[0], target[0]) + delinearize.apply(target[0], target[0], clip) } } } @@ -145,10 +147,10 @@ class HashBloom : MipBloom(blur = HashBlur()) { @IntParameter("number of samples", 1, 100) var samples: Int = 30 - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { blur.radius = radius blur.samples = samples - super.apply(source, target) + super.apply(source, target, clip) } } @@ -166,9 +168,9 @@ class GaussianBloom : MipBloom(blur = GaussianBlur()) { @DoubleParameter("kernel sigma", 0.0, 25.0) var sigma: Double = 1.0 - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { blur.window = window blur.sigma = sigma - super.apply(source, target) + super.apply(source, target, clip) } } \ No newline at end of file diff --git a/orx-fx/src/commonMain/kotlin/blur/ZoomBlur.kt b/orx-fx/src/commonMain/kotlin/blur/ZoomBlur.kt index f0440e19..7b8b673f 100644 --- a/orx-fx/src/commonMain/kotlin/blur/ZoomBlur.kt +++ b/orx-fx/src/commonMain/kotlin/blur/ZoomBlur.kt @@ -8,6 +8,7 @@ import org.openrndr.extra.fx.mppFilterShader import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.math.Vector2 +import org.openrndr.shape.Rectangle @Description("Zoom Blur") class ZoomBlur : Filter1to1(mppFilterShader(fx_zoom_blur, "zoom-blur")) { @@ -23,7 +24,8 @@ class ZoomBlur : Filter1to1(mppFilterShader(fx_zoom_blur, "zoom-blur")) { private var intermediate: ColorBuffer? = null - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { + require(clip == null) intermediate?.let { if (it.width != target[0].width || it.height != target[0].height) { intermediate = null @@ -37,9 +39,7 @@ class ZoomBlur : Filter1to1(mppFilterShader(fx_zoom_blur, "zoom-blur")) { intermediate?.let { parameters["dimensions"] = Vector2(it.effectiveWidth.toDouble(), it.effectiveHeight.toDouble()) - - super.apply(source, arrayOf(it)) - + super.apply(source, arrayOf(it), clip) it.copyTo(target[0]) } } diff --git a/orx-fx/src/commonMain/kotlin/color/ChromaticAberration.kt b/orx-fx/src/commonMain/kotlin/color/ChromaticAberration.kt index 1d6a359c..3736306b 100644 --- a/orx-fx/src/commonMain/kotlin/color/ChromaticAberration.kt +++ b/orx-fx/src/commonMain/kotlin/color/ChromaticAberration.kt @@ -8,6 +8,7 @@ import org.openrndr.extra.fx.mppFilterShader import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.math.Vector2 +import org.openrndr.shape.Rectangle @Description("Chromatic Aberration") class ChromaticAberration : Filter1to1(mppFilterShader(fx_chromatic_aberration, "chromatic-aberration")) { @@ -23,7 +24,9 @@ class ChromaticAberration : Filter1to1(mppFilterShader(fx_chromatic_aberration, private var intermediate: ColorBuffer? = null - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { + require(clip == null) + intermediate?.let { if (it.width != target[0].width || it.height != target[0].height) { intermediate = null @@ -36,9 +39,7 @@ class ChromaticAberration : Filter1to1(mppFilterShader(fx_chromatic_aberration, intermediate?.let { parameters["dimensions"] = Vector2(it.effectiveWidth.toDouble(), it.effectiveHeight.toDouble()) - - super.apply(source, arrayOf(it)) - + super.apply(source, arrayOf(it), clip) it.copyTo(target[0]) } } diff --git a/orx-fx/src/commonMain/kotlin/color/ColorLookup.kt b/orx-fx/src/commonMain/kotlin/color/ColorLookup.kt index d3214056..9bcef9da 100644 --- a/orx-fx/src/commonMain/kotlin/color/ColorLookup.kt +++ b/orx-fx/src/commonMain/kotlin/color/ColorLookup.kt @@ -3,6 +3,7 @@ package org.openrndr.extra.fx.color import org.openrndr.draw.* import org.openrndr.extra.fx.fx_color_lookup import org.openrndr.extra.fx.mppFilterShader +import org.openrndr.shape.Rectangle class ColorLookup(lookup: ColorBuffer) : Filter1to1(mppFilterShader(fx_color_lookup, "color-lookup")) { /** a color look-up texture */ @@ -24,8 +25,8 @@ class ColorLookup(lookup: ColorBuffer) : Filter1to1(mppFilterShader(fx_color_loo this.seed = 0.0 } - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { lookup.filter(MinifyingFilter.LINEAR, MagnifyingFilter.LINEAR) - super.apply(source, target) + super.apply(source, target, clip) } } \ No newline at end of file diff --git a/orx-fx/src/commonMain/kotlin/composite/CompositeFilter.kt b/orx-fx/src/commonMain/kotlin/composite/CompositeFilter.kt index e3f7503a..1e011c2d 100644 --- a/orx-fx/src/commonMain/kotlin/composite/CompositeFilter.kt +++ b/orx-fx/src/commonMain/kotlin/composite/CompositeFilter.kt @@ -4,6 +4,7 @@ import org.openrndr.draw.ColorBuffer import org.openrndr.draw.Filter import org.openrndr.draw.createEquivalent import org.openrndr.draw.isEquivalentTo +import org.openrndr.shape.Rectangle /** * @param first the filter that is applied first @@ -26,15 +27,15 @@ class CompositeFilter( ) : Filter() { private var intermediate: ColorBuffer? = null - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { val firstSource = firstSource(source.toList()).toTypedArray() if (!useIntermediateBuffer) { first.firstParameters() - first.apply(firstSource, target) + first.apply(firstSource, target, clip) second.secondParameters() val secondSource = secondSource(source.toList(), target.first()).toTypedArray() - second.apply(secondSource, target) + second.apply(secondSource, target, clip) } else { val li = intermediate if (li != null && !li.isEquivalentTo(target.first())) { @@ -45,10 +46,10 @@ class CompositeFilter( intermediate = target.first().createEquivalent() } first.firstParameters() - first.apply(firstSource, arrayOf(intermediate!!)) + first.apply(firstSource, arrayOf(intermediate!!), clip) val secondSource = secondSource(source.toList(), intermediate!!).toTypedArray() second.secondParameters() - second.apply(secondSource, target) + second.apply(secondSource, target, clip) } } diff --git a/orx-fx/src/commonMain/kotlin/distort/BlockRepeat.kt b/orx-fx/src/commonMain/kotlin/distort/BlockRepeat.kt index 4a2fb652..6a8d61cf 100644 --- a/orx-fx/src/commonMain/kotlin/distort/BlockRepeat.kt +++ b/orx-fx/src/commonMain/kotlin/distort/BlockRepeat.kt @@ -8,6 +8,7 @@ import org.openrndr.extra.fx.mppFilterShader import org.openrndr.extra.parameters.BooleanParameter import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter +import org.openrndr.shape.Rectangle @Description("Block repeat") class BlockRepeat : Filter1to1(mppFilterShader(fx_block_repeat, "block-repeat")) { @@ -38,12 +39,12 @@ class BlockRepeat : Filter1to1(mppFilterShader(fx_block_repeat, "block-repeat")) @BooleanParameter("bicubic filtering") var bicubicFiltering: Boolean by parameters - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { if (bicubicFiltering && source.isNotEmpty()) { source[0].generateMipmaps() source[0].filter(MinifyingFilter.LINEAR_MIPMAP_LINEAR, MagnifyingFilter.LINEAR) } - super.apply(source, target) + super.apply(source, target, clip) } init { diff --git a/orx-fx/src/commonMain/kotlin/distort/DisplaceBlend.kt b/orx-fx/src/commonMain/kotlin/distort/DisplaceBlend.kt index b2116a4e..fed7e1e4 100644 --- a/orx-fx/src/commonMain/kotlin/distort/DisplaceBlend.kt +++ b/orx-fx/src/commonMain/kotlin/distort/DisplaceBlend.kt @@ -8,6 +8,7 @@ import org.openrndr.extra.fx.mppFilterShader import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.math.Vector3 +import org.openrndr.shape.Rectangle @Description("Displace blend") class DisplaceBlend : Filter2to1(mppFilterShader(fx_displace_blend, "displace-blend")) { @@ -42,7 +43,8 @@ class DisplaceBlend : Filter2to1(mppFilterShader(fx_displace_blend, "displace-bl var bicubicFiltering = true private var intermediate: ColorBuffer? = null - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { + require(clip == null) if (source.size >= 2) { if (target[0] === source[0] || target[0] === source[1]) { if (intermediate == null) { @@ -53,7 +55,7 @@ class DisplaceBlend : Filter2to1(mppFilterShader(fx_displace_blend, "displace-bl source[0].generateMipmaps() source[0].filter(MinifyingFilter.LINEAR_MIPMAP_LINEAR, MagnifyingFilter.LINEAR) } - super.apply(source, arrayOf(intermediate ?: target[0])) + super.apply(source, arrayOf(intermediate ?: target[0]), clip) intermediate?.copyTo(target[0]) } } diff --git a/orx-fx/src/commonMain/kotlin/distort/Fisheye.kt b/orx-fx/src/commonMain/kotlin/distort/Fisheye.kt index 7d3c77c7..3c50a3f4 100644 --- a/orx-fx/src/commonMain/kotlin/distort/Fisheye.kt +++ b/orx-fx/src/commonMain/kotlin/distort/Fisheye.kt @@ -7,6 +7,7 @@ import org.openrndr.extra.fx.fx_fisheye import org.openrndr.extra.fx.mppFilterShader import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter +import org.openrndr.shape.Rectangle @Description("Fisheye") class Fisheye : Filter1to1(mppFilterShader(fx_fisheye, "fisheye")) { @@ -30,11 +31,11 @@ class Fisheye : Filter1to1(mppFilterShader(fx_fisheye, "fisheye")) { } var bicubicFiltering = true - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { if (bicubicFiltering && source.isNotEmpty()) { source[0].generateMipmaps() source[0].filter(MinifyingFilter.LINEAR_MIPMAP_LINEAR, MagnifyingFilter.LINEAR) } - super.apply(source, target) + super.apply(source, target, clip) } } diff --git a/orx-fx/src/commonMain/kotlin/distort/FluidDistort.kt b/orx-fx/src/commonMain/kotlin/distort/FluidDistort.kt index 45f3674f..13f201fd 100644 --- a/orx-fx/src/commonMain/kotlin/distort/FluidDistort.kt +++ b/orx-fx/src/commonMain/kotlin/distort/FluidDistort.kt @@ -4,6 +4,7 @@ import org.openrndr.draw.* import org.openrndr.extra.fx.fx_fluid_distort import org.openrndr.extra.fx.fx_uvmap import org.openrndr.extra.fx.mppFilterShader +import org.openrndr.shape.Rectangle import kotlin.math.cos private class UVMap: Filter( mppFilterShader(fx_uvmap, "uvmap")) @@ -28,8 +29,8 @@ class FluidDistort : Filter1to1() { private var buffer0: ColorBuffer? = null private var buffer1: ColorBuffer? = null private var index = 0 - override fun apply(source: Array, target: Array) { - + override fun apply(source: Array, target: Array, clip: Rectangle?) { + require(clip == null) distort.blend = blend distort.random = cos(index*0.5)*0.5+0.5 @@ -51,12 +52,12 @@ class FluidDistort : Filter1to1() { buffer1 = target[0].createEquivalent() } val buffers = arrayOf(buffer0!!, buffer1!!) - distort.apply(buffers[index%2], buffers[(index+1)%2]) + distort.apply(buffers[index%2], buffers[(index+1)%2], clip) if (!outputUV) { - uvmap.apply(arrayOf(buffers[(index + 1) % 2], source[0]), target[0]) + uvmap.apply(arrayOf(buffers[(index + 1) % 2], source[0]), target[0], clip) } else { - buffers[(index+1)%2].copyTo(target[0]) + buffers[(index+1)%2]. copyTo(target[0]) } index++ blend = 0.0 diff --git a/orx-fx/src/commonMain/kotlin/distort/Lenses.kt b/orx-fx/src/commonMain/kotlin/distort/Lenses.kt index 00114dae..69605af8 100644 --- a/orx-fx/src/commonMain/kotlin/distort/Lenses.kt +++ b/orx-fx/src/commonMain/kotlin/distort/Lenses.kt @@ -9,6 +9,7 @@ import org.openrndr.extra.parameters.BooleanParameter import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.extra.parameters.IntParameter +import org.openrndr.shape.Rectangle @Description("Lenses") class Lenses : Filter1to1(mppFilterShader(fx_lenses, "block-repeat")) { @@ -30,12 +31,12 @@ class Lenses : Filter1to1(mppFilterShader(fx_lenses, "block-repeat")) { @BooleanParameter("bicubic filtering") var bicubicFiltering: Boolean by parameters - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { if (bicubicFiltering && source.isNotEmpty()) { source[0].generateMipmaps() source[0].filter(MinifyingFilter.LINEAR_MIPMAP_LINEAR, MagnifyingFilter.LINEAR) } - super.apply(source, target) + super.apply(source, target, clip) } init { diff --git a/orx-fx/src/commonMain/kotlin/distort/PerspectivePlane.kt b/orx-fx/src/commonMain/kotlin/distort/PerspectivePlane.kt index df020ae9..387f5c37 100644 --- a/orx-fx/src/commonMain/kotlin/distort/PerspectivePlane.kt +++ b/orx-fx/src/commonMain/kotlin/distort/PerspectivePlane.kt @@ -10,6 +10,7 @@ import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.math.Vector3 import org.openrndr.math.transforms.transform +import org.openrndr.shape.Rectangle @Description("Perspective plane") class PerspectivePlane : Filter1to1(mppFilterShader(fx_perspective_plane, "perspective-plane")) { @@ -43,7 +44,7 @@ class PerspectivePlane : Filter1to1(mppFilterShader(fx_perspective_plane, "persp tile = false } - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { source[0].generateMipmaps() source[0].filter(MinifyingFilter.LINEAR_MIPMAP_LINEAR, MagnifyingFilter.LINEAR) source[0].wrapU = WrapMode.REPEAT @@ -55,6 +56,6 @@ class PerspectivePlane : Filter1to1(mppFilterShader(fx_perspective_plane, "persp rotate(Vector3.UNIT_Y, planeYaw) rotate(Vector3.UNIT_Z, planeRoll) } - super.apply(source, target) + super.apply(source, target, clip) } } \ No newline at end of file diff --git a/orx-fx/src/commonMain/kotlin/distort/Perturb.kt b/orx-fx/src/commonMain/kotlin/distort/Perturb.kt index f0120533..affd06ad 100644 --- a/orx-fx/src/commonMain/kotlin/distort/Perturb.kt +++ b/orx-fx/src/commonMain/kotlin/distort/Perturb.kt @@ -8,6 +8,7 @@ import org.openrndr.extra.fx.mppFilterShader import org.openrndr.extra.parameters.* import org.openrndr.math.Vector2 import org.openrndr.math.Vector3 +import org.openrndr.shape.Rectangle @Description("Perturb") class Perturb : Filter1to1(mppFilterShader(fx_perturb, "perturb")) { @@ -71,11 +72,11 @@ class Perturb : Filter1to1(mppFilterShader(fx_perturb, "perturb")) { } var bicubicFiltering = true - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { if (bicubicFiltering && source.isNotEmpty()) { source[0].generateMipmaps() source[0].filter(MinifyingFilter.LINEAR_MIPMAP_LINEAR, MagnifyingFilter.LINEAR) } - super.apply(source, target) + super.apply(source, target, clip) } } \ No newline at end of file diff --git a/orx-fx/src/commonMain/kotlin/distort/PolarToRectangular.kt b/orx-fx/src/commonMain/kotlin/distort/PolarToRectangular.kt index 4fd7157f..7f652ab1 100644 --- a/orx-fx/src/commonMain/kotlin/distort/PolarToRectangular.kt +++ b/orx-fx/src/commonMain/kotlin/distort/PolarToRectangular.kt @@ -9,6 +9,7 @@ import org.openrndr.extra.parameters.BooleanParameter import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.Vector2Parameter import org.openrndr.math.Vector2 +import org.openrndr.shape.Rectangle @Description("Polar to rectangular") class PolarToRectangular : Filter1to1(mppFilterShader(fx_polar_to_rectangular, "polar-to-rectangular")) { @@ -21,11 +22,11 @@ class PolarToRectangular : Filter1to1(mppFilterShader(fx_polar_to_rectangular, " var bicubicFiltering = true - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { if (bicubicFiltering && source.isNotEmpty()) { source[0].generateMipmaps() source[0].filter(MinifyingFilter.LINEAR_MIPMAP_LINEAR, MagnifyingFilter.LINEAR) } - super.apply(source, target) + super.apply(source, target, clip) } } \ No newline at end of file diff --git a/orx-fx/src/commonMain/kotlin/distort/RectangularToPolar.kt b/orx-fx/src/commonMain/kotlin/distort/RectangularToPolar.kt index f5b238c3..3fb905d7 100644 --- a/orx-fx/src/commonMain/kotlin/distort/RectangularToPolar.kt +++ b/orx-fx/src/commonMain/kotlin/distort/RectangularToPolar.kt @@ -9,6 +9,7 @@ import org.openrndr.extra.parameters.BooleanParameter import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.Vector2Parameter import org.openrndr.math.Vector2 +import org.openrndr.shape.Rectangle import kotlin.math.log @Description("Rectangular to polar") @@ -23,11 +24,11 @@ class RectangularToPolar : Filter1to1(mppFilterShader(fx_rectangular_to_polar, " var bicubicFiltering = true - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { if (bicubicFiltering && source.isNotEmpty()) { source[0].generateMipmaps() source[0].filter(MinifyingFilter.LINEAR_MIPMAP_LINEAR, MagnifyingFilter.LINEAR) } - super.apply(source, target) + super.apply(source, target, clip) } } \ No newline at end of file diff --git a/orx-fx/src/commonMain/kotlin/distort/StackRepeat.kt b/orx-fx/src/commonMain/kotlin/distort/StackRepeat.kt index 3a44abfe..98d2e464 100644 --- a/orx-fx/src/commonMain/kotlin/distort/StackRepeat.kt +++ b/orx-fx/src/commonMain/kotlin/distort/StackRepeat.kt @@ -8,6 +8,7 @@ import org.openrndr.extra.fx.mppFilterShader import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.extra.parameters.IntParameter +import org.openrndr.shape.Rectangle @Description("Stack repeat") class StackRepeat : Filter1to1(mppFilterShader(fx_stack_repeat, "stack-repeat")) { @@ -43,11 +44,11 @@ class StackRepeat : Filter1to1(mppFilterShader(fx_stack_repeat, "stack-repeat")) } var bicubicFiltering = true - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { if (bicubicFiltering && source.isNotEmpty()) { source[0].generateMipmaps() source[0].filter(MinifyingFilter.LINEAR_MIPMAP_LINEAR, MagnifyingFilter.LINEAR) } - super.apply(source, target) + super.apply(source, target, clip) } } diff --git a/orx-fx/src/commonMain/kotlin/distort/StretchWaves.kt b/orx-fx/src/commonMain/kotlin/distort/StretchWaves.kt index cbae30a1..12ce2976 100644 --- a/orx-fx/src/commonMain/kotlin/distort/StretchWaves.kt +++ b/orx-fx/src/commonMain/kotlin/distort/StretchWaves.kt @@ -7,6 +7,7 @@ import org.openrndr.extra.fx.fx_stretch_waves import org.openrndr.extra.fx.mppFilterShader import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter +import org.openrndr.shape.Rectangle @Description("Stretch waves") class StretchWaves : Filter1to1(mppFilterShader(fx_stretch_waves, "stretch-waves")) { @@ -34,11 +35,11 @@ class StretchWaves : Filter1to1(mppFilterShader(fx_stretch_waves, "stretch-waves } var bicubicFiltering = true - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { if (bicubicFiltering && source.isNotEmpty()) { source[0].generateMipmaps() source[0].filter(MinifyingFilter.LINEAR_MIPMAP_LINEAR, MagnifyingFilter.LINEAR) } - super.apply(source, target) + super.apply(source, target, clip) } } \ No newline at end of file diff --git a/orx-fx/src/commonMain/kotlin/distort/Tiles.kt b/orx-fx/src/commonMain/kotlin/distort/Tiles.kt index 89ce452a..6cb43207 100644 --- a/orx-fx/src/commonMain/kotlin/distort/Tiles.kt +++ b/orx-fx/src/commonMain/kotlin/distort/Tiles.kt @@ -8,6 +8,7 @@ import org.openrndr.extra.fx.mppFilterShader import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.extra.parameters.IntParameter +import org.openrndr.shape.Rectangle @Description("Tiles") class Tiles : Filter1to1(mppFilterShader(fx_tiles, "tiles")) { @@ -27,11 +28,11 @@ class Tiles : Filter1to1(mppFilterShader(fx_tiles, "tiles")) { } var bicubicFiltering = false - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { if (bicubicFiltering && source.isNotEmpty()) { source[0].generateMipmaps() source[0].filter(MinifyingFilter.LINEAR_MIPMAP_LINEAR, MagnifyingFilter.LINEAR) } - super.apply(source, target) + super.apply(source, target, clip) } } diff --git a/orx-fx/src/commonMain/kotlin/distort/Wave.kt b/orx-fx/src/commonMain/kotlin/distort/Wave.kt index 3bf43c8f..82c84f7e 100644 --- a/orx-fx/src/commonMain/kotlin/distort/Wave.kt +++ b/orx-fx/src/commonMain/kotlin/distort/Wave.kt @@ -9,6 +9,7 @@ import org.openrndr.extra.fx.mppFilterShader import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.extra.parameters.IntParameter +import org.openrndr.shape.Rectangle @Description("Horizontal wave") class HorizontalWave : Filter1to1(mppFilterShader(fx_horizontal_wave, "horizontal-wave")) { @@ -32,12 +33,12 @@ class HorizontalWave : Filter1to1(mppFilterShader(fx_horizontal_wave, "horizonta } var bicubicFiltering = true - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { if (bicubicFiltering && source.isNotEmpty()) { source[0].generateMipmaps() source[0].filter(MinifyingFilter.LINEAR_MIPMAP_LINEAR, MagnifyingFilter.LINEAR) } - super.apply(source, target) + super.apply(source, target, clip) } } @@ -63,11 +64,11 @@ class VerticalWave : Filter1to1(mppFilterShader(fx_vertical_wave, "vertical-wave } var bicubicFiltering = true - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { if (bicubicFiltering && source.isNotEmpty()) { source[0].generateMipmaps() source[0].filter(MinifyingFilter.LINEAR_MIPMAP_LINEAR, MagnifyingFilter.LINEAR) } - super.apply(source, target) + super.apply(source, target, clip) } } \ No newline at end of file diff --git a/orx-fx/src/commonMain/kotlin/edges/EdgesWork.kt b/orx-fx/src/commonMain/kotlin/edges/EdgesWork.kt index c60e69c1..3d0d4535 100644 --- a/orx-fx/src/commonMain/kotlin/edges/EdgesWork.kt +++ b/orx-fx/src/commonMain/kotlin/edges/EdgesWork.kt @@ -10,6 +10,7 @@ import org.openrndr.extra.fx.mppFilterShader import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.IntParameter import org.openrndr.math.Vector2 +import org.openrndr.shape.Rectangle internal class EdgesWork1 : Filter(mppFilterShader(fx_edges_work_1, "edges-work-1")) { var delta: Vector2 by parameters @@ -38,7 +39,7 @@ open class EdgesWork : Filter1to1(mppFilterShader(fx_edges_work_2, "edges-work-2 delta = Vector2.ZERO } - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { val intermediateDescription = ColorBufferDescription( target[0].width, target[0].height, @@ -52,10 +53,10 @@ open class EdgesWork : Filter1to1(mppFilterShader(fx_edges_work_2, "edges-work-2 intermediate.let { work1.delta = Vector2(radius / it.effectiveWidth.toDouble(), 0.0) - work1.apply(source, arrayOf(it)) + work1.apply(source, arrayOf(it), clip) parameters["delta"] = Vector2(0.0, radius / it.effectiveHeight.toDouble()) - super.apply(arrayOf(it), target) + super.apply(arrayOf(it), target, clip) } } } diff --git a/orx-fx/src/commonMain/kotlin/shadow/DropShadow.kt b/orx-fx/src/commonMain/kotlin/shadow/DropShadow.kt index 83f51818..f9288abe 100644 --- a/orx-fx/src/commonMain/kotlin/shadow/DropShadow.kt +++ b/orx-fx/src/commonMain/kotlin/shadow/DropShadow.kt @@ -12,6 +12,7 @@ import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.extra.parameters.IntParameter import org.openrndr.math.Vector2 +import org.openrndr.shape.Rectangle private class Blend : Filter(mppFilterShader(fx_dropshadow_blend, "dropshadow-blend")) { var shift: Vector2 by parameters @@ -45,7 +46,7 @@ class DropShadow : Filter1to1(mppFilterShader(fx_dropshadow_blur, "dropshadow-bl gain = 1.0 } - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { intermediate?.let { if (it.width != target[0].width || it.height != target[0].height) { intermediate = null @@ -65,13 +66,13 @@ class DropShadow : Filter1to1(mppFilterShader(fx_dropshadow_blur, "dropshadow-bl intermediate?.let { parameters["blurDirection"] = Vector2(1.0, 0.0) - super.apply(source, arrayOf(it)) + super.apply(source, arrayOf(it), clip) parameters["blurDirection"] = Vector2(0.0, 1.0) - super.apply(arrayOf(it), arrayOf(intermediate2!!)) + super.apply(arrayOf(it), arrayOf(intermediate2!!), clip) b.shift = (Vector2(xShift,yShift)) / Vector2(target[0].width * 1.0, target[0].height * 1.0) - b.apply(arrayOf(intermediate2!!, source[0]), target) + b.apply(arrayOf(intermediate2!!, source[0]), target, clip) } } } \ No newline at end of file diff --git a/orx-jumpflood/src/commonMain/kotlin/ClusteredField.kt b/orx-jumpflood/src/commonMain/kotlin/ClusteredField.kt index cbe56c91..6453c442 100644 --- a/orx-jumpflood/src/commonMain/kotlin/ClusteredField.kt +++ b/orx-jumpflood/src/commonMain/kotlin/ClusteredField.kt @@ -7,6 +7,7 @@ import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.math.Vector2 import org.openrndr.shape.IntRectangle +import org.openrndr.shape.Rectangle import kotlin.math.ceil import kotlin.math.log2 import kotlin.math.max @@ -40,7 +41,8 @@ class ClusteredField(decodeMode: DecodeMode = DecodeMode.DIRECTION, private var fit: ColorBuffer? = null - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { + require(clip == null) val advisedWidth = 2.0.pow(ceil(log2(source[0].effectiveWidth.toDouble()))).toInt() val advisedHeight = 2.0.pow(ceil(log2(source[0].effectiveHeight.toDouble()))).toInt() val advisedSize = max(advisedWidth, advisedHeight) @@ -98,7 +100,7 @@ class ClusteredField(decodeMode: DecodeMode = DecodeMode.DIRECTION, decodeFilter.normalizedDistance = normalizedDistance decodeFilter.unitDirection = unitDirection decodeFilter.flipV = flipV - decodeFilter.apply(arrayOf(result, encoded!!), arrayOf(result)) + decodeFilter.apply(arrayOf(result, encoded!!), arrayOf(result), clip) result.copyTo( target[0], diff --git a/orx-jumpflood/src/commonMain/kotlin/DirectionalField.kt b/orx-jumpflood/src/commonMain/kotlin/DirectionalField.kt index 7edaa435..f3fbf87d 100644 --- a/orx-jumpflood/src/commonMain/kotlin/DirectionalField.kt +++ b/orx-jumpflood/src/commonMain/kotlin/DirectionalField.kt @@ -6,6 +6,7 @@ import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.math.Vector2 import org.openrndr.shape.IntRectangle +import org.openrndr.shape.Rectangle import kotlin.math.ceil import kotlin.math.log2 import kotlin.math.max @@ -38,7 +39,9 @@ class DirectionalField : Filter1to1() { private var fit: ColorBuffer? = null - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { + require(clip == null) + val advisedWidth = 2.0.pow(ceil(log2(source[0].effectiveWidth.toDouble()))).toInt() val advisedHeight = 2.0.pow(ceil(log2(source[0].effectiveHeight.toDouble()))).toInt() val advisedSize = max(advisedWidth, advisedHeight) diff --git a/orx-jumpflood/src/commonMain/kotlin/DistanceField.kt b/orx-jumpflood/src/commonMain/kotlin/DistanceField.kt index 622d2732..ec51d1dc 100644 --- a/orx-jumpflood/src/commonMain/kotlin/DistanceField.kt +++ b/orx-jumpflood/src/commonMain/kotlin/DistanceField.kt @@ -6,6 +6,7 @@ import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.math.Vector2 import org.openrndr.shape.IntRectangle +import org.openrndr.shape.Rectangle import kotlin.math.ceil import kotlin.math.log2 import kotlin.math.max @@ -32,7 +33,8 @@ class DistanceField : Filter1to1() { @BooleanParameter("signed distance") var signedDistance = true - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { + require(clip == null) val advisedWidth = 2.0.pow(ceil(log2(source[0].effectiveWidth.toDouble()))).toInt() val advisedHeight = 2.0.pow(ceil(log2(source[0].effectiveHeight.toDouble()))).toInt() val advisedSize = max(advisedWidth, advisedHeight) diff --git a/orx-jumpflood/src/commonMain/kotlin/draw/SDFDraw.kt b/orx-jumpflood/src/commonMain/kotlin/draw/SDFDraw.kt index cfbb43a1..d0ad6d4e 100644 --- a/orx-jumpflood/src/commonMain/kotlin/draw/SDFDraw.kt +++ b/orx-jumpflood/src/commonMain/kotlin/draw/SDFDraw.kt @@ -8,6 +8,7 @@ import org.openrndr.extra.jumpflood.jf_sdf_stroke_fill import org.openrndr.extra.parameters.ColorParameter import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter +import org.openrndr.shape.Rectangle @Description("SDF stroke and fill") class SDFStrokeFill : Filter(filterShaderFromCode(jf_sdf_stroke_fill, "sdf-stroke-fill")) { @@ -34,8 +35,4 @@ class SDFStrokeFill : Filter(filterShaderFromCode(jf_sdf_stroke_fill, "sdf-strok fillColor = ColorRGBa.WHITE } - - override fun apply(source: Array, target: Array) { - super.apply(source, target) - } } diff --git a/orx-jumpflood/src/commonMain/kotlin/fx/InnerBevel.kt b/orx-jumpflood/src/commonMain/kotlin/fx/InnerBevel.kt index 586b9ee0..e0e6bbca 100644 --- a/orx-jumpflood/src/commonMain/kotlin/fx/InnerBevel.kt +++ b/orx-jumpflood/src/commonMain/kotlin/fx/InnerBevel.kt @@ -1,3 +1,5 @@ +@file:Suppress("RUNTIME_ANNOTATION_NOT_SUPPORTED") + package org.openrndr.extra.jumpfill.fx import org.openrndr.draw.* @@ -9,6 +11,7 @@ import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.math.Vector2 import org.openrndr.resourceUrl +import org.openrndr.shape.Rectangle private class InnerBevelFilter : Filter(filterShaderFromCode(jf_inner_bevel, "inner-bevel")) { var angle: Double by parameters @@ -45,7 +48,7 @@ class InnerBevel : Filter1to1() { private var distance: ColorBuffer? = null - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { if (jumpFlooder == null) { jumpFlooder = JumpFlooder(target[0].width, target[0].height, encodePoints = EncodeSubpixel()) } @@ -60,6 +63,6 @@ class InnerBevel : Filter1to1() { bevelFilter.angle = angle bevelFilter.width = width bevelFilter.noise = noise - bevelFilter.apply(arrayOf(source[0], distance!!), target[0]) + bevelFilter.apply(arrayOf(source[0], distance!!), target[0], clip) } } \ No newline at end of file diff --git a/orx-jumpflood/src/commonMain/kotlin/fx/InnerGlow.kt b/orx-jumpflood/src/commonMain/kotlin/fx/InnerGlow.kt index d0b50bb7..32866c40 100644 --- a/orx-jumpflood/src/commonMain/kotlin/fx/InnerGlow.kt +++ b/orx-jumpflood/src/commonMain/kotlin/fx/InnerGlow.kt @@ -11,6 +11,7 @@ import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.math.Vector2 import org.openrndr.resourceUrl +import org.openrndr.shape.Rectangle private class InnerGlowFilter : Filter(filterShaderFromCode(jf_inner_glow, "inner-glow")) { var angle: Double by parameters @@ -56,7 +57,7 @@ class InnerGlow : Filter1to1() { private val glowFilter = InnerGlowFilter() private var distance: ColorBuffer? = null - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { if (jumpFlooder == null) { jumpFlooder = JumpFlooder(target[0].width, target[0].height, encodePoints = EncodeSubpixel()) } @@ -73,6 +74,6 @@ class InnerGlow : Filter1to1() { glowFilter.noise = noise glowFilter.shape = shape glowFilter.imageOpacity = imageOpacity - glowFilter.apply(arrayOf(source[0], distance!!), target[0]) + glowFilter.apply(arrayOf(source[0], distance!!), target[0], clip) } } \ No newline at end of file diff --git a/orx-jumpflood/src/commonMain/kotlin/fx/Inpaint.kt b/orx-jumpflood/src/commonMain/kotlin/fx/Inpaint.kt index 058ea77c..7938cf16 100644 --- a/orx-jumpflood/src/commonMain/kotlin/fx/Inpaint.kt +++ b/orx-jumpflood/src/commonMain/kotlin/fx/Inpaint.kt @@ -9,6 +9,7 @@ import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.math.Vector2 import org.openrndr.resourceUrl +import org.openrndr.shape.Rectangle private class InpaintFilter : Filter(filterShaderFromCode(jf_inpaint, "inpaint")) { @@ -50,7 +51,7 @@ class Inpaint : Filter1to1() { private var distance: ColorBuffer? = null - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { if (jumpFlooder == null) { jumpFlooder = JumpFlooder(target[0].width, target[0].height, encodePoints = EncodeSubpixel()) } @@ -67,6 +68,6 @@ class Inpaint : Filter1to1() { inpaintFilter.opacity = opacity inpaintFilter.shape = shape inpaintFilter.width = width - inpaintFilter.apply(arrayOf(source[0], distance!!), target[0]) + inpaintFilter.apply(arrayOf(source[0], distance!!), target[0], clip) } } \ No newline at end of file diff --git a/orx-jumpflood/src/commonMain/kotlin/fx/OuterGlow.kt b/orx-jumpflood/src/commonMain/kotlin/fx/OuterGlow.kt index ead88eaa..1e1c1b23 100644 --- a/orx-jumpflood/src/commonMain/kotlin/fx/OuterGlow.kt +++ b/orx-jumpflood/src/commonMain/kotlin/fx/OuterGlow.kt @@ -11,6 +11,7 @@ import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.math.Vector2 import org.openrndr.resourceUrl +import org.openrndr.shape.Rectangle private class OuterGlowFilter : Filter(filterShaderFromCode(jf_outer_glow, "outer-glow")) { var angle: Double by parameters @@ -57,7 +58,7 @@ class OuterGlow : Filter1to1() { private var distance: ColorBuffer? = null - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { if (jumpFlooder == null) { jumpFlooder = JumpFlooder(target[0].width, target[0].height, encodePoints = EncodeSubpixel()) } @@ -74,6 +75,6 @@ class OuterGlow : Filter1to1() { glowFilter.noise = noise glowFilter.shape = shape glowFilter.imageOpacity = imageOpacity - glowFilter.apply(arrayOf(source[0], distance!!), target[0]) + glowFilter.apply(arrayOf(source[0], distance!!), target[0], clip) } } \ No newline at end of file diff --git a/orx-jumpflood/src/commonMain/kotlin/fx/Skeleton.kt b/orx-jumpflood/src/commonMain/kotlin/fx/Skeleton.kt index 60be4e27..8d1e0bbf 100644 --- a/orx-jumpflood/src/commonMain/kotlin/fx/Skeleton.kt +++ b/orx-jumpflood/src/commonMain/kotlin/fx/Skeleton.kt @@ -10,6 +10,7 @@ import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.math.Vector2 import org.openrndr.resourceUrl +import org.openrndr.shape.Rectangle private class SkeletonFilter : Filter(filterShaderFromCode(jf_skeleton, "skeleton")) { var skeletonColor: ColorRGBa by parameters @@ -50,7 +51,9 @@ class Skeleton : Filter() { private val decodeFilter = PixelDistance() private val skeletonFilter = SkeletonFilter() - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { + require(clip == null) + if (thresholded == null) { thresholded = colorBuffer(target[0].width, target[0].height, format = ColorFormat.R) } diff --git a/orx-jumpflood/src/commonMain/kotlin/fx/StraightSkeleton.kt b/orx-jumpflood/src/commonMain/kotlin/fx/StraightSkeleton.kt index 87acf2e8..6b199213 100644 --- a/orx-jumpflood/src/commonMain/kotlin/fx/StraightSkeleton.kt +++ b/orx-jumpflood/src/commonMain/kotlin/fx/StraightSkeleton.kt @@ -10,6 +10,7 @@ import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.math.Vector2 import org.openrndr.resourceUrl +import org.openrndr.shape.Rectangle import kotlin.math.sqrt private class StraightSkeletonFilter : Filter(filterShaderFromCode(jf_straight_skeleton, "straight-skeleton")) { @@ -56,7 +57,7 @@ class StraightSkeleton : Filter() { private val decodeFilter = PixelDirection() private val skeletonFilter = StraightSkeletonFilter() - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { if (thresholded == null) { thresholded = colorBuffer(target[0].width, target[0].height, format = ColorFormat.R) } @@ -83,6 +84,6 @@ class StraightSkeleton : Filter() { skeletonFilter.skeletonColor = skeletonColor skeletonFilter.backgroundColor = backgroundColor skeletonFilter.foregroundColor = foregroundColor - skeletonFilter.apply(copied!!, target[0]) + skeletonFilter.apply(copied!!, target[0], clip) } } \ No newline at end of file diff --git a/orx-jumpflood/src/commonMain/kotlin/ops/SDFOps.kt b/orx-jumpflood/src/commonMain/kotlin/ops/SDFOps.kt index b4386fb9..a96586de 100644 --- a/orx-jumpflood/src/commonMain/kotlin/ops/SDFOps.kt +++ b/orx-jumpflood/src/commonMain/kotlin/ops/SDFOps.kt @@ -8,6 +8,7 @@ import org.openrndr.extra.jumpflood.* import org.openrndr.extra.parameters.Description import org.openrndr.extra.parameters.DoubleParameter import org.openrndr.resourceUrl +import org.openrndr.shape.Rectangle class SDFSmoothUnion : Filter(filterShaderFromCode(jf_sdf_smooth_union, "sdf-smooth-union")) { var radius: Double by parameters @@ -16,11 +17,11 @@ class SDFSmoothUnion : Filter(filterShaderFromCode(jf_sdf_smooth_union, "sdf-smo radius = 0.0 } - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { require(target[0].type == ColorType.FLOAT16 || target[0].type == ColorType.FLOAT32) { "needs a floating point target" } - super.apply(source, target) + super.apply(source, target, clip) } } @@ -31,11 +32,11 @@ class SDFSmoothIntersection : Filter(filterShaderFromCode(jf_sdf_smooth_intersec radius = 0.0 } - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { require(target[0].type == ColorType.FLOAT16 || target[0].type == ColorType.FLOAT32) { "needs a floating point target" } - super.apply(source, target) + super.apply(source, target, clip) } } @Description("SDF smooth difference") @@ -47,11 +48,11 @@ class SDFSmoothDifference : Filter(filterShaderFromCode(jf_sdf_smooth_difference radius = 0.0 } - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { require(target[0].type == ColorType.FLOAT16 || target[0].type == ColorType.FLOAT32) { "needs a floating point target" } - super.apply(source, target) + super.apply(source, target, clip) } } @@ -63,11 +64,11 @@ class SDFRound : Filter(filterShaderFromCode(jf_sdf_round, "sdf-round")) { radius = 0.0 } - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { require(target[0].type == ColorType.FLOAT16 || target[0].type == ColorType.FLOAT32) { "needs a floating point target" } - super.apply(source, target) + super.apply(source, target, clip) } } @@ -78,11 +79,11 @@ class SDFOnion : Filter(filterShaderFromCode(jf_sdf_onion, "sdf-onion")) { radius = 0.0 } - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { require(target[0].type == ColorType.FLOAT16 || target[0].type == ColorType.FLOAT32) { "needs a floating point target" } - super.apply(source, target) + super.apply(source, target, clip) } } @@ -93,10 +94,10 @@ class SDFBlend : Filter(filterShaderFromCode(jf_sdf_blend, "sdf-blend")) { factor = 0.5 } - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { require(target[0].type == ColorType.FLOAT16 || target[0].type == ColorType.FLOAT32) { "needs a floating point target" } - super.apply(source, target) + super.apply(source, target, clip) } } diff --git a/orx-jumpflood/src/jvmMain/kotlin/ShapeSDF.kt b/orx-jumpflood/src/jvmMain/kotlin/ShapeSDF.kt index 76d99026..688b6d8f 100644 --- a/orx-jumpflood/src/jvmMain/kotlin/ShapeSDF.kt +++ b/orx-jumpflood/src/jvmMain/kotlin/ShapeSDF.kt @@ -6,6 +6,7 @@ import org.openrndr.extra.parameters.BooleanParameter import org.openrndr.math.Matrix44 import org.openrndr.math.Vector4 import org.openrndr.resourceUrl +import org.openrndr.shape.Rectangle import org.openrndr.shape.Shape import org.openrndr.shape.ShapeContour @@ -76,7 +77,7 @@ class ShapeSDF : Filter(filterShaderFromCode(jf_shape_sdf, "shape-sdf")) { segmentCount = from.size } - override fun apply(source: Array, target: Array) { + override fun apply(source: Array, target: Array, clip: Rectangle?) { require(target[0].type == ColorType.FLOAT16 || target[0].type == ColorType.FLOAT32) { "needs a floating point target" } @@ -85,6 +86,6 @@ class ShapeSDF : Filter(filterShaderFromCode(jf_shape_sdf, "shape-sdf")) { parameters["segmentCount"] = segmentCount // -- bit of an hack val effectiveSource = if (source.isNotEmpty()) source else target - super.apply(effectiveSource, target) + super.apply(effectiveSource, target, clip) } } \ No newline at end of file