[orx-shapes] BezierPatch: add missing user uniforms, demo (#366)

This commit is contained in:
Abe Pazos
2025-08-03 22:22:43 +02:00
committed by GitHub
parent de0d757da5
commit cb24d4f78d
2 changed files with 57 additions and 0 deletions

View File

@@ -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() {

View File

@@ -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)
}
}
}