Add Chromatic Aberration effect

This commit is contained in:
Ricardo Matias
2020-01-07 14:53:48 +01:00
parent 49b34ed902
commit 6e6f095439
2 changed files with 63 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
package org.openrndr.extra.fx.color
import org.openrndr.draw.*
import org.openrndr.extra.fx.filterFragmentCode
import org.openrndr.math.Vector2
import org.openrndr.resourceUrl
class ChromaticAberration : Filter(Shader.createFromCode(Filter.filterVertexCode, filterFragmentCode("color/chromatic-aberration.frag"))){
/**
* aberration factor, default value is 1.0
*/
var aberrationFactor: Double by parameters
init {
aberrationFactor = 8.0
}
private var intermediate: ColorBuffer? = null
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
intermediate?.let {
if (it.width != target[0].width || it.height != target[0].height) {
intermediate = null
}
}
if (intermediate == null) {
intermediate = colorBuffer(target[0].width, target[0].height, target[0].contentScale, target[0].format, target[0].type)
}
intermediate?.let {
parameters["dimensions"] = Vector2(it.effectiveWidth.toDouble(), it.effectiveHeight.toDouble())
super.apply(source, arrayOf(it))
it.copyTo(target[0])
}
}
}