diff options
| author | Akshay Nair <phenax5@gmail.com> | 2026-09-12 22:09:57 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2026-09-12 22:10:00 +0530 |
| commit | 42b66232530f933b184d446a7461e2e9f8d42bce (patch) | |
| tree | 907c2e68d6c79e8ce1a32a432785101ff49bfa19 /src/main/kotlin/play/PlayProgram.kt | |
| parent | f4ec01f09dbe4b731bee44e12d2c1f93268ca705 (diff) | |
| download | art-playground-openrndr-42b66232530f933b184d446a7461e2e9f8d42bce.tar.gz art-playground-openrndr-42b66232530f933b184d446a7461e2e9f8d42bce.zip | |
Fix recording + refactor play shader
Diffstat (limited to '')
| -rw-r--r-- | src/main/kotlin/play/PlayProgram.kt | 93 |
1 files changed, 46 insertions, 47 deletions
diff --git a/src/main/kotlin/play/PlayProgram.kt b/src/main/kotlin/play/PlayProgram.kt index 4840a89..ea54c35 100644 --- a/src/main/kotlin/play/PlayProgram.kt +++ b/src/main/kotlin/play/PlayProgram.kt @@ -9,7 +9,7 @@ import org.openrndr.math.Vector3 import phenax.utils.* fun main() = application { - recordDuration(10.seconds()) + recordDuration(5.seconds()) configure { width = 640 @@ -28,68 +28,67 @@ fun main() = application { 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) } + if (!recordingEnabled) { + 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 { lastPos -> cameraPosition -= (pos - lastPos) } + } else if (actionType == ActionType.LIGHT_MOVE) { + lastPos?.let { lastPos -> lightPosition += (pos - lastPos) } + } + actionType?.let { lastPos = pos } } - 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.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 } - } - mouse.buttonUp.listen { - actionType = null - lastPos = null } val noiseBuffer = colorBuffer(width, height, type = ColorType.UINT8) val noiseFilter = SimplexNoise3D() + 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) 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.uniform("camera_position", cameraPosition) cs.uniform("primary_light_position", lightPosition) - cs.image("output_image", 1, outputBuffer.imageBinding(0, ImageAccess.WRITE)) + cs.image("output_image", 2, 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 - ) + if (!recordingEnabled) { + 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 + ) + } } } } |
