[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

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

View File

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

View File

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

View File

@@ -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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, clip: Rectangle?) {
parameters["wrapX"] = false
parameters["wrapY"] = false
super.apply(source, target)
super.apply(source, target, clip)
}
}

View File

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

View File

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

View File

@@ -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<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, clip: Rectangle?) {
parameters["blurDirection"] = Vector2(cos(blurAngle.asRadians), sin(blurAngle.asRadians))
super.apply(source, target)
super.apply(source, target, clip)
}
}

View File

@@ -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<T : Filter>(val blur: T) : Filter1to1(mppFilterShader(fx_blo
val downScale = BloomDownscale()
val combine = BloomCombine()
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, clip: Rectangle?) {
require(clip == null)
sourceCopy?.let {
if (!it.isEquivalentTo(source[0], ignoreType = true)) {
it.destroy()
@@ -106,26 +108,26 @@ open class MipBloom<T : Filter>(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<HashBlur>(blur = HashBlur()) {
@IntParameter("number of samples", 1, 100)
var samples: Int = 30
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, clip: Rectangle?) {
blur.radius = radius
blur.samples = samples
super.apply(source, target)
super.apply(source, target, clip)
}
}
@@ -166,9 +168,9 @@ class GaussianBloom : MipBloom<GaussianBlur>(blur = GaussianBlur()) {
@DoubleParameter("kernel sigma", 0.0, 25.0)
var sigma: Double = 1.0
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>, clip: Rectangle?) {
blur.window = window
blur.sigma = sigma
super.apply(source, target)
super.apply(source, target, clip)
}
}

View File

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