Add screenshot generation

This commit is contained in:
Edwin Jakobs
2020-04-22 21:56:08 +02:00
parent 6a29853c71
commit 60a64806fc
66 changed files with 1316 additions and 84 deletions

View File

@@ -0,0 +1,78 @@
package org.openrndr.extra.jumpfill
import org.openrndr.draw.*
import org.openrndr.extra.parameters.BooleanParameter
import org.openrndr.math.Vector4
import org.openrndr.resourceUrl
import org.openrndr.shape.Shape
import org.openrndr.shape.ShapeContour
class ShapeSDF : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/shape-sdf.frag"))) {
private val fromBuffer = bufferTexture(1024, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
private val toBuffer = bufferTexture(1024, format = ColorFormat.RGBa, type = ColorType.FLOAT32)
private var segmentCount = 0
@BooleanParameter("use UV map")
var useUV:Boolean by parameters
@BooleanParameter("rectify distance")
var rectify:Boolean by parameters
init {
useUV = false
rectify = false
}
fun setShapes(shapes: List<Shape>) {
setContours(shapes.flatMap { it.contours })
}
fun setContours(contours: List<ShapeContour>) {
val from = mutableListOf<Vector4>()
val to = mutableListOf<Vector4>()
for (contour in contours) {
val lin = contour.sampleLinear()
var contourLength = 0.0
for (segment in lin.segments) {
contourLength += segment.length
}
var offset = 0.0
for (segment in lin.segments) {
from.add(Vector4(segment.start.x, segment.start.y, offset, contourLength))
offset += segment.length
to.add(Vector4(segment.end.x, segment.end.y, offset, contourLength))
}
}
val fromShadow = fromBuffer.shadow
val fromWriter = fromShadow.writer()
fromWriter.rewind()
for (v in from) {
fromWriter.write(v)
}
fromShadow.upload(0, from.size*4*4)
val toShadow = toBuffer.shadow
val toWriter = toShadow.writer()
toWriter.rewind()
for (v in to) {
toWriter.write(v)
}
toShadow.upload(0, to.size*4*4)
segmentCount = from.size
}
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
require(target[0].type == ColorType.FLOAT16 || target[0].type == ColorType.FLOAT32) {
"needs a floating point target"
}
parameters["fromBuffer"] = fromBuffer
parameters["toBuffer"] = toBuffer
parameters["segmentCount"] = segmentCount
super.apply(source, target)
}
}

View File

@@ -0,0 +1,41 @@
package org.openrndr.extra.jumpfill.draw
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.ColorBuffer
import org.openrndr.draw.Filter
import org.openrndr.draw.filterShaderFromUrl
import org.openrndr.extra.parameters.ColorParameter
import org.openrndr.extra.parameters.Description
import org.openrndr.extra.parameters.DoubleParameter
import org.openrndr.resourceUrl
@Description("SDF stroke and fill")
class SDFStrokeFill : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/draw/sdf-stroke-fill.frag"))) {
@DoubleParameter("stroke weight", 0.0, 20.0, order = 0)
var strokeWeight: Double by parameters
@DoubleParameter("stroke feather", 0.0, 20.0, order = 0)
var strokeFeather: Double by parameters
@ColorParameter("stroke color", order = 1)
var strokeColor: ColorRGBa by parameters
@DoubleParameter("fill feather", 0.0, 20.0, order = 0)
var fillFeather: Double by parameters
@ColorParameter("fill color", order = 2)
var fillColor: ColorRGBa by parameters
init {
fillFeather = 1.0
strokeFeather = 1.0
strokeWeight = 1.0
strokeColor = ColorRGBa.BLACK
fillColor = ColorRGBa.WHITE
}
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
super.apply(source, target)
}
}

View File

@@ -0,0 +1,86 @@
package org.openrndr.extra.jumpfill.ops
import org.openrndr.draw.ColorBuffer
import org.openrndr.draw.ColorType
import org.openrndr.draw.Filter
import org.openrndr.draw.filterShaderFromUrl
import org.openrndr.extra.parameters.Description
import org.openrndr.extra.parameters.DoubleParameter
import org.openrndr.resourceUrl
class SDFSmoothUnion : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/ops/sdf-smooth-union.frag"))) {
var radius: Double by parameters
init {
radius = 0.0
}
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
require(target[0].type == ColorType.FLOAT16 || target[0].type == ColorType.FLOAT32) {
"needs a floating point target"
}
super.apply(source, target)
}
}
class SDFSmoothIntersection : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/ops/sdf-smooth-intersection.frag"))) {
var radius: Double by parameters
init {
radius = 0.0
}
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
require(target[0].type == ColorType.FLOAT16 || target[0].type == ColorType.FLOAT32) {
"needs a floating point target"
}
super.apply(source, target)
}
}
@Description("SDF smooth difference")
class SDFSmoothDifference : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/ops/sdf-smooth-difference.frag"))) {
@DoubleParameter("smooth radius", 0.0, 200.0, order = 0)
var radius: Double by parameters
init {
radius = 0.0
}
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
require(target[0].type == ColorType.FLOAT16 || target[0].type == ColorType.FLOAT32) {
"needs a floating point target"
}
super.apply(source, target)
}
}
class SDFRound : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/ops/sdf-round.frag"))) {
@DoubleParameter("rounding radius", 0.0, 200.0, order = 0)
var radius: Double by parameters
init {
radius = 0.0
}
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
require(target[0].type == ColorType.FLOAT16 || target[0].type == ColorType.FLOAT32) {
"needs a floating point target"
}
super.apply(source, target)
}
}
class SDFOnion : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/ops/sdf-onion.frag"))) {
var radius: Double by parameters
init {
radius = 0.0
}
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
require(target[0].type == ColorType.FLOAT16 || target[0].type == ColorType.FLOAT32) {
"needs a floating point target"
}
super.apply(source, target)
}
}