Add orx-fx, the new home for what was in openrndr-filter before
This commit is contained in:
66
orx-fx/src/main/kotlin/blur/ApproximateGaussianBlur.kt
Normal file
66
orx-fx/src/main/kotlin/blur/ApproximateGaussianBlur.kt
Normal file
@@ -0,0 +1,66 @@
|
||||
package org.openrndr.extra.fx.blur
|
||||
|
||||
import org.openrndr.draw.ColorBuffer
|
||||
import org.openrndr.draw.Filter
|
||||
import org.openrndr.draw.Shader
|
||||
import org.openrndr.draw.colorBuffer
|
||||
import org.openrndr.extra.fx.filterFragmentCode
|
||||
|
||||
import org.openrndr.math.Vector2
|
||||
|
||||
/**
|
||||
* Approximate separated Gaussian blur
|
||||
*/
|
||||
class ApproximateGaussianBlur : Filter(Shader.createFromCode(Filter.filterVertexCode,
|
||||
filterFragmentCode("blur/approximate-gaussian-blur.frag"))) {
|
||||
|
||||
/**
|
||||
* blur sample window, default value is 5
|
||||
*/
|
||||
var window: Int by parameters
|
||||
|
||||
/**
|
||||
* spread multiplier, default value is 1.0
|
||||
*/
|
||||
var spread: Double by parameters
|
||||
|
||||
/**
|
||||
* blur sigma, default value is 1.0
|
||||
*/
|
||||
var sigma: Double by parameters
|
||||
|
||||
/**
|
||||
* post blur gain, default value is 1.0
|
||||
*/
|
||||
var gain: Double by parameters
|
||||
|
||||
|
||||
private var intermediate: ColorBuffer? = null
|
||||
|
||||
init {
|
||||
window = 5
|
||||
spread = 1.0
|
||||
gain = 1.0
|
||||
sigma = 1.0
|
||||
}
|
||||
|
||||
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["blurDirection"] = Vector2(1.0, 0.0)
|
||||
super.apply(source, arrayOf(it))
|
||||
|
||||
parameters["blurDirection"] = Vector2(0.0, 1.0)
|
||||
super.apply(arrayOf(it), target)
|
||||
}
|
||||
}
|
||||
}
|
||||
59
orx-fx/src/main/kotlin/blur/BoxBlur.kt
Normal file
59
orx-fx/src/main/kotlin/blur/BoxBlur.kt
Normal file
@@ -0,0 +1,59 @@
|
||||
package org.openrndr.extra.fx.blur
|
||||
|
||||
import org.openrndr.draw.ColorBuffer
|
||||
import org.openrndr.draw.Filter
|
||||
import org.openrndr.draw.Shader
|
||||
import org.openrndr.draw.colorBuffer
|
||||
import org.openrndr.extra.fx.filterFragmentCode
|
||||
|
||||
import org.openrndr.math.Vector2
|
||||
|
||||
/**
|
||||
* BoxBlur implemented as a separable filter
|
||||
*/
|
||||
class BoxBlur : Filter(Shader.createFromCode(Filter.filterVertexCode,
|
||||
filterFragmentCode("blur/box-blur.frag"))) {
|
||||
|
||||
/**
|
||||
* The sample window, default is 5
|
||||
*/
|
||||
var window: Int by parameters
|
||||
|
||||
/**
|
||||
* Spread multiplier, default is 1.0
|
||||
*/
|
||||
var spread: Double by parameters
|
||||
|
||||
/**
|
||||
* Post-blur gain, default is 1.0
|
||||
*/
|
||||
var gain: Double by parameters
|
||||
|
||||
private var intermediate: ColorBuffer? = null
|
||||
|
||||
init {
|
||||
window = 5
|
||||
spread = 1.0
|
||||
gain = 1.0
|
||||
}
|
||||
|
||||
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["blurDirection"] = Vector2(1.0, 0.0)
|
||||
super.apply(source, arrayOf(it))
|
||||
|
||||
parameters["blurDirection"] = Vector2(0.0, 1.0)
|
||||
super.apply(arrayOf(it), target)
|
||||
}
|
||||
}
|
||||
}
|
||||
39
orx-fx/src/main/kotlin/blur/GaussianBlur.kt
Normal file
39
orx-fx/src/main/kotlin/blur/GaussianBlur.kt
Normal file
@@ -0,0 +1,39 @@
|
||||
package org.openrndr.extra.fx.blur
|
||||
|
||||
import org.openrndr.draw.Filter
|
||||
import org.openrndr.draw.Shader
|
||||
import org.openrndr.extra.fx.filterFragmentCode
|
||||
|
||||
/**
|
||||
* Exact Gaussian blur, implemented as a single pass filter
|
||||
*/
|
||||
class GaussianBlur : Filter(Shader.createFromCode(Filter.filterVertexCode,
|
||||
filterFragmentCode("blur/gaussian-blur.frag"))) {
|
||||
|
||||
/**
|
||||
* The sample window, default value is 5
|
||||
*/
|
||||
var window: Int by parameters
|
||||
|
||||
/**
|
||||
* Spread multiplier, default value is 1.0
|
||||
*/
|
||||
var spread: Double by parameters
|
||||
|
||||
/**
|
||||
* Blur kernel sigma, default value is 1.0
|
||||
*/
|
||||
var sigma: Double by parameters
|
||||
|
||||
/**
|
||||
* Post-blur gain, default value is 1.0
|
||||
*/
|
||||
var gain: Double by parameters
|
||||
|
||||
init {
|
||||
window = 5
|
||||
spread = 1.0
|
||||
sigma = 1.0
|
||||
gain = 1.0
|
||||
}
|
||||
}
|
||||
35
orx-fx/src/main/kotlin/blur/HashBlur.kt
Normal file
35
orx-fx/src/main/kotlin/blur/HashBlur.kt
Normal file
@@ -0,0 +1,35 @@
|
||||
package org.openrndr.extra.fx.blur
|
||||
|
||||
import org.openrndr.draw.Filter
|
||||
import org.openrndr.draw.Shader
|
||||
import org.openrndr.extra.fx.filterFragmentCode
|
||||
|
||||
class HashBlur : Filter(Shader.createFromCode(Filter.filterVertexCode,
|
||||
filterFragmentCode("blur/hash-blur.frag"))) {
|
||||
/**
|
||||
* Blur radius in pixels, default is 5.0
|
||||
*/
|
||||
var radius: Double by parameters
|
||||
|
||||
/**
|
||||
* Time/seed, this should be fed with seconds, default is 0.0
|
||||
*/
|
||||
var time: Double by parameters
|
||||
|
||||
/**
|
||||
* Number of samples, default is 30
|
||||
*/
|
||||
var samples: Int by parameters
|
||||
|
||||
/**
|
||||
* Post-blur gain, default is 1.0
|
||||
*/
|
||||
var gain: Double by parameters
|
||||
|
||||
init {
|
||||
radius = 5.0
|
||||
time = 0.0
|
||||
samples = 30
|
||||
gain = 1.0
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user