[orx-fx] Add PolarToRectangular, RectangularToPolar and LineBlur

This commit is contained in:
Edwin Jakobs
2021-08-30 11:45:47 +02:00
parent f379554890
commit 6274e29349
8 changed files with 219 additions and 15 deletions

View File

@@ -49,6 +49,8 @@ class BoxBlur : Filter(mppFilterShader(fx_box_blur,"box-blur")) {
colorBuffer(target[0].width, target[0].height, target[0].contentScale, target[0].format, target[0].type)
}
parameters["wrapX"] = false
parameters["wrapY"] = false
intermediate.let {
parameters["blurDirection"] = Vector2(1.0, 0.0)
super.apply(source, arrayOf(it))

View File

@@ -0,0 +1,65 @@
package org.openrndr.extra.fx.blur
import org.openrndr.draw.*
import org.openrndr.extra.fx.fx_box_blur
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.extra.parameters.IntParameter
import org.openrndr.math.Vector2
import org.openrndr.math.asRadians
import kotlin.math.cos
import kotlin.math.sin
/**
* BoxBlur implemented as a separable filter
*/
@Description("Box-blur")
class LineBlur : Filter(mppFilterShader(fx_box_blur, "line-blur")) {
/**
* The sample window, default is 5
*/
@IntParameter("window size", 1, 25)
var window: Int by parameters
/**
* Spread multiplier, default is 1.0
*/
@DoubleParameter("kernel spread", 1.0, 4.0)
var spread: Double by parameters
/**
* Post-blur gain, default is 1.0
*/
@DoubleParameter("gain", 0.0, 4.0)
var gain: Double by parameters
@DoubleParameter("blur angle", -180.0, 180.0)
var blurAngle: Double by parameters
@BooleanParameter("wrap x", order = 9)
var wrapX: Boolean by parameters
@BooleanParameter("wrap y", order = 10)
var wrapY: Boolean by parameters
init {
window = 5
spread = 1.0
gain = 1.0
blurAngle = 0.0
wrapX = false
wrapY = false
}
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
parameters["blurDirection"] = Vector2(cos(blurAngle.asRadians), sin(blurAngle.asRadians))
super.apply(source, target)
}
}

View File

@@ -0,0 +1,23 @@
package org.openrndr.extra.fx.distort
import org.openrndr.draw.ColorBuffer
import org.openrndr.draw.Filter
import org.openrndr.draw.MagnifyingFilter
import org.openrndr.draw.MinifyingFilter
import org.openrndr.extra.fx.fx_polar_to_rectangular
import org.openrndr.extra.fx.mppFilterShader
import org.openrndr.extra.parameters.Description
import org.openrndr.extra.parameters.Vector2Parameter
import org.openrndr.math.Vector2
@Description("Polar to rectangular")
class PolarToRectangular : Filter(mppFilterShader(fx_polar_to_rectangular, "polar-to-rectangular")) {
var bicubicFiltering = true
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
if (bicubicFiltering && source.isNotEmpty()) {
source[0].generateMipmaps()
source[0].filter(MinifyingFilter.LINEAR_MIPMAP_LINEAR, MagnifyingFilter.LINEAR)
}
super.apply(source, target)
}
}

View File

@@ -0,0 +1,23 @@
package org.openrndr.extra.fx.distort
import org.openrndr.draw.ColorBuffer
import org.openrndr.draw.Filter
import org.openrndr.draw.MagnifyingFilter
import org.openrndr.draw.MinifyingFilter
import org.openrndr.extra.fx.fx_rectangular_to_polar
import org.openrndr.extra.fx.mppFilterShader
import org.openrndr.extra.parameters.Description
import org.openrndr.extra.parameters.Vector2Parameter
import org.openrndr.math.Vector2
@Description("Rectangular to polar")
class RectangularToPolar : Filter(mppFilterShader(fx_rectangular_to_polar, "rectangular-to-polar")) {
var bicubicFiltering = true
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
if (bicubicFiltering && source.isNotEmpty()) {
source[0].generateMipmaps()
source[0].filter(MinifyingFilter.LINEAR_MIPMAP_LINEAR, MagnifyingFilter.LINEAR)
}
super.apply(source, target)
}
}