-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathDemoDirectionalBlur01.kt
More file actions
52 lines (49 loc) · 1.75 KB
/
Copy pathDemoDirectionalBlur01.kt
File metadata and controls
52 lines (49 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.*
import org.openrndr.extra.fx.blur.DirectionalBlur
import org.openrndr.math.smoothstep
import kotlin.math.cos
import kotlin.math.sin
/**
* Demonstrates how to use [DirectionalBlur] by creating a `direction`
* ColorBuffer in which the red and green components of the pixels point
* in various directions where to sample pixels from. All the pixel colors
* of the ColorBuffer are set one by one using two for loops.
*
* Note the FLOAT32 color type of the buffer to allow for negative values,
* so sampling can happen from every direction.
*
* Every 60 animation frames the `centerWindow` property is toggled
* between true and false to demonstrate how the result changes.
*
*/
fun main() = application {
program {
val db = DirectionalBlur()
val rt = renderTarget(width, height) {
colorBuffer()
}
val blurred = colorBuffer(width, height)
val direction = colorBuffer(width, height, type = ColorType.FLOAT32)
val s = direction.shadow
for (y in 0 until height) {
for (x in 0 until width) {
val a = smoothstep(0.45, 0.55, cos((x + y) * 0.01) * 0.5 + 0.5)
s[x, y] = ColorRGBa(cos(y * .1) * a, sin(x * 0.1) * a, 0.0, 1.0)
}
}
s.upload()
val image = loadImage("demo-data/images/image-001.png")
extend {
drawer.isolatedWithTarget(rt) {
clear(ColorRGBa.BLACK)
drawer.image(image)
}
db.window = 10
db.centerWindow = frameCount % 120 > 60
db.apply(arrayOf(rt.colorBuffer(0), direction), blurred)
drawer.image(blurred)
}
}
}