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 | |
| parent | f4ec01f09dbe4b731bee44e12d2c1f93268ca705 (diff) | |
| download | art-playground-openrndr-42b66232530f933b184d446a7461e2e9f8d42bce.tar.gz art-playground-openrndr-42b66232530f933b184d446a7461e2e9f8d42bce.zip | |
Fix recording + refactor play shader
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/kotlin/play/PlayProgram.kt | 93 | ||||
| -rw-r--r-- | src/main/resources/shaders/play_shader.cs | 26 |
2 files changed, 60 insertions, 59 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 + ) + } } } } diff --git a/src/main/resources/shaders/play_shader.cs b/src/main/resources/shaders/play_shader.cs index c92e8b6..ec19900 100644 --- a/src/main/resources/shaders/play_shader.cs +++ b/src/main/resources/shaders/play_shader.cs @@ -90,10 +90,10 @@ vec2 scene(in vec3 p) { float c1 = sdf_circle(p - vec3(0, 1, 2.4), 0.2); float c2 = sdf_circle(p - vec3(-0.6, 1, 3), 0.3); float box = sdf_box(p - vec3(1, 0.5, 3), vec3(0.5, 0.18, 0.2), 0.07); - float terrain_noise = - 3.0 * noise(p / 20.0) + noise(p / 4.0) + noise(p * 5) / 30.0; + float terrain_noise = 6.0 * noise(p / 20.0) + 0.2 * noise((p + 200.0) / 2.0) + + 0.005 * noise((p - 50.0) * 20.0); float terrain = - sdf_plane(p + vec3(0.0, terrain_noise, 0.0), vec3(0.0, 1.0, 0.0), 0.0); + sdf_plane(p + vec3(0.0, terrain_noise, 0.0), vec3(0., 1., 0.), 0.0); float light_indicator = sdf_circle(p - primary_light_position + vec3(0.1, 0.1, -0.4), 0.01); float dist = min(min(min(min(c1, c2), terrain), box), light_indicator); @@ -135,17 +135,17 @@ float shadow_scene(in vec3 ray_origin, in vec3 ray_direction, in float light_intensity) { float dist = 0.; float res = 1.; - float ph = 1e10; + float prev_gap = 1e10; for (int i = 0; i < 50 && dist < MAX_DISTANCE; i++) { vec3 p = ray_origin + dist * ray_direction; vec2 obj = scene(p); float gap = obj.x; if (obj.y < 0.) // Debug objects dont cast shadows continue; - float y = gap * gap / (2.0 * ph); - float d = sqrt(gap * gap - y * y); - res = min(res, light_intensity * d / max(0.0, dist - y)); - ph = gap; + float y = gap * gap / (10000.0 * prev_gap); + float d = sqrt(abs(gap * gap - y * y)); + res = min(res, light_intensity * d / max(0., dist - y)); + prev_gap = gap; dist += gap; if (res < 0.0001) @@ -187,15 +187,17 @@ void main() { } if (depth < MAX_DISTANCE && oid > 0.) { - float illumination = shadow_scene(p, light_dir, 24.0); - float contrast = clamp(dot(normal, light_dir), 0, 1.) * illumination; + float contrast = 1.; + contrast *= clamp(dot(normal, light_dir), 0, 1.); + contrast *= shadow_scene(p, light_dir, 24.0); float spe = pow(clamp(dot(normal, hal), 0.0, 1.0), 16.0) * contrast * (0.04 + 0.96 * pow(clamp(1.0 + dot(hal, uv_direction), 0.0, 1.0), 5.0)); col = col * 1.1 + 0.01; - col += 12.0 * spe * vec3(1.00, 0.70, 0.5); + if (oid != OID_TERRAIN) + col += 12.0 * spe * vec3(1.00, 0.70, 0.5); col *= contrast; - // col *= max(0.2, exp(-0.00005 * depth * depth * depth)); + // col *= max(0.1, exp(-0.00005 * depth * depth * depth)); } imageStore(output_image, ivec2(gl_GlobalInvocationID.xy), |
