Add orx-poisson-fill

This commit is contained in:
Edwin Jakobs
2019-11-02 12:47:30 +01:00
parent 3a1f8a2ac7
commit 004eab4fae
16 changed files with 702 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package org.openrndr.poissonfill
import org.openrndr.draw.*
import org.openrndr.resourceUrl
internal class FillBoundary : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/poisson/fill-boundary.frag")))
internal class FillCombine : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/poisson/fill-combine.frag")))
class PoissonFiller(width: Int, height: Int, type: ColorType = ColorType.FLOAT32) {
private val pyramid = ConvolutionPyramid(width, height, 0, type = type)
private val preproc = colorBuffer(width, height, type = type)
private val combined = colorBuffer(width, height, type = type)
private val fillBoundary = FillBoundary()
private val fillCombine = FillCombine()
private val h1 = floatArrayOf(0.1507146f, 0.6835785f, 1.0334191f, 0.6836f, 0.1507f)
private val h2 = 0.0269546f
private val g = floatArrayOf(0.0311849f, 0.7752854f, 0.0311849f)
init {
pyramid.h1 = h1
pyramid.g = g
pyramid.h2 = h2
}
fun process(input: ColorBuffer): ColorBuffer {
fillBoundary.apply(input, preproc)
val result = pyramid.process(preproc)
fillCombine.apply(arrayOf(result, input), arrayOf(combined))
return combined
}
}