Skip to content

Commit ddea26a

Browse files
committed
[orx-shapes] BezierPatch: add missing user uniforms, demo
1 parent bef1a75 commit ddea26a

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

orx-shapes/src/commonMain/kotlin/bezierpatches/BezierPatchDrawer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class BezierPatchDrawer {
3434
return ("""
3535
|// BezierPatchDrawer.kt / fsGenerator
3636
|${drawerUniforms()}
37+
|${structure.uniforms ?: ""}
3738
|${structure.varyingIn.orEmpty()}
3839
3940
|out vec4 o_color;
@@ -53,6 +54,7 @@ class BezierPatchDrawer {
5354
|${drawerUniforms()}
5455
|${ColorPhraseBook.oklabToLinearRgb.phrase}
5556
|${ColorPhraseBook.linearRgbToSRgb.phrase}
57+
|${structure.uniforms ?: ""}
5658
|${structure.varyingIn.orEmpty()}
5759
|out vec4 o_color;
5860
|void main() {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package bezierpatch
2+
3+
import org.openrndr.application
4+
import org.openrndr.color.ColorRGBa
5+
import org.openrndr.draw.loadImage
6+
import org.openrndr.draw.shadeStyle
7+
import org.openrndr.extra.shapes.bezierpatches.bezierPatch
8+
import org.openrndr.math.Polar
9+
import org.openrndr.shape.LineSegment
10+
import org.openrndr.shape.Segment2D
11+
12+
/**
13+
* Shows how to
14+
* - create a [bezierPatch] out of 4 curved Segment2D instances
15+
* - apply an image texture to the patch using a shadeStyle
16+
*
17+
*/
18+
fun main() = application {
19+
configure {
20+
width = 800
21+
height = 800
22+
}
23+
program {
24+
fun offset(n: Int) = Polar(n * 107.0, 100.0).cartesian
25+
26+
// Take the window bounds, shift it inwards, then take 4 horizontal
27+
// LineSegment instances from that Rectangle
28+
val lineSegments = List(4) {
29+
drawer.bounds.offsetEdges(-100.0).horizontal(1.0 - it * 0.333)
30+
}
31+
// Map the 4 LineSegment instances to curved Segment2D instances by
32+
// offsetting 4 points in each.
33+
val bentSegments = lineSegments.mapIndexed { i, seg ->
34+
Segment2D(
35+
seg.position(0.0) + offset(i * 4 + 1),
36+
seg.position(0.333) + offset(i * 4 + 2),
37+
seg.position(0.666) + offset(i * 4 + 3),
38+
seg.position(1.0) + offset(i * 4 + 4)
39+
)
40+
}
41+
42+
val bp = bezierPatch(bentSegments[0], bentSegments[1], bentSegments[2], bentSegments[3])
43+
44+
val tex = loadImage("demo-data/images/peopleCity01.jpg")
45+
val style = shadeStyle {
46+
fragmentTransform = "x_fill = texture(p_tex, va_texCoord0.xy);"
47+
parameter("tex", tex)
48+
}
49+
extend {
50+
drawer.shadeStyle = style
51+
drawer.clear(ColorRGBa.PINK)
52+
drawer.bezierPatch(bp)
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)