Files
orx/orx-fx/src/commonMain/kotlin/blur/FrameBlur.kt
Edwin Jakobs 750b5ef67e [orx-fx] Use the appropriate FilterNto1 interfaces
* Fix webgl 2 compatibility
 * Add LumaLaplacian, ACESTonemap, ReinhardTonemap, DirectionalHashBlur
2022-12-28 14:18:37 +01:00

41 lines
1.2 KiB
Kotlin

package org.openrndr.extra.fx.blur
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.*
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
@Description("Frame blur")
class FrameBlur : Filter1to1(mppFilterShader(fx_frame_blur, "frame-blur")) {
@DoubleParameter("blend", 0.0, 1.0)
var blend: Double by parameters
private var intermediate: ColorBuffer? = null
init {
blend = 0.5
}
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
if (target.isNotEmpty()) {
intermediate?.let {
if (it.width != target[0].width || it.height != target[0].height) {
it.destroy()
intermediate = null
}
}
if (intermediate == null) {
intermediate = colorBuffer(target[0].width, target[0].height, type = ColorType.FLOAT16)
intermediate?.fill(ColorRGBa.TRANSPARENT)
}
super.apply(arrayOf(source[0], intermediate!!), arrayOf(intermediate!!))
intermediate!!.copyTo(target[0])
}
}
}