[orx-shapes] convert to MPP
This commit is contained in:
@@ -29,6 +29,7 @@ def multiplatformModules = [
|
|||||||
"orx-parameters",
|
"orx-parameters",
|
||||||
"orx-shade-styles",
|
"orx-shade-styles",
|
||||||
"orx-shader-phrases",
|
"orx-shader-phrases",
|
||||||
|
"orx-shapes",
|
||||||
"orx-quadtree",
|
"orx-quadtree",
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -3,7 +3,12 @@
|
|||||||
|
|
||||||
// Ad[a|o]pted from shader by "noby" https://www.shadertoy.com/view/3sGSWV
|
// Ad[a|o]pted from shader by "noby" https://www.shadertoy.com/view/3sGSWV
|
||||||
uniform sampler2D tex0;
|
uniform sampler2D tex0;
|
||||||
|
|
||||||
|
#ifdef OR_IN_OUT
|
||||||
in vec2 v_texCoord0;
|
in vec2 v_texCoord0;
|
||||||
|
#else
|
||||||
|
varying vec2 v_texCoord0;
|
||||||
|
#endif
|
||||||
|
|
||||||
uniform bool useColor;// false
|
uniform bool useColor;// false
|
||||||
uniform float time;
|
uniform float time;
|
||||||
@@ -15,8 +20,9 @@ uniform float grainPitch;// = 1.0;
|
|||||||
|
|
||||||
uniform float colorLevel;// = 1.0;
|
uniform float colorLevel;// = 1.0;
|
||||||
|
|
||||||
|
#ifndef OR_GL_FRAGCOLOR
|
||||||
out vec4 o_output;
|
out vec4 o_output;
|
||||||
|
#endif
|
||||||
|
|
||||||
// From Dave Hoskins: https://www.shadertoy.com/view/4djSRW.
|
// From Dave Hoskins: https://www.shadertoy.com/view/4djSRW.
|
||||||
float hash(vec3 p3){
|
float hash(vec3 p3){
|
||||||
@@ -59,7 +65,12 @@ void main() {
|
|||||||
// Alternatively use iTime here instead and change the grain_rate
|
// Alternatively use iTime here instead and change the grain_rate
|
||||||
// parameter to correspond to frames-per-second.
|
// parameter to correspond to frames-per-second.
|
||||||
float t = time;
|
float t = time;
|
||||||
|
#ifndef OR_GL_TEXTURE2D
|
||||||
vec4 colorAlpha = texture(tex0, uv);
|
vec4 colorAlpha = texture(tex0, uv);
|
||||||
|
#else
|
||||||
|
vec4 colorAlpha = texture2D(tex0, uv);
|
||||||
|
#endif
|
||||||
|
|
||||||
vec3 color = colorAlpha.rgb;
|
vec3 color = colorAlpha.rgb;
|
||||||
vec3 grain = vec3(0);
|
vec3 grain = vec3(0);
|
||||||
|
|
||||||
@@ -86,6 +97,11 @@ void main() {
|
|||||||
|
|
||||||
// After this you would normally perform tone mapping,
|
// After this you would normally perform tone mapping,
|
||||||
// apply the grain before that.
|
// apply the grain before that.
|
||||||
|
#ifndef OR_GL_FRACOLOR
|
||||||
o_output.rgb = color;
|
o_output.rgb = color;
|
||||||
o_output.a = 1.0;
|
o_output.a = 1.0;
|
||||||
|
#else
|
||||||
|
gl_FragColor.rgb = color;
|
||||||
|
gl_FragColor.a = 1.0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ class ShaderPhrase(val phrase: String) {
|
|||||||
* A book of shader phrases.
|
* A book of shader phrases.
|
||||||
*/
|
*/
|
||||||
expect open class ShaderPhraseBook(bookId: String) {
|
expect open class ShaderPhraseBook(bookId: String) {
|
||||||
//private var registered = false
|
val bookId: String
|
||||||
/**
|
/**
|
||||||
* Registers all known shader phrases
|
* Registers all known shader phrases
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package org.openrndr.extra.shaderphrases
|
|||||||
/**
|
/**
|
||||||
* A book of shader phrases.
|
* A book of shader phrases.
|
||||||
*/
|
*/
|
||||||
actual open class ShaderPhraseBook actual constructor(val bookId: String) {
|
actual open class ShaderPhraseBook actual constructor(actual val bookId: String) {
|
||||||
private var registered = false
|
private var registered = false
|
||||||
/**
|
/**
|
||||||
* Registers all known shader phrases
|
* Registers all known shader phrases
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import kotlin.reflect.full.declaredMemberProperties
|
|||||||
/**
|
/**
|
||||||
* A book of shader phrases.
|
* A book of shader phrases.
|
||||||
*/
|
*/
|
||||||
actual open class ShaderPhraseBook actual constructor(val bookId: String) {
|
actual open class ShaderPhraseBook actual constructor(actual val bookId: String) {
|
||||||
private var registered = false
|
private var registered = false
|
||||||
/**
|
/**
|
||||||
* Registers all known shader phrases
|
* Registers all known shader phrases
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
sourceSets {
|
|
||||||
demo {
|
|
||||||
java {
|
|
||||||
srcDirs = ["src/demo/kotlin"]
|
|
||||||
compileClasspath += main.getCompileClasspath()
|
|
||||||
runtimeClasspath += main.getRuntimeClasspath()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation(project(":orx-color"))
|
|
||||||
implementation(project(":orx-shader-phrases"))
|
|
||||||
demoImplementation("org.openrndr:openrndr-application:$openrndrVersion")
|
|
||||||
demoImplementation("org.openrndr:openrndr-extensions:$openrndrVersion")
|
|
||||||
demoRuntimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion")
|
|
||||||
demoRuntimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion")
|
|
||||||
demoImplementation(sourceSets.getByName("main").output)
|
|
||||||
}
|
|
||||||
98
orx-shapes/build.gradle.kts
Normal file
98
orx-shapes/build.gradle.kts
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import Orx_embed_shaders_gradle.EmbedShadersTask
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
kotlin("plugin.serialization")
|
||||||
|
id("orx.embed-shaders")
|
||||||
|
}
|
||||||
|
|
||||||
|
val kotlinxSerializationVersion: String by rootProject.extra
|
||||||
|
val kotestVersion: String by rootProject.extra
|
||||||
|
val junitJupiterVersion: String by rootProject.extra
|
||||||
|
val jvmTarget: String by rootProject.extra
|
||||||
|
val kotlinApiVersion: String by rootProject.extra
|
||||||
|
val kotlinVersion: String by rootProject.extra
|
||||||
|
val kotlinLoggingVersion: String by rootProject.extra
|
||||||
|
val kluentVersion: String by rootProject.extra
|
||||||
|
val openrndrVersion: String by rootProject.extra
|
||||||
|
val openrndrOS: String by rootProject.extra
|
||||||
|
val spekVersion: String by rootProject.extra
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
jvm {
|
||||||
|
compilations {
|
||||||
|
val demo by creating {
|
||||||
|
defaultSourceSet {
|
||||||
|
kotlin.srcDir("src/demo")
|
||||||
|
dependencies {
|
||||||
|
implementation(project(":orx-camera"))
|
||||||
|
implementation(project(":orx-color"))
|
||||||
|
implementation("org.openrndr:openrndr-application:$openrndrVersion")
|
||||||
|
implementation("org.openrndr:openrndr-extensions:$openrndrVersion")
|
||||||
|
runtimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion")
|
||||||
|
runtimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion")
|
||||||
|
implementation(compilations["main"]!!.output.allOutputs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
compilations.all {
|
||||||
|
kotlinOptions.jvmTarget = jvmTarget
|
||||||
|
kotlinOptions.apiVersion = kotlinApiVersion
|
||||||
|
}
|
||||||
|
testRuns["test"].executionTask.configure {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
js(IR) {
|
||||||
|
browser()
|
||||||
|
nodejs()
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
@Suppress("UNUSED_VARIABLE")
|
||||||
|
val commonMain by getting {
|
||||||
|
dependencies {
|
||||||
|
implementation(project(":orx-parameters"))
|
||||||
|
implementation(project(":orx-shader-phrases"))
|
||||||
|
implementation(project(":orx-color"))
|
||||||
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlinxSerializationVersion")
|
||||||
|
implementation("org.openrndr:openrndr-application:$openrndrVersion")
|
||||||
|
implementation("org.openrndr:openrndr-draw:$openrndrVersion")
|
||||||
|
implementation("org.openrndr:openrndr-filter:$openrndrVersion")
|
||||||
|
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
|
||||||
|
implementation("io.github.microutils:kotlin-logging:$kotlinLoggingVersion")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Suppress("UNUSED_VARIABLE")
|
||||||
|
val commonTest by getting {
|
||||||
|
dependencies {
|
||||||
|
implementation(kotlin("test-common"))
|
||||||
|
implementation(kotlin("test-annotations-common"))
|
||||||
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion")
|
||||||
|
implementation("io.kotest:kotest-assertions-core:$kotestVersion")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("UNUSED_VARIABLE")
|
||||||
|
val jvmTest by getting {
|
||||||
|
dependencies {
|
||||||
|
implementation(kotlin("test-common"))
|
||||||
|
implementation(kotlin("test-annotations-common"))
|
||||||
|
implementation(kotlin("test-junit5"))
|
||||||
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion")
|
||||||
|
runtimeOnly("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion")
|
||||||
|
runtimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion")
|
||||||
|
implementation("org.spekframework.spek2:spek-dsl-jvm:$spekVersion")
|
||||||
|
implementation("org.amshove.kluent:kluent:$kluentVersion")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("UNUSED_VARIABLE")
|
||||||
|
val jsTest by getting {
|
||||||
|
dependencies {
|
||||||
|
implementation(kotlin("test-js"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,19 @@
|
|||||||
package org.openrndr.extra.shapes
|
package org.openrndr.extra.shapes
|
||||||
|
|
||||||
import org.openrndr.math.Vector2
|
import org.openrndr.math.Vector2
|
||||||
|
import org.openrndr.math.asRadians
|
||||||
import org.openrndr.shape.ShapeContour
|
import org.openrndr.shape.ShapeContour
|
||||||
import org.openrndr.shape.contour
|
import org.openrndr.shape.contour
|
||||||
|
import kotlin.math.PI
|
||||||
import kotlin.math.cos
|
import kotlin.math.cos
|
||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
|
|
||||||
fun regularPolygon(sides: Int, center: Vector2 = Vector2.ZERO, radius: Double = 100.0, phase: Double = 0.0): ShapeContour {
|
fun regularPolygon(sides: Int, center: Vector2 = Vector2.ZERO, radius: Double = 100.0, phase: Double = 0.0): ShapeContour {
|
||||||
val c = contour {
|
val c = contour {
|
||||||
val phi = Math.toRadians(phase)
|
val phi = phase.asRadians
|
||||||
for (i in 0 until sides) {
|
for (i in 0 until sides) {
|
||||||
val x = center.x + radius * cos(i.toDouble() / sides * Math.PI * 2 + phi)
|
val x = center.x + radius * cos(i.toDouble() / sides * PI * 2 + phi)
|
||||||
val y = center.y + radius * sin(i.toDouble() / sides * Math.PI * 2 + phi)
|
val y = center.y + radius * sin(i.toDouble() / sides * PI * 2 + phi)
|
||||||
|
|
||||||
moveOrLineTo(x, y)
|
moveOrLineTo(x, y)
|
||||||
}
|
}
|
||||||
@@ -22,16 +24,16 @@ fun regularPolygon(sides: Int, center: Vector2 = Vector2.ZERO, radius: Double =
|
|||||||
|
|
||||||
fun regularPolygonRounded(sides: Int, roundFactor: Double = 0.5, center: Vector2 = Vector2.ZERO, radius: Double = 100.0, phase: Double = 0.0): ShapeContour {
|
fun regularPolygonRounded(sides: Int, roundFactor: Double = 0.5, center: Vector2 = Vector2.ZERO, radius: Double = 100.0, phase: Double = 0.0): ShapeContour {
|
||||||
val c = contour {
|
val c = contour {
|
||||||
val phi = Math.toRadians(phase)
|
val phi = phase.asRadians
|
||||||
for (i in 0 until sides) {
|
for (i in 0 until sides) {
|
||||||
val x0 = center.x + radius * cos(i.toDouble() / sides * Math.PI * 2 + phi)
|
val x0 = center.x + radius * cos(i.toDouble() / sides * PI * 2 + phi)
|
||||||
val y0 = center.y + radius * sin(i.toDouble() / sides * Math.PI * 2 + phi)
|
val y0 = center.y + radius * sin(i.toDouble() / sides * PI * 2 + phi)
|
||||||
|
|
||||||
val x1 = center.x + radius * cos((i + 1.0) / sides * Math.PI * 2 + phi)
|
val x1 = center.x + radius * cos((i + 1.0) / sides * PI * 2 + phi)
|
||||||
val y1 = center.y + radius * sin((i + 1.0) / sides * Math.PI * 2 + phi)
|
val y1 = center.y + radius * sin((i + 1.0) / sides * PI * 2 + phi)
|
||||||
|
|
||||||
val x2 = center.x + radius * cos((i + 2.0) / sides * Math.PI * 2 + phi)
|
val x2 = center.x + radius * cos((i + 2.0) / sides * PI * 2 + phi)
|
||||||
val y2 = center.y + radius * sin((i + 2.0) / sides * Math.PI * 2 + phi)
|
val y2 = center.y + radius * sin((i + 2.0) / sides * PI * 2 + phi)
|
||||||
|
|
||||||
val f = roundFactor / 2.0
|
val f = roundFactor / 2.0
|
||||||
|
|
||||||
@@ -60,16 +62,16 @@ fun regularPolygonRounded(sides: Int, roundFactor: Double = 0.5, center: Vector2
|
|||||||
|
|
||||||
fun regularPolygonBeveled(sides: Int, bevelFactor: Double = 0.5, center: Vector2 = Vector2.ZERO, radius: Double = 100.0, phase: Double = 0.0): ShapeContour {
|
fun regularPolygonBeveled(sides: Int, bevelFactor: Double = 0.5, center: Vector2 = Vector2.ZERO, radius: Double = 100.0, phase: Double = 0.0): ShapeContour {
|
||||||
val c = contour {
|
val c = contour {
|
||||||
val phi = Math.toRadians(phase)
|
val phi = phase.asRadians
|
||||||
for (i in 0 until sides) {
|
for (i in 0 until sides) {
|
||||||
val x0 = center.x + radius * cos(i.toDouble() / sides * Math.PI * 2 + phi)
|
val x0 = center.x + radius * cos(i.toDouble() / sides * PI * 2 + phi)
|
||||||
val y0 = center.y + radius * sin(i.toDouble() / sides * Math.PI * 2 + phi)
|
val y0 = center.y + radius * sin(i.toDouble() / sides * PI * 2 + phi)
|
||||||
|
|
||||||
val x1 = center.x + radius * cos((i + 1.0) / sides * Math.PI * 2 + phi)
|
val x1 = center.x + radius * cos((i + 1.0) / sides * PI * 2 + phi)
|
||||||
val y1 = center.y + radius * sin((i + 1.0) / sides * Math.PI * 2 + phi)
|
val y1 = center.y + radius * sin((i + 1.0) / sides * PI * 2 + phi)
|
||||||
|
|
||||||
val x2 = center.x + radius * cos((i + 2.0) / sides * Math.PI * 2 + phi)
|
val x2 = center.x + radius * cos((i + 2.0) / sides * PI * 2 + phi)
|
||||||
val y2 = center.y + radius * sin((i + 2.0) / sides * Math.PI * 2 + phi)
|
val y2 = center.y + radius * sin((i + 2.0) / sides * PI * 2 + phi)
|
||||||
|
|
||||||
val f = bevelFactor / 2.0
|
val f = bevelFactor / 2.0
|
||||||
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.openrndr.extra.shapes
|
package org.openrndr.extra.shapes
|
||||||
|
|
||||||
import org.openrndr.math.Vector2
|
import org.openrndr.math.Vector2
|
||||||
|
import org.openrndr.math.asRadians
|
||||||
import org.openrndr.shape.ShapeContour
|
import org.openrndr.shape.ShapeContour
|
||||||
import org.openrndr.shape.contour
|
import org.openrndr.shape.contour
|
||||||
import kotlin.math.PI
|
import kotlin.math.PI
|
||||||
@@ -9,7 +10,7 @@ import kotlin.math.sin
|
|||||||
|
|
||||||
fun regularStar(points: Int, innerRadius: Double, outerRadius: Double, center: Vector2 = Vector2.ZERO, phase: Double = 0.0): ShapeContour {
|
fun regularStar(points: Int, innerRadius: Double, outerRadius: Double, center: Vector2 = Vector2.ZERO, phase: Double = 0.0): ShapeContour {
|
||||||
return contour {
|
return contour {
|
||||||
val theta = Math.toRadians(phase)
|
val theta = phase.asRadians
|
||||||
val phi = PI * 2.0 / (points * 2)
|
val phi = PI * 2.0 / (points * 2)
|
||||||
for (i in 0 until points * 2 step 2) {
|
for (i in 0 until points * 2 step 2) {
|
||||||
val outerPoint = Vector2(cos(i * phi + theta), sin(i * phi + theta)) * outerRadius + center
|
val outerPoint = Vector2(cos(i * phi + theta), sin(i * phi + theta)) * outerRadius + center
|
||||||
@@ -26,7 +27,7 @@ fun regularStarRounded(points: Int, innerRadius: Double, outerRadius: Double,
|
|||||||
center: Vector2 = Vector2.ZERO,
|
center: Vector2 = Vector2.ZERO,
|
||||||
phase: Double = 0.0): ShapeContour {
|
phase: Double = 0.0): ShapeContour {
|
||||||
return contour {
|
return contour {
|
||||||
val theta = Math.toRadians(phase)
|
val theta = phase.asRadians
|
||||||
val phi = PI * 2.0 / (points * 2)
|
val phi = PI * 2.0 / (points * 2)
|
||||||
for (i in 0 until points * 2 step 2) {
|
for (i in 0 until points * 2 step 2) {
|
||||||
val outerPoint0 = Vector2(cos(i * phi + theta), sin(i * phi + theta)) * outerRadius + center
|
val outerPoint0 = Vector2(cos(i * phi + theta), sin(i * phi + theta)) * outerRadius + center
|
||||||
@@ -56,7 +57,7 @@ fun regularStarBeveled(points: Int, innerRadius: Double, outerRadius: Double,
|
|||||||
center: Vector2 = Vector2.ZERO,
|
center: Vector2 = Vector2.ZERO,
|
||||||
phase: Double = 0.0): ShapeContour {
|
phase: Double = 0.0): ShapeContour {
|
||||||
return contour {
|
return contour {
|
||||||
val theta = Math.toRadians(phase)
|
val theta = phase.asRadians
|
||||||
val phi = PI * 2.0 / (points * 2)
|
val phi = PI * 2.0 / (points * 2)
|
||||||
for (i in 0 until points * 2 step 2) {
|
for (i in 0 until points * 2 step 2) {
|
||||||
val outerPoint0 = Vector2(cos(i * phi + theta), sin(i * phi + theta)) * outerRadius + center
|
val outerPoint0 = Vector2(cos(i * phi + theta), sin(i * phi + theta)) * outerRadius + center
|
||||||
@@ -14,6 +14,7 @@ import org.openrndr.extra.shapes.phrases.BezierPhraseBook
|
|||||||
import org.openrndr.extras.color.phrases.ColorPhraseBook
|
import org.openrndr.extras.color.phrases.ColorPhraseBook
|
||||||
import org.openrndr.extras.color.spaces.ColorOKLABa
|
import org.openrndr.extras.color.spaces.ColorOKLABa
|
||||||
import org.openrndr.math.Vector4
|
import org.openrndr.math.Vector4
|
||||||
|
import kotlin.jvm.JvmName
|
||||||
|
|
||||||
private val glslVersion = "410 core"
|
private val glslVersion = "410 core"
|
||||||
|
|
||||||
Reference in New Issue
Block a user