Merge branch 'master' into feature/7/kinect1Support

# Conflicts:
#	build.gradle
This commit is contained in:
Kazik Pogoda
2019-08-16 09:44:18 +02:00
5 changed files with 98 additions and 77 deletions

View File

@@ -37,7 +37,9 @@ plugins {
//}
project.ext {
openrndrVersion = "0.3.35-rc1"
openrndrVersion = "0.3.35"
kotlinVersion = "1.3.41"
spekVersion = "2.0.6"
libfreenectVersion = "0.5.7-1.5.1"
}
@@ -67,13 +69,25 @@ allprojects {
maven {
url = "https://dl.bintray.com/openrndr/openrndr"
}
maven {
url "https://dl.bintray.com/spekframework/spek"
}
}
dependencies {
compile "org.openrndr:openrndr-core:$openrndrVersion"
compile "org.openrndr:openrndr-filter:$openrndrVersion"
compile "org.openrndr:openrndr-shape:$openrndrVersion"
compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.3.0-RC'
compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.3.0-RC2'
testImplementation "org.spekframework.spek2:spek-dsl-jvm:$spekVersion"
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVersion"
testRuntimeOnly "org.spekframework.spek2:spek-runner-junit5:$spekVersion"
testRuntimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
}
contacts {
@@ -97,4 +111,9 @@ allprojects {
}
}
test {
useJUnitPlatform {
includeEngines 'spek2'
}
}
}

View File

@@ -5,6 +5,9 @@ import org.openrndr.draw.*
import org.openrndr.filter.blend.passthrough
import org.openrndr.math.Matrix44
import org.openrndr.resourceUrl
import kotlin.math.ceil
import kotlin.math.max
import kotlin.math.pow
class EncodePoints : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/encode-points.frag")))
class JumpFlood : Filter(filterShaderFromUrl(resourceUrl("/shaders/gl3/jumpflood.frag"))) {
@@ -30,38 +33,26 @@ private val pixelDirection by lazy { PixelDirection() }
private val contourPoints by lazy { ContourPoints() }
private val threshold by lazy { Threshold() }
class JumpFlooder(val width: Int, val height: Int) {
private val dimension = Math.max(width, height)
private val exp = Math.ceil(Math.log(dimension.toDouble()) / Math.log(2.0)).toInt()
private val squareDim = Math.pow(2.0, exp.toDouble()).toInt()
class JumpFlooder(val width: Int, val height: Int, format:ColorFormat = ColorFormat.RGB, type:ColorType = ColorType.FLOAT32) {
private val dimension = max(width, height)
private val exp = ceil(Math.log(dimension.toDouble()) / Math.log(2.0)).toInt()
private val squareDim = 2.0.pow(exp.toDouble()).toInt()
private val coordinates =
listOf(colorBuffer(squareDim, squareDim, format = ColorFormat.RGB, type = ColorType.FLOAT32),
colorBuffer(squareDim, squareDim, format = ColorFormat.RGB, type = ColorType.FLOAT32))
listOf(colorBuffer(squareDim, squareDim, format = format, type = type),
colorBuffer(squareDim, squareDim, format = format, type = type))
private val final = renderTarget(width, height) {
colorBuffer(type = ColorType.FLOAT32)
colorBuffer(format = format, type = type)
}
val encoded: ColorBuffer get() = final.colorBuffer(0)
private val square = renderTarget(squareDim, squareDim) {
colorBuffer()
colorBuffer(format = format, type = type)
}
// fun distanceToContour(drawer: Drawer, input: ColorBuffer, thresholdValue: Double = 0.5): ColorBuffer {
// threshold.threshold = thresholdValue
// threshold.apply(input, thresholded)
// contourPoints.apply(thresholded, edges)
// contourUsed = true
// return jumpFlood(drawer, edges)
// }
// fun directions(xRange: IntProgression = 0 until width, yRange: IntProgression = 0 until height): Array<List<Vector2>> {
// result.shadow.download()
// return result.shadow.mapIndexed(xRange, yRange) { _, _, r, g, _, _ -> Vector2(r, g) }
// }
fun jumpFlood(drawer: Drawer, input: ColorBuffer): ColorBuffer {
if (input.width != width || input.height != height) {
throw IllegalArgumentException("dimensions mismatch")
@@ -140,4 +131,3 @@ fun directionFieldFromBitmap(drawer: Drawer, bitmap: ColorBuffer,
jumpFlooder: JumpFlooder? = null,
result: ColorBuffer? = null
): ColorBuffer = encodeDecodeBitmap(drawer, contourPoints, pixelDirection, bitmap, jumpFlooder, result)

View File

@@ -1,16 +1,16 @@
#version 330 core
uniform sampler2D tex0;
in vec2 v_texCoord0;
out vec4 o_color;
void main() {
float ref = texture(tex0, v_texCoord0).r;
vec4 outc = vec4(-1.0, -1.0, 0.0, 1.0);
if (ref > 0.5) {
outc.xy = v_texCoord0.xy;
}
o_color = outc;
#version 330 core
uniform sampler2D tex0;
in vec2 v_texCoord0;
out vec4 o_color;
void main() {
vec4 t = texture(tex0, v_texCoord0);
vec4 outc = vec4(-1.0, -1.0, t.r, 1.0);
if (t.r > 0.0) {
outc.xy = v_texCoord0.xy;
}
o_color = outc;
}

View File

@@ -1,39 +1,39 @@
#version 330 core
in vec2 v_texCoord0;
uniform sampler2D tex0;
uniform int maxSteps;
uniform int step;
out vec4 o_color;
void main() {
float stepwidth = 1.0 / pow(2.0, step+1);
float bestDistance = 9999.0;
vec2 bestCoord = vec2(-1.0);
vec2 bestColor = vec2(-1.0);
vec2 is = vec2(1.0) / textureSize(tex0, 0);
float found = 0.0;
for (int y = -1; y <= 1; ++y) {
for (int x = -1; x <= 1; ++x) {
vec2 sampleCoord = v_texCoord0 + vec2(stepwidth) * vec2(x,y);
vec4 data = texture( tex0, sampleCoord);
vec2 seedCoord = data.xy;
vec2 seedColor = data.zw;
float dist = length(seedCoord - v_texCoord0);
if ((seedCoord.x >= 0.0 || seedCoord.y >= 0.0) && dist < bestDistance)
{
found = 1.0;
bestDistance = dist;
bestCoord = seedCoord;
bestColor = seedColor;
}
}
}
o_color = vec4(bestCoord, found, 1.0);
#version 330 core
in vec2 v_texCoord0;
uniform sampler2D tex0;
uniform int maxSteps;
uniform int step;
out vec4 o_color;
void main() {
float stepwidth = 1.0 / pow(2.0, step+1);
float bestDistance = 9999.0;
vec2 bestCoord = vec2(-1.0);
vec2 bestColor = vec2(-1.0);
vec2 is = vec2(1.0) / textureSize(tex0, 0);
float found = 0.0;
for (int y = -1; y <= 1; ++y) {
for (int x = -1; x <= 1; ++x) {
vec2 sampleCoord = v_texCoord0 + vec2(stepwidth) * vec2(x,y);
vec4 data = texture( tex0, sampleCoord);
vec2 seedCoord = data.xy;
vec2 seedColor = data.zw;
float dist = length(seedCoord - v_texCoord0);
if ((seedCoord.x >= 0.0 || seedCoord.y >= 0.0) && dist < bestDistance)
{
found = 1.0;
bestDistance = dist;
bestCoord = seedCoord;
bestColor = seedColor;
}
}
}
o_color = vec4(bestCoord, bestColor.r, 1.0);
}

View File

@@ -0,0 +1,12 @@
import org.openrndr.extra.noise.fastFloor
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import kotlin.test.assertEquals
object TestMathUtils : Spek({
describe("Fast floor") {
it("it is corrrect for 0.0") {
assertEquals(0, 0.0.fastFloor())
}
}
})