diff --git a/src/commonMain/kotlin/baaahs/gl/shader/dialect/IsfShaderDialect.kt b/src/commonMain/kotlin/baaahs/gl/shader/dialect/IsfShaderDialect.kt index 26461558ac..3c31418837 100644 --- a/src/commonMain/kotlin/baaahs/gl/shader/dialect/IsfShaderDialect.kt +++ b/src/commonMain/kotlin/baaahs/gl/shader/dialect/IsfShaderDialect.kt @@ -1,5 +1,6 @@ package baaahs.gl.shader.dialect +import baaahs.Color import baaahs.englishize import baaahs.gl.glsl.* import baaahs.gl.patch.ContentType @@ -10,6 +11,7 @@ import baaahs.gl.shader.ShaderSubstitutions import baaahs.listOf import baaahs.plugin.PluginRef import baaahs.plugin.Plugins +import baaahs.plugin.core.feed.ColorPickerFeed import baaahs.plugin.core.feed.XyPadFeed import baaahs.show.Shader import baaahs.util.Logger @@ -248,7 +250,16 @@ class IsfShaderAnalyzer( private fun createColor(input: IsfColorInput): InputPort { return InputPort( input.NAME, ContentType.Color, title = input.LABEL ?: input.NAME.englishize(), - pluginRef = PluginRef("baaahs.Core", "ColorPicker") + pluginRef = ColorPickerFeed.pluginRef, + pluginConfig = buildJsonObject { + input.DEFAULT?.let { + if (it.size == 4) { + val (r, g, b, a) = it + val defaultColor = Color(r.toFloat(), g.toFloat(), b.toFloat(), a.toFloat()) + put("default", JsonPrimitive(defaultColor.toHexString())) + } + } + } ) } diff --git a/src/commonMain/kotlin/baaahs/plugin/core/feed/ColorPickerFeed.kt b/src/commonMain/kotlin/baaahs/plugin/core/feed/ColorPickerFeed.kt index dafeeaa8a2..5a9054d991 100644 --- a/src/commonMain/kotlin/baaahs/plugin/core/feed/ColorPickerFeed.kt +++ b/src/commonMain/kotlin/baaahs/plugin/core/feed/ColorPickerFeed.kt @@ -9,6 +9,7 @@ import baaahs.gl.data.singleUniformFeedContext import baaahs.gl.glsl.GlslType import baaahs.gl.patch.ContentType import baaahs.gl.shader.InputPort +import baaahs.plugin.PluginRef import baaahs.plugin.classSerializer import baaahs.plugin.core.CorePlugin import baaahs.show.Feed @@ -51,13 +52,14 @@ data class ColorPickerFeed( override val resourceName: String get() = "ColorPicker" override val contentType: ContentType get() = ContentType.Color override val serializerRegistrar get() = classSerializer(serializer()) + val pluginRef = PluginRef(CorePlugin.id, resourceName) override fun build(inputPort: InputPort): ColorPickerFeed { val default = inputPort.pluginConfig?.get("default")?.jsonPrimitive?.contentOrNull return ColorPickerFeed( inputPort.title, - initialValue = default?.let { Color.Companion.from(it) } ?: Color.WHITE + initialValue = default?.let { Color.from(it) } ?: Color.WHITE ) } diff --git a/src/commonMain/kotlin/baaahs/plugin/core/feed/RasterCoordinateFeed.kt b/src/commonMain/kotlin/baaahs/plugin/core/feed/RasterCoordinateFeed.kt index 2909f1fd5b..024323b54f 100644 --- a/src/commonMain/kotlin/baaahs/plugin/core/feed/RasterCoordinateFeed.kt +++ b/src/commonMain/kotlin/baaahs/plugin/core/feed/RasterCoordinateFeed.kt @@ -20,12 +20,12 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.Transient /** - * This feed provides `gl_FragColor` for quad previews. + * This feed provides `gl_FragCoord` for quad previews. * - * Because `gl_FragColor` is always given as absolute pixels relative to the bottom-left - * of the screen/canvas, _not_ relative to the the viewport, and we might be rendering + * Because `gl_FragCoord` is always given as absolute pixels relative to the bottom-left + * of the screen/canvas, _not_ relative to the viewport, and we might be rendering * into a `SharedGlContext` (which adjusts the viewport to a rectangle within the shared - * canvas), we need to adjust `gl_FragColor` to account for any offset. + * canvas), we need to adjust `gl_FragCoord` to account for any offset. */ @Serializable @SerialName("baaahs.Core:RasterCoordinate") diff --git a/src/commonTest/kotlin/baaahs/gl/shader/dialect/IsfShaderDialectSpec.kt b/src/commonTest/kotlin/baaahs/gl/shader/dialect/IsfShaderDialectSpec.kt index ec414b66a9..7e2f3e070e 100644 --- a/src/commonTest/kotlin/baaahs/gl/shader/dialect/IsfShaderDialectSpec.kt +++ b/src/commonTest/kotlin/baaahs/gl/shader/dialect/IsfShaderDialectSpec.kt @@ -1,7 +1,7 @@ package baaahs.gl.shader.dialect +import baaahs.* import baaahs.app.ui.editor.stringify -import baaahs.describe import baaahs.device.PixelArrayDevice import baaahs.gl.autoWire import baaahs.gl.autoWireWithDefaults @@ -15,14 +15,12 @@ import baaahs.gl.shader.InputPort import baaahs.gl.shader.OutputPort import baaahs.gl.shader.ShaderSubstitutions import baaahs.gl.testToolchain -import baaahs.only import baaahs.plugin.PluginRef +import baaahs.plugin.core.feed.ColorPickerFeed import baaahs.plugin.core.feed.RasterCoordinateFeed import baaahs.plugin.core.feed.SelectFeed import baaahs.show.live.LinkedPatch import baaahs.show.mutable.MutableFeedPort -import baaahs.toBeSpecified -import baaahs.toEqual import baaahs.ui.diagnostics.DotDag import ch.tutteli.atrium.api.fluent.en_GB.contains import ch.tutteli.atrium.api.fluent.en_GB.containsExactly @@ -73,6 +71,17 @@ object IsfShaderDialectSpec : Spek({ "NAME": "channel", "TYPE": "long", "VALUES": [ 1, 2, 3 ] + }, + { + "NAME": "fillColor", + "LABEL": "Fill Color", + "TYPE": "color", + "DEFAULT": [ + 1.0, + 0.0, + 0.0, + 1.0 + ] } ] }*/ @@ -117,15 +126,28 @@ object IsfShaderDialectSpec : Spek({ put("default", 1.json) }, isImplicit = true + ), + InputPort( + "fillColor", ContentType.Color, GlslType.Vec4, "Fill Color", + pluginRef = PluginRef("baaahs.Core", "ColorPicker"), + pluginConfig = buildJsonObject { + put("default", "#ff0000".json) + }, + isImplicit = true ) ) } - it("generates correct data sources") { + it("generates correct select feed") { expect(SelectFeed.build(openShader.inputPorts[1])) .toEqual(SelectFeed("Color Channel", listOf(1 to "Red", 2 to "Green", 3 to "Blue"), 0)) } + it("generates correct color picker feed") { + expect(ColorPickerFeed.build(openShader.inputPorts[2])) + .toEqual(ColorPickerFeed("Fill Color", Color.from("#ff0000"))) + } + it("finds the output port") { expect(shaderAnalysis.outputPorts).containsExactly( OutputPort(ContentType.Color, description = "Output Color", id = "gl_FragColor")