I wanted to perform an accumulation pass between colorBuffers.
Something like Add().apply(sourceBuffer, targetBuffer), where some parts of the sourceBuffer are transparent.
However this overrules what was stored in targetBuffer and is effectively the same as sourceBuffer.copyTo(targetBuffer).
I wrote a small program to illustrate this and verify for yourself:
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.*
import org.openrndr.extra.fx.blend.Add
import org.openrndr.extra.fx.color.ColorCorrection
import org.openrndr.math.map
import kotlin.math.*
fun main() = application {
program {
// Pipeline setup
val rt = renderTarget(width, height) {
colorBuffer()
}
val drawBuffer = rt.colorBuffer(0)
val accumulator = drawBuffer.createEquivalent()
val colorCorrectionFx = ColorCorrection().apply { hueShift = 5.0 }
val addBlend = Add()
extend {
drawer.isolatedWithTarget(rt) {
// This clears the buffer, add will use TRANSPARENT to overwrite target
clear(ColorRGBa.TRANSPARENT) // Equivalent to drawBuffer.fill(TRANSPARENT)
stroke = null
val lumFac = sin(seconds * 1.5)*0.5 + 0.5
val opaFac = sin(seconds*3)*0.5 + 0.5
fill = ColorRGBa.PINK.shade(lumFac).opacify(opaFac)
val x = sin(seconds).map(-1.0, 1.0, width*0.2, width*0.8)
val y = cos(seconds).map(-1.0, 1.0, height*0.2, height*0.8)
circle(x, y, 50.0)
}
// Works fine, just for illustration
colorCorrectionFx.apply(accumulator, accumulator)
// On blend, the transparent part of the image gets destroyed
if (frameCount%10 == 0) {
addBlend.apply(drawBuffer, accumulator)
}
drawer.image(accumulator)
}
}
}
I am 99% certain I misunderstand something about blend filters and colorBuffers.
How would you actually perform an addtive pass from one colorBuffer to another ?