diff options
| author | Akshay Nair <phenax5@gmail.com> | 2026-09-11 17:25:39 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2026-09-11 17:25:39 +0530 |
| commit | f4ec01f09dbe4b731bee44e12d2c1f93268ca705 (patch) | |
| tree | 7ed1d824edb31ddcd45072920d4f9ee353844918 /src/main/kotlin/play/PlayProgram.kt | |
| parent | 41246c0567f4c48ec5788a291386e377241e0eed (diff) | |
| download | art-playground-openrndr-f4ec01f09dbe4b731bee44e12d2c1f93268ca705.tar.gz art-playground-openrndr-f4ec01f09dbe4b731bee44e12d2c1f93268ca705.zip | |
Overdid the raymarch experiment
Diffstat (limited to '')
| -rw-r--r-- | src/main/kotlin/play/PlayProgram.kt | 84 |
1 files changed, 66 insertions, 18 deletions
diff --git a/src/main/kotlin/play/PlayProgram.kt b/src/main/kotlin/play/PlayProgram.kt index 0ec0133..4840a89 100644 --- a/src/main/kotlin/play/PlayProgram.kt +++ b/src/main/kotlin/play/PlayProgram.kt @@ -1,9 +1,11 @@ package play -import java.io.File -import org.openrndr.Program +import org.openrndr.KeyModifier import org.openrndr.application +import org.openrndr.color.* import org.openrndr.draw.* +import org.openrndr.extra.noise.filters.SimplexNoise3D +import org.openrndr.math.Vector3 import phenax.utils.* fun main() = application { @@ -16,32 +18,78 @@ fun main() = application { } oliveProgram { + val font = loadFont("data/fonts/default.otf", 16.0) val cs by liveComputeShader("play_shader") - // val image = loadImage("data/images/pm5544.png") - // val font = loadFont("data/fonts/default.otf", 64.0) - // val inputBuffer = colorBuffer(width, height, type = ColorType.UINT8) val outputBuffer = colorBuffer(width, height, type = ColorType.UINT8) - extend { - // drawer.drawStyle.colorMatrix = tint(ColorRGBa.WHITE.shade(0.2)) - // drawer.image(image) + var cameraPosition: Vector3 = Vector3(0.0, 1.0, 0.0) + var lightPosition: Vector3 = Vector3(1.0, 2.0, 1.0) + var actionType: ActionType? = null + var lastPos: Vector3? = null + + mouse.moved.listen { + val dimens = Vector3(program.width.toDouble(), program.height.toDouble(), 1.0) + val pos = (Vector3(it.position.x, -it.position.y, 0.0) - dimens / 2.0).div(dimens) + if (actionType == ActionType.PAN) { + lastPos?.let { prev -> cameraPosition -= (pos - prev) } + } else if (actionType == ActionType.LIGHT_MOVE) { + lastPos?.let { prev -> lightPosition += (pos - prev) } + } + actionType?.let { lastPos = pos } + } + mouse.buttonDown.listen { + val isCtrl = KeyModifier.CTRL in it.modifiers + actionType = + if (isCtrl) { + ActionType.LIGHT_MOVE + } else { + ActionType.PAN + } + } + mouse.scrolled.listen { + val isCtrl = KeyModifier.CTRL in it.modifiers + if (isCtrl) { + lightPosition += Vector3(0.0, 0.0, it.rotation.y * 0.1) + } else { + cameraPosition += Vector3(0.0, 0.0, it.rotation.y * 0.1) + } + } + mouse.buttonUp.listen { + actionType = null + lastPos = null + } - // drawer.fill = ColorRGBa.PINK - // drawer.circle( - // cos(seconds) * width / 2.0 + width / 2.0, - // sin(0.5 * seconds) * height / 2.0 + height / 2.0, - // 140.0 - // ) + val noiseBuffer = colorBuffer(width, height, type = ColorType.UINT8) + val noiseFilter = SimplexNoise3D() - // drawer.fontMap = font - // drawer.fill = ColorRGBa.WHITE - // drawer.text("OPENRNDR", width / 2.0, height / 2.0) + extend { + noiseFilter.seed = Vector3(0.0, 0.0, 0.1) + noiseFilter.scale = Vector3.ONE * 1.0 + noiseFilter.octaves = 8 + noiseFilter.premultipliedAlpha = true + noiseFilter.apply(emptyArray(), noiseBuffer) + cs.image("noise_texture", 0, noiseBuffer.imageBinding(0, ImageAccess.READ)) cs.uniform("seconds", seconds) - cs.image("outputImg", 1, outputBuffer.imageBinding(0, ImageAccess.WRITE)) + cs.uniform("camera_position", cameraPosition) + cs.uniform("primary_light_position", lightPosition) + cs.image("output_image", 1, outputBuffer.imageBinding(0, ImageAccess.WRITE)) cs.execute(outputBuffer.width, outputBuffer.height, 1) drawer.image(outputBuffer) + + drawer.fontMap = font + drawer.fill = ColorRGBa.WHITE + drawer.text( + "C: %.2f %.2f %.2f".format(cameraPosition.x, cameraPosition.y, cameraPosition.z), + 8.0, + 16.0 + ) + drawer.text( + "L: %.2f %.2f %.2f".format(lightPosition.x, lightPosition.y, lightPosition.z), + 8.0, + 32.0 + ) } } } |
