From 7bdd84e8ecade87ececdefe3cee614df8438e0a1 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 20 Sep 2026 15:53:10 +0530 Subject: Wood pattern flow field(wip) --- src/main/kotlin/phenax/utils/program.kt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/main/kotlin/phenax') 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 { val shaderCode by watchingFile(File("src/main/resources/shaders/${name}.glsl")) { file -> -- cgit v1.3.1