Fix demos (#331)

This commit is contained in:
Abe Pazos
2024-04-02 13:17:06 +02:00
committed by GitHub
parent 275f677cf3
commit 1060f751d7
9 changed files with 113 additions and 85 deletions

View File

@@ -26,7 +26,7 @@ fun main() = application {
circlePositions.put {
for (i in 0 until circlePositions.vertexCount) {
write(Vector3.uniformRing(0.0, 3.0))
write(Vector3.uniformRing(2.0, 3.0))
write(Math.random().toFloat()*0.1f)
}
}
@@ -36,8 +36,7 @@ fun main() = application {
drawer.perspective(90.0, width*1.0/height*1.0, 0.1, 100.0)
drawer.fill = ColorRGBa.PINK
drawer.stroke = ColorRGBa.GREEN
drawer.strokeWeight = 0.05
drawer.stroke = null
drawer.drawStyle.alphaToCoverage = true
drawer.depthWrite = true
@@ -52,6 +51,14 @@ fun main() = application {
x_position = viewOffset + vec3(a_position.xy * i_scale, 0.0);
vi_radius = vec2(i_scale);
""".trimIndent()
// The circle bounds can be used to calculate a color or to sample a texture
fragmentTransform = """
float r = length(c_boundsPosition.xy - 0.5) * 2.0;
x_fill.rg = c_boundsPosition.xy;
x_fill.a = 1.0 - step(1.0, r);
""".trimIndent()
attributes(circlePositions)
}

View File

@@ -1,37 +0,0 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.math.Vector2
import org.openrndr.shape.drawComposition
//import org.openrndr.svg.svgNamespaceInkscape
import org.openrndr.svg.toSVG
import org.openrndr.svg.writeSVG
fun main() {
application {
program {
extend {
drawer.clear(ColorRGBa.WHITE)
val composition = drawComposition {
val layer = group {
fill = ColorRGBa.PINK
stroke = ColorRGBa.BLACK
strokeWeight = 10.0
circle(Vector2(width / 2.0, height / 2.0), 100.0)
circle(Vector2(200.0, 200.0), 50.0)
}
// demonstrating how to set custom attributes on the CompositionNode
// these are stored in SVG
// layer.id = "Layer_2"
// layer.attributes["inkscape:label"] = "Layer 1"
// layer.attributes["inkscape:groupmode"] = "layer"
}
// draw the composition to the screen
drawer.composition(composition)
// print the svg to the console
// println(composition.toSVG(namespaces = listOf(svgNamespaceInkscape)))
}
}
}
}

View File

@@ -1,39 +1,51 @@
//import org.openrndr.application
//import org.openrndr.draw.VertexElementType
//import org.openrndr.draw.shadeStyle
//import org.openrndr.draw.shaderStorageBuffer
//import org.openrndr.draw.shaderStorageFormat
//import java.nio.ByteBuffer
//import java.nio.ByteOrder
//
//fun main() = application {
// program {
//
// val ssb = shaderStorageBuffer(shaderStorageFormat {
// //member("foo", VertexElementType.FLOAT32, 1000)
//
// })
// val ss = shadeStyle {
// buffer("someBuffer", ssb)
// fragmentTransform = "float a = b_someBuffer.foo[0]; b_someBuffer.foo[1] += 2.0;"
// }
//
// val bb = ByteBuffer.allocateDirect(ssb.format.size)
// bb.order(ByteOrder.nativeOrder())
//
// extend {
// ssb.clear()
//
// drawer.shadeStyle = ss
// drawer.circle(100.0, 100.0, 200.0)
// bb.rewind()
// ssb.read(bb)
// bb.rewind()
// val f0 = bb.float
// val f1 = bb.float
// println(f1)
//
// }
//
// }
//}
import org.openrndr.application
import org.openrndr.draw.*
import java.nio.ByteBuffer
import java.nio.ByteOrder
// A demo of shaderStorageBuffer doing no useful work
fun main() = application {
program {
// Construct a SSB
val ssb = shaderStorageBuffer(shaderStorageFormat {
primitive("foo", BufferPrimitiveType.FLOAT32, 1000)
})
// A ShadeStyle that reads from and writes into an SSB
val ss = shadeStyle {
buffer("someBuffer", ssb)
fragmentTransform = """
float a = b_someBuffer.foo[0];
b_someBuffer.foo[1] += 2.0;
""".trimIndent()
}
// A ByteBuffer in RAM to download the GPU data into
val bb = ByteBuffer.allocateDirect(ssb.format.size)
bb.order(ByteOrder.nativeOrder())
extend {
// Clear the SSB
ssb.clear()
drawer.shadeStyle = ss
drawer.circle(100.0, 100.0, 200.0)
// Download the SSB into RAM
bb.rewind()
ssb.read(bb)
bb.rewind()
val f0 = bb.float
val f1 = bb.float
println(f1)
// The shade style runs for every pix el in the circle.
// The order in which the pixels are processed is not known
// Therefore the value of `f1` can vary from frame to frame,
// because we don't know how many times `+= 2.0` was executed.
}
}
}

View File

@@ -44,6 +44,7 @@ kotlin {
implementation(project(":orx-mesh-generators"))
implementation(project(":orx-color"))
implementation(project(":orx-jvm:orx-gui"))
implementation(project(":orx-shade-styles"))
}
}
}

View File

@@ -22,8 +22,8 @@ kotlin {
@Suppress("UNUSED_VARIABLE")
val jvmDemo by getting {
dependencies {
implementation(project(":orx-shapes"))
implementation(project(":orx-svg"))
}
}
}
}
}

View File

@@ -0,0 +1,42 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.composition.composition
import org.openrndr.extra.composition.drawComposition
import org.openrndr.extra.svg.saveToFile
import org.openrndr.extra.svg.toSVG
import org.openrndr.math.Vector2
import java.io.File
fun main() {
application {
program {
val composition = drawComposition {
val layer = group {
fill = ColorRGBa.PINK
stroke = ColorRGBa.BLACK
strokeWeight = 10.0
circle(Vector2(width / 2.0, height / 2.0), 100.0)
circle(Vector2(200.0, 200.0), 50.0)
}
// demonstrating how to set custom attributes on the CompositionNode
// these are stored in SVG
//layer.id = "Layer_2"
//layer.attributes["inkscape:label"] = "Layer 1"
//layer.attributes["inkscape:groupmode"] = "layer"
}
// print the svg to the console
println(composition.toSVG())
// save svg to a File
//composition.saveToFile(File("/path/to/design.svg"))
extend {
drawer.clear(ColorRGBa.WHITE)
// draw the composition to the screen
drawer.composition(composition)
}
}
}
}

View File

@@ -1,7 +1,8 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.shape.ClipMode
import org.openrndr.shape.drawComposition
import org.openrndr.extra.composition.ClipMode
import org.openrndr.extra.composition.composition
import org.openrndr.extra.composition.drawComposition
fun main() {
application {

View File

@@ -1,7 +1,8 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.shape.ClipMode
import org.openrndr.shape.drawComposition
import org.openrndr.extra.composition.ClipMode
import org.openrndr.extra.composition.composition
import org.openrndr.extra.composition.drawComposition
fun main() {
application {

View File

@@ -63,6 +63,7 @@ fun main() {
is HashBlur -> {
blur.samples = 50
blur.radius = 5.0
blur.time = seconds
}
is GaussianBlur -> {
blur.window = 25