aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/phenax/utils/program.kt
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2026-09-20 15:53:10 +0530
committerAkshay Nair <phenax5@gmail.com>2026-09-20 15:53:10 +0530
commit7bdd84e8ecade87ececdefe3cee614df8438e0a1 (patch)
tree5228218d87c08ca348a549d3444c12657439a694 /src/main/kotlin/phenax/utils/program.kt
parent70e53263b259c6b73a03ec16fe819bfce5f1ecb7 (diff)
downloadart-playground-openrndr-7bdd84e8ecade87ececdefe3cee614df8438e0a1.tar.gz
art-playground-openrndr-7bdd84e8ecade87ececdefe3cee614df8438e0a1.zip
Wood pattern flow field(wip)
Diffstat (limited to 'src/main/kotlin/phenax/utils/program.kt')
-rw-r--r--src/main/kotlin/phenax/utils/program.kt22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/kotlin/phenax/utils/program.kt b/src/main/kotlin/phenax/utils/program.kt
index ced3e3a..fe48351 100644
--- a/src/main/kotlin/phenax/utils/program.kt
+++ b/src/main/kotlin/phenax/utils/program.kt
@@ -5,6 +5,7 @@ import kotlin.properties.ReadOnlyProperty
import org.openrndr.ApplicationBuilder
import org.openrndr.Program
import org.openrndr.draw.*
+import org.openrndr.color.*
import org.openrndr.extra.filewatcher.watchingFile
import org.openrndr.extra.olive.oliveProgram as oliveProgramOriginal
@@ -57,6 +58,27 @@ fun preprocessShader(shaderCode: String): String {
val defaultShaderCode: String = ""
+fun averageColor(cb: ColorBuffer): ColorRGBa {
+ val shadow = cb.shadow
+ shadow.download()
+
+ var r = 0.0
+ var g = 0.0
+ var b = 0.0
+ var a = 0.0
+ for (y in 0 until cb.height) {
+ for (x in 0 until cb.width) {
+ val c = shadow[x, y]
+ r += c.r
+ g += c.g
+ b += c.b
+ a += c.alpha
+ }
+ }
+ val n = (cb.width * cb.height).toDouble()
+ return ColorRGBa(r / n, g / n, b / n, a / n)
+}
+
fun Program.liveComputeShader(name: String): ReadOnlyProperty<Any?, ComputeShader> {
val shaderCode by
watchingFile(File("src/main/resources/shaders/${name}.glsl")) { file ->