diff options
| author | Akshay Nair <phenax5@gmail.com> | 2026-09-20 15:53:10 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2026-09-20 15:53:10 +0530 |
| commit | c853f72ccf8a968edbdf15b3f8204772f66a5c23 (patch) | |
| tree | d273bc009a21f45a1d4d809cbfc6183b37ce482c /src/main/kotlin/phenax/utils | |
| parent | db0dfe5cc7faeeeeb76856568f0c0060845eab8a (diff) | |
| download | art-playground-openrndr-c853f72ccf8a968edbdf15b3f8204772f66a5c23.tar.gz art-playground-openrndr-c853f72ccf8a968edbdf15b3f8204772f66a5c23.zip | |
Wood pattern flow field(wip)
Diffstat (limited to '')
| -rw-r--r-- | src/main/kotlin/phenax/utils/program.kt | 22 |
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 -> |
