From cb24d4f78df92e6b318f063abe16a4b896082db2 Mon Sep 17 00:00:00 2001 From: Abe Pazos Date: Sun, 3 Aug 2025 22:22:43 +0200 Subject: [PATCH] [orx-shapes] BezierPatch: add missing user uniforms, demo (#366) --- .../kotlin/bezierpatches/BezierPatchDrawer.kt | 2 + .../kotlin/bezierpatch/DemoBezierPatch06.kt | 55 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 orx-shapes/src/jvmDemo/kotlin/bezierpatch/DemoBezierPatch06.kt diff --git a/orx-shapes/src/commonMain/kotlin/bezierpatches/BezierPatchDrawer.kt b/orx-shapes/src/commonMain/kotlin/bezierpatches/BezierPatchDrawer.kt index 7dc436fb..db40d083 100644 --- a/orx-shapes/src/commonMain/kotlin/bezierpatches/BezierPatchDrawer.kt +++ b/orx-shapes/src/commonMain/kotlin/bezierpatches/BezierPatchDrawer.kt @@ -34,6 +34,7 @@ class BezierPatchDrawer { return (""" |// BezierPatchDrawer.kt / fsGenerator |${drawerUniforms()} + |${structure.uniforms ?: ""} |${structure.varyingIn.orEmpty()} |out vec4 o_color; @@ -53,6 +54,7 @@ class BezierPatchDrawer { |${drawerUniforms()} |${ColorPhraseBook.oklabToLinearRgb.phrase} |${ColorPhraseBook.linearRgbToSRgb.phrase} + |${structure.uniforms ?: ""} |${structure.varyingIn.orEmpty()} |out vec4 o_color; |void main() { diff --git a/orx-shapes/src/jvmDemo/kotlin/bezierpatch/DemoBezierPatch06.kt b/orx-shapes/src/jvmDemo/kotlin/bezierpatch/DemoBezierPatch06.kt new file mode 100644 index 00000000..c9f77b65 --- /dev/null +++ b/orx-shapes/src/jvmDemo/kotlin/bezierpatch/DemoBezierPatch06.kt @@ -0,0 +1,55 @@ +package bezierpatch + +import org.openrndr.application +import org.openrndr.color.ColorRGBa +import org.openrndr.draw.loadImage +import org.openrndr.draw.shadeStyle +import org.openrndr.extra.shapes.bezierpatches.bezierPatch +import org.openrndr.math.Polar +import org.openrndr.shape.LineSegment +import org.openrndr.shape.Segment2D + +/** + * Shows how to + * - create a [bezierPatch] out of 4 curved Segment2D instances + * - apply an image texture to the patch using a shadeStyle + * + */ +fun main() = application { + configure { + width = 800 + height = 800 + } + program { + fun offset(n: Int) = Polar(n * 107.0, 100.0).cartesian + + // Take the window bounds, shift it inwards, then take 4 horizontal + // LineSegment instances from that Rectangle + val lineSegments = List(4) { + drawer.bounds.offsetEdges(-100.0).horizontal(1.0 - it * 0.333) + } + // Map the 4 LineSegment instances to curved Segment2D instances by + // offsetting 4 points in each. + val bentSegments = lineSegments.mapIndexed { i, seg -> + Segment2D( + seg.position(0.0) + offset(i * 4 + 1), + seg.position(0.333) + offset(i * 4 + 2), + seg.position(0.666) + offset(i * 4 + 3), + seg.position(1.0) + offset(i * 4 + 4) + ) + } + + val bp = bezierPatch(bentSegments[0], bentSegments[1], bentSegments[2], bentSegments[3]) + + val tex = loadImage("demo-data/images/peopleCity01.jpg") + val style = shadeStyle { + fragmentTransform = "x_fill = texture(p_tex, va_texCoord0.xy);" + parameter("tex", tex) + } + extend { + drawer.shadeStyle = style + drawer.clear(ColorRGBa.PINK) + drawer.bezierPatch(bp) + } + } +}