[orx-fx, orx-jumpflood] Match changes to Filter

This commit is contained in:
Edwin Jakobs
2023-12-14 17:52:09 +01:00
parent ad9177e085
commit 3ec3f0bafb
39 changed files with 162 additions and 118 deletions

View File

@@ -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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, 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],

View File

@@ -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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, 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)

View File

@@ -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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, 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)

View File

@@ -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<ColorBuffer>, target: Array<ColorBuffer>) {
super.apply(source, target)
}
}

View File

@@ -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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, 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)
}
}

View File

@@ -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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, 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)
}
}

View File

@@ -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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, 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)
}
}

View File

@@ -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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, 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)
}
}

View File

@@ -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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, clip: Rectangle?) {
require(clip == null)
if (thresholded == null) {
thresholded = colorBuffer(target[0].width, target[0].height, format = ColorFormat.R)
}

View File

@@ -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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, 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)
}
}

View File

@@ -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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, 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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, 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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, 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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, 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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, 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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, 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)
}
}

View File

@@ -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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, 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)
}
}