From f0013b96a7785823b233caa4e39f99460cb9c5a6 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Mon, 20 Jul 2020 14:34:11 +0200 Subject: [PATCH] [openrndr-demos] Add demo for circle billboards --- .../src/demo/kotlin/DemoBillboardCircles01.kt | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 openrndr-demos/src/demo/kotlin/DemoBillboardCircles01.kt diff --git a/openrndr-demos/src/demo/kotlin/DemoBillboardCircles01.kt b/openrndr-demos/src/demo/kotlin/DemoBillboardCircles01.kt new file mode 100644 index 00000000..a45cca6d --- /dev/null +++ b/openrndr-demos/src/demo/kotlin/DemoBillboardCircles01.kt @@ -0,0 +1,61 @@ +// Demonstration of circles that always face the camera + +import org.openrndr.WindowMultisample +import org.openrndr.application +import org.openrndr.color.ColorRGBa +import org.openrndr.draw.* +import org.openrndr.extra.noise.uniformRing +import org.openrndr.extras.camera.Orbital +import org.openrndr.math.Vector2 +import org.openrndr.math.Vector3 + + +fun main() = application { + + configure { + multisample = WindowMultisample.SampleCount(8) + } + program { + extend(Orbital()) + + + val circlePositions = vertexBuffer(vertexFormat { + attribute("position", VertexElementType.VECTOR3_FLOAT32) + attribute("scale", VertexElementType.FLOAT32) + }, 1000) + + circlePositions.put { + for (i in 0 until circlePositions.vertexCount) { + write(Vector3.uniformRing(0.0, 3.0)) + write(Math.random().toFloat()*0.1f) + } + } + + + extend { + 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.drawStyle.alphaToCoverage = true + + drawer.depthWrite = true + drawer.depthTestPass = DepthTestPass.LESS_OR_EQUAL + + drawer.shadeStyle = shadeStyle { + vertexTransform = """ + vec3 viewOffset = (x_viewMatrix * x_modelMatrix * vec4(i_position, 1.0)).xyz; + vec2 i = vec2(0.0, 1.0); + x_viewMatrix = mat4(i.yxxx, i.xyxx, i.xxyx, i.xxxy); + x_modelMatrix = mat4(i.yxxx, i.xyxx, i.xxyx, i.xxxy); + x_position = viewOffset + vec3(a_position.xy * i_scale, 0.0); + vi_radius = vec2(i_scale); + """.trimIndent() + attributes(circlePositions) + } + + drawer.circles((0 until circlePositions.vertexCount).map { Vector2.ZERO }, 0.0) + } + } +} \ No newline at end of file