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 | 7bdd84e8ecade87ececdefe3cee614df8438e0a1 (patch) | |
| tree | 5228218d87c08ca348a549d3444c12657439a694 /src/main/kotlin/wood/WoodProgram.kt | |
| parent | 70e53263b259c6b73a03ec16fe819bfce5f1ecb7 (diff) | |
| download | art-playground-openrndr-7bdd84e8ecade87ececdefe3cee614df8438e0a1.tar.gz art-playground-openrndr-7bdd84e8ecade87ececdefe3cee614df8438e0a1.zip | |
Wood pattern flow field(wip)
Diffstat (limited to '')
| -rw-r--r-- | src/main/kotlin/wood/WoodProgram.kt | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/main/kotlin/wood/WoodProgram.kt b/src/main/kotlin/wood/WoodProgram.kt new file mode 100644 index 0000000..66ae071 --- /dev/null +++ b/src/main/kotlin/wood/WoodProgram.kt @@ -0,0 +1,83 @@ +package wood + +import org.openrndr.application +import org.openrndr.color.* +import org.openrndr.draw.* +import org.openrndr.extra.noise.filters.SimplexNoise3D +import org.openrndr.math.IntVector2 +import org.openrndr.math.Vector2 +import org.openrndr.math.Vector3 +import org.openrndr.shape.IntRectangle +import phenax.utils.* + +fun main() = application { + recordDuration(5.seconds()) + + configure { + width = 640 + height = 480 + windowResizable = false + } + + oliveProgram { + val cs by liveComputeShader("wood") + + val outputBuffer = colorBuffer(width, height, type = ColorType.UINT8) + + val size = Math.max(width, height) * 2 + val noiseBuffer = colorBuffer(size, size, type = ColorType.UINT8) + val noiseFilter = SimplexNoise3D() + noiseFilter.scale = Vector3.ONE * 1.8 + noiseFilter.octaves = 8 + noiseFilter.premultipliedAlpha = false + noiseFilter.seed = Vector3(0.1, 2.6, 0.1) + noiseFilter.apply(emptyArray(), noiseBuffer) + + var flowField: MutableList<Double> = mutableListOf() + val subdiv = IntVector2(20, 20) + var subBuffer = colorBuffer(size / subdiv.x, size / subdiv.y) + for (row in 1..subdiv.y) { + for (col in 1..subdiv.x) { + val pos = IntVector2((col - 1) * subBuffer.width, (row - 1) * subBuffer.height) + noiseBuffer.copyTo( + subBuffer, + sourceRectangle = IntRectangle(pos, subBuffer.width, subBuffer.height), + targetRectangle = IntRectangle(0, 0, subBuffer.width, subBuffer.height) + ) + flowField.add(averageColor(subBuffer).r) + } + } + + var particles: MutableList<Vector2> = mutableListOf() + val particles_count = 5 + for (i in 0..(particles_count - 1)) { + particles.add(Vector2(0.5, 0.5)) + } + var particle_velocities = particles.map { Vector2(0.001, 0.0) }.toMutableList() + println(particles) + println(particles_count) + + extend { + for ((index, particle) in particles.withIndex()) { + val gpos = Vector2(particle.x * subdiv.x, particle.y * subdiv.y) + val fidx = gpos.x.toInt() + gpos.y.toInt() * subdiv.y + if (flowField.count() > fidx && fidx >= 0) { + val current_cell = flowField[fidx] + particle_velocities[index] += Vector2(0.0, current_cell/1000000.0) + } + particles[index] += particle_velocities[index] + } + } + + extend { + cs.uniform("particles", particles.toTypedArray()) + cs.uniform("particles_count", particles_count) + cs.uniform("flow_field", flowField.toTypedArray()) + cs.image("noise_texture", 1, noiseBuffer.imageBinding(0, ImageAccess.READ)) + cs.uniform("seconds", seconds) + cs.image("output_image", 0, outputBuffer.imageBinding(0, ImageAccess.WRITE)) + cs.execute(outputBuffer.width, outputBuffer.height, 1) + drawer.image(outputBuffer) + } + } +} |
