From 69a0b0c0ce46da983791f846ccc2dbdaf3ada8a3 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Tue, 28 Apr 2020 16:36:38 +0200 Subject: [PATCH] Fix ShapeSDF in case no distortion map is given --- orx-jumpflood/src/demo/kotlin/DemoShapeSDF03.kt | 1 - orx-jumpflood/src/main/kotlin/ShapeSDF.kt | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/orx-jumpflood/src/demo/kotlin/DemoShapeSDF03.kt b/orx-jumpflood/src/demo/kotlin/DemoShapeSDF03.kt index 54405bd6..02df9dc7 100644 --- a/orx-jumpflood/src/demo/kotlin/DemoShapeSDF03.kt +++ b/orx-jumpflood/src/demo/kotlin/DemoShapeSDF03.kt @@ -39,7 +39,6 @@ fun main() { } } extend { - drawer.background(ColorRGBa.PINK) fd.apply(emptyArray(), uvmap) diff --git a/orx-jumpflood/src/main/kotlin/ShapeSDF.kt b/orx-jumpflood/src/main/kotlin/ShapeSDF.kt index 20d8feda..aed9d4cc 100644 --- a/orx-jumpflood/src/main/kotlin/ShapeSDF.kt +++ b/orx-jumpflood/src/main/kotlin/ShapeSDF.kt @@ -14,10 +14,10 @@ class ShapeSDF : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/shape-sdf. private var segmentCount = 0 @BooleanParameter("use UV map") - var useUV:Boolean by parameters + var useUV: Boolean by parameters @BooleanParameter("rectify distance") - var rectify:Boolean by parameters + var rectify: Boolean by parameters init { @@ -53,7 +53,7 @@ class ShapeSDF : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/shape-sdf. for (v in from) { fromWriter.write(v) } - fromShadow.upload(0, from.size*4*4) + fromShadow.upload(0, from.size * 4 * 4) val toShadow = toBuffer.shadow val toWriter = toShadow.writer() @@ -61,7 +61,7 @@ class ShapeSDF : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/shape-sdf. for (v in to) { toWriter.write(v) } - toShadow.upload(0, to.size*4*4) + toShadow.upload(0, to.size * 4 * 4) segmentCount = from.size } @@ -73,6 +73,8 @@ class ShapeSDF : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/shape-sdf. parameters["fromBuffer"] = fromBuffer parameters["toBuffer"] = toBuffer parameters["segmentCount"] = segmentCount - super.apply(source, target) + // -- bit of an hack + val effectiveSource = if (source.isNotEmpty()) source else target + super.apply(effectiveSource, target) } } \ No newline at end of file