[orx-fx] Fix GLES compatibility for FrameBlur and MipBloom
This commit is contained in:
@@ -4,6 +4,7 @@ package org.openrndr.extra.fx.blur
|
||||
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.*
|
||||
import org.openrndr.extra.fx.blend.Passthrough
|
||||
import org.openrndr.extra.fx.fx_frame_blur
|
||||
import org.openrndr.extra.fx.mppFilterShader
|
||||
import org.openrndr.extra.parameters.Description
|
||||
@@ -17,7 +18,10 @@ class FrameBlur(val colorType: ColorType = ColorType.FLOAT16) :
|
||||
@DoubleParameter("blend", 0.0, 1.0)
|
||||
var blend: Double by parameters
|
||||
|
||||
|
||||
val pt = Passthrough()
|
||||
private var intermediate: ColorBuffer? = null
|
||||
private var intermediate2: ColorBuffer? = null
|
||||
|
||||
init {
|
||||
blend = 0.5
|
||||
@@ -32,14 +36,26 @@ class FrameBlur(val colorType: ColorType = ColorType.FLOAT16) :
|
||||
intermediate = null
|
||||
}
|
||||
}
|
||||
intermediate2?.let {
|
||||
if (it.isEquivalentTo(target[0], ignoreFormat = true, ignoreLevels = true)) {
|
||||
it.destroy()
|
||||
intermediate2 = null
|
||||
}
|
||||
}
|
||||
|
||||
if (intermediate == null) {
|
||||
intermediate = target[0].createEquivalent(type = colorType)
|
||||
intermediate?.fill(ColorRGBa.TRANSPARENT)
|
||||
}
|
||||
if (intermediate2 == null) {
|
||||
intermediate2 = target[0].createEquivalent(type = colorType)
|
||||
intermediate2?.fill(ColorRGBa.TRANSPARENT)
|
||||
}
|
||||
|
||||
super.apply(arrayOf(source[0], intermediate!!), arrayOf(intermediate!!), clip)
|
||||
intermediate!!.copyTo(target[0])
|
||||
super.apply(arrayOf(source[0], intermediate!!), arrayOf(intermediate2!!), clip)
|
||||
|
||||
pt.apply(intermediate2!!, intermediate!!)
|
||||
pt.apply(intermediate!!, target[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,12 +66,8 @@ open class MipBloom<T : Filter>(val blur: T) : Filter1to1(mppFilterShader(fx_blo
|
||||
|
||||
@DoubleParameter("noise seed", 0.0, 1000.0)
|
||||
var noiseSeed: Double = 0.0
|
||||
|
||||
@BooleanParameter("sRGB")
|
||||
var sRGB = true
|
||||
|
||||
var intermediates = mutableListOf<ColorBuffer>()
|
||||
var sourceCopy: ColorBuffer? = null
|
||||
var blurred = mutableListOf<ColorBuffer>()
|
||||
|
||||
val upscale = BloomUpscale()
|
||||
val downScale = BloomDownscale()
|
||||
@@ -79,17 +75,6 @@ open class MipBloom<T : Filter>(val blur: T) : Filter1to1(mppFilterShader(fx_blo
|
||||
|
||||
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()
|
||||
sourceCopy = null
|
||||
}
|
||||
}
|
||||
if (sourceCopy == null) {
|
||||
sourceCopy = source[0].createEquivalent(type = ColorType.FLOAT16)
|
||||
}
|
||||
|
||||
source[0].copyTo(sourceCopy!!)
|
||||
|
||||
upscale.shape = shape
|
||||
if (intermediates.size != passes
|
||||
@@ -97,38 +82,35 @@ open class MipBloom<T : Filter>(val blur: T) : Filter1to1(mppFilterShader(fx_blo
|
||||
intermediates.forEach {
|
||||
it.destroy()
|
||||
}
|
||||
blurred.forEach {
|
||||
it.destroy()
|
||||
}
|
||||
intermediates.clear()
|
||||
blurred.clear()
|
||||
|
||||
for (pass in 0 until passes) {
|
||||
val tdiv = 1 shl (pass + 1)
|
||||
val cb = colorBuffer(target[0].width / tdiv, target[0].height / tdiv, type = ColorType.FLOAT16)
|
||||
val cb = colorBuffer(target[0].width / tdiv, target[0].height / tdiv, type = ColorType.FLOAT32)
|
||||
intermediates.add(cb)
|
||||
val cbb = colorBuffer(target[0].width / tdiv, target[0].height / tdiv, type = ColorType.FLOAT32)
|
||||
blurred.add(cbb)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (sRGB) {
|
||||
linearize.apply(sourceCopy!!, sourceCopy!!, clip)
|
||||
}
|
||||
|
||||
upscale.noiseGain = noiseGain
|
||||
upscale.noiseSeed = noiseSeed
|
||||
downScale.apply(sourceCopy!!, intermediates[0], clip)
|
||||
blur.apply(intermediates[0], intermediates[0], clip)
|
||||
downScale.apply(source[0], intermediates[0], clip)
|
||||
blur.apply(intermediates[0], blurred[0], clip)
|
||||
|
||||
for (pass in 1 until passes) {
|
||||
downScale.apply(intermediates[pass - 1], intermediates[pass], clip)
|
||||
blur.apply(intermediates[pass], intermediates[pass], clip)
|
||||
downScale.apply(blurred[pass - 1], intermediates[pass], clip)
|
||||
blur.apply(intermediates[pass], blurred[pass], clip)
|
||||
}
|
||||
|
||||
upscale.apply(intermediates.toTypedArray(), arrayOf(target[0]), clip)
|
||||
upscale.apply(blurred.toTypedArray(), arrayOf(target[0]), clip)
|
||||
combine.gain = gain
|
||||
combine.pregain = pregain
|
||||
combine.apply(arrayOf(sourceCopy!!, target[0]), target, clip)
|
||||
|
||||
if (sRGB) {
|
||||
delinearize.apply(target[0], target[0], clip)
|
||||
}
|
||||
combine.apply(arrayOf(source[0], target[0]), target, clip)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user