diff options
Diffstat (limited to 'src/main/kotlin/phenax')
| -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 -> |
