[orx-dnk3] Fix demos

This commit is contained in:
Edwin Jakobs
2023-04-04 23:33:25 +02:00
parent 16455b9069
commit daf9c75bb3
17 changed files with 92 additions and 283 deletions

View File

@@ -13,7 +13,9 @@ dependencies {
implementation(libs.openrndr.math)
implementation(libs.kotlin.coroutines)
demoImplementation(project(":orx-mesh-generators"))
demoImplementation(project(":orx-camera"))
demoImplementation(project(":orx-noise"))
demoImplementation(project(":orx-shader-phrases"))
demoImplementation(libs.openrndr.ffmpeg)
demoImplementation(libs.openrndr.filter)
}

View File

@@ -19,12 +19,6 @@ fun main() = application {
}
program {
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val gltf = loadGltfFromFile(File("demo-data/gltf-models/box-animated/BoxAnimated.glb"))
val scene = Scene(SceneNode())

View File

@@ -12,16 +12,9 @@ fun main() = application {
configure {
width = 1280
height = 720
//multisample = WindowMultisample.SampleCount(8)
}
program {
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val gltf = loadGltfFromFile(File("demo-data/gltf-models/camera/Scene.glb"))
val scene = Scene(SceneNode())

View File

@@ -17,11 +17,6 @@ fun main() = application {
}
program {
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
extend(Orbital()) {
eye = Vector3(4.0, 4.0, 4.0)
}

View File

@@ -1,87 +1,82 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extensions.SingleScreenshot
import org.openrndr.extra.dnk3.dsl.*
import org.openrndr.extra.dnk3.renderers.dryRenderer
import org.openrndr.extra.dnk3.tools.addSkybox
import org.openrndr.extra.noise.simplex
import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.meshgenerators.groundPlaneMesh
import org.openrndr.math.Vector3
import org.openrndr.math.transforms.transform
import org.openrndr.shape.path3D
fun main() = application {
configure {
width = 1280
height = 720
}
program {
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
extend(Orbital()) {
eye = Vector3(4.0, 4.0, 4.0)
}
val renderer = dryRenderer()
val scene = scene {
addSkybox("file:demo-data/cubemaps/garage_iem.dds")
root.hemisphereLight {
upColor = ColorRGBa.WHITE.shade(0.1)
downColor = ColorRGBa.BLACK
}
root.node {
transform = transform {
translate(0.0, 2.0, 0.0)
}
pointLight {
constantAttenuation = 0.0
quadraticAttenuation = 1.0
}
}
root.node {
simpleMesh {
vertexBuffer = groundPlaneMesh(100.0, 100.0)
material = pbrMaterial {
color = ColorRGBa.GREEN
}
}
}
root.node {
pathMesh {
weight = 10.0
material = pbrMaterial {
color = ColorRGBa.PINK
}
update {
paths = mutableListOf(
path3D {
val t = seconds * 0.1
moveTo(Vector3.ZERO)
val control = Vector3.simplex(3032, t).let { it.copy(y = it.y * 0.5 + 0.5) } * 4.0
val target = Vector3.simplex(5077, t).let { it.copy(y = it.y * 0.5 + 0.5) } * 4.0
val end = Vector3.simplex(9041, t).let { it.copy(y = it.y * 0.5 + 0.5) } * 4.0
curveTo(control, target)
continueTo(end)
}
)
}
}
}
}
extend {
drawer.clear(ColorRGBa.BLACK)
renderer.draw(drawer, scene)
}
}
}
//import org.openrndr.application
//import org.openrndr.color.ColorRGBa
//import org.openrndr.extensions.SingleScreenshot
//import org.openrndr.extra.dnk3.dsl.*
//import org.openrndr.extra.dnk3.renderers.dryRenderer
//import org.openrndr.extra.dnk3.tools.addSkybox
//import org.openrndr.extra.noise.simplex
//import org.openrndr.extra.camera.Orbital
//import org.openrndr.extra.meshgenerators.groundPlaneMesh
//import org.openrndr.math.Vector3
//import org.openrndr.math.transforms.transform
//import org.openrndr.shape.path3D
//
//fun main() = application {
// configure {
// width = 1280
// height = 720
// }
//
// program {
// extend(Orbital()) {
// eye = Vector3(4.0, 4.0, 4.0)
// }
//
// val renderer = dryRenderer()
// val scene = scene {
//
// addSkybox("file:demo-data/cubemaps/garage_iem.dds")
//
// root.hemisphereLight {
// upColor = ColorRGBa.WHITE.shade(0.1)
// downColor = ColorRGBa.BLACK
// }
//
// root.node {
// transform = transform {
// translate(0.0, 2.0, 0.0)
// }
//
// pointLight {
// constantAttenuation = 0.0
// quadraticAttenuation = 1.0
// }
// }
//
// root.node {
// simpleMesh {
// vertexBuffer = groundPlaneMesh(100.0, 100.0)
// material = pbrMaterial {
// color = ColorRGBa.GREEN
// }
// }
// }
//
// root.node {
// pathMesh {
// weight = 10.0
// material = pbrMaterial {
// color = ColorRGBa.PINK
// }
// update {
// paths = mutableListOf(
// path3D {
// val t = seconds * 0.1
// moveTo(Vector3.ZERO)
// val control = Vector3.simplex(3032, t).let { it.copy(y = it.y * 0.5 + 0.5) } * 4.0
// val target = Vector3.simplex(5077, t).let { it.copy(y = it.y * 0.5 + 0.5) } * 4.0
// val end = Vector3.simplex(9041, t).let { it.copy(y = it.y * 0.5 + 0.5) } * 4.0
// curveTo(control, target)
// continueTo(end)
// }
// )
// }
// }
// }
// }
// extend {
// drawer.clear(ColorRGBa.BLACK)
// renderer.draw(drawer, scene)
// }
// }
//}

View File

@@ -37,13 +37,6 @@ fun main() = application {
}
program {
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val gltf = loadGltfFromFile(File("demo-data/gltf-models/irradiance-probes/model.glb"))
val scene = Scene(SceneNode())

View File

@@ -17,12 +17,6 @@ fun main() = application {
}
program {
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val gltf = loadGltfFromFile(File("demo-data/gltf-models/point-light/Scene.glb"))
val scene = Scene(SceneNode())

View File

@@ -17,12 +17,6 @@ fun main() = application {
}
program {
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val gltf = loadGltfFromFile(File("demo-data/gltf-models/spot-light/Scene.glb"))
val scene = Scene(SceneNode())

View File

@@ -17,12 +17,6 @@ fun main() = application {
}
program {
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val gltf = loadGltfFromFile(File("demo-data/gltf-models/directional-light/Scene.glb"))
val scene = Scene(SceneNode())

View File

@@ -9,12 +9,6 @@ import java.io.File
fun main() = application {
program {
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val gltf = loadGltfFromFile(File("demo-data/gltf-models/duck/Duck.gltf"))
val meshes = gltf.meshes.map {
it.createDrawCommands(gltf)

View File

@@ -18,12 +18,6 @@ fun main() = application {
}
program {
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val gltf = loadGltfFromFile(File("demo-data/gltf-models/suzanne/Suzanne.gltf"))
val scene = Scene(SceneNode())

View File

@@ -1,6 +1,5 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extensions.SingleScreenshot
import org.openrndr.extra.dnk3.*
import org.openrndr.extra.dnk3.gltf.buildSceneNodes
@@ -18,12 +17,6 @@ fun main() = application {
}
program {
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val gltf = loadGltfFromFile(File("demo-data/gltf-models/duck/Duck.gltf"))
val scene = Scene(SceneNode())
@@ -38,7 +31,7 @@ fun main() = application {
scene.root.entities.add(HemisphereLight().apply {
upColor = ColorRGBa.WHITE.shade(1.0)
downColor = ColorRGBa.WHITE.shade(0.1)
})
})
scene.root.children.add(lightNode)
scene.root.children.addAll(gltf.buildSceneNodes().scenes.first())

View File

@@ -18,11 +18,6 @@ fun main() = application {
}
program {
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val root = SceneNode()
val scene = Scene(root)

View File

@@ -1,3 +1,4 @@
import org.openrndr.WindowMultisample
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.BufferMultisample
@@ -15,15 +16,10 @@ fun main() = application {
configure {
width = 1280
height = 720
//multisample = WindowMultisample.SampleCount(8)
multisample = WindowMultisample.SampleCount(8)
}
program {
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val gltf = loadGltfFromFile(File("demo-data/gltf-models/fox/Fox.glb"))
val scene = Scene(SceneNode())

View File

@@ -10,7 +10,7 @@ import org.openrndr.math.Vector3
import org.openrndr.math.mod_
import java.io.File
suspend fun main() = application {
fun main() = application {
configure {
width = 1280
height = 720
@@ -18,12 +18,6 @@ suspend fun main() = application {
}
program {
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val gltf = loadGltfFromFile(File("demo-data/gltf-models/fox/Fox.glb"))
val scene = Scene(SceneNode())

View File

@@ -1,114 +0,0 @@
import kotlinx.coroutines.yield
import org.openrndr.*
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.*
import org.openrndr.extensions.SingleScreenshot
import org.openrndr.extra.dnk3.*
import org.openrndr.extra.dnk3.features.addVoxelConeTracing
import org.openrndr.extra.dnk3.gltf.buildSceneNodes
import org.openrndr.extra.dnk3.gltf.loadGltfFromFile
import org.openrndr.extra.dnk3.renderers.postRenderer
import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.meshgenerators.sphereMesh
import org.openrndr.filter.color.Delinearize
import org.openrndr.math.Spherical
import org.openrndr.math.Vector3
import org.openrndr.math.transforms.transform
import java.io.File
import kotlin.math.cos
import kotlin.math.sin
fun main() = application {
configure {
width = 1280
height = 720
multisample = WindowMultisample.SampleCount(8)
}
program {
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
val gltf = loadGltfFromFile(File("demo-data/gltf-models/irradiance-probes/model.glb"))
val scene = Scene(SceneNode())
val probeBox = sphereMesh(16, 16, 0.1)
val probeGeometry = Geometry(listOf(probeBox), null, DrawPrimitive.TRIANGLES, 0, probeBox.vertexCount)
val c = 5
// scene.addIrradianceSH(c, c, c, 3.0 / c, cubemapSize = 32, offset = Vector3(0.0, 0.0, 0.0))
val vctFeature = scene.addVoxelConeTracing(64,64,64, 0.1)
val sceneData = gltf.buildSceneNodes()
scene.root.children.addAll(sceneData.scenes.first())
// -- create a renderer
val renderer = postRenderer()
// renderer.postSteps.add(
// FilterPostStep(1.0, ScreenspaceReflections(), listOf("color", "clipDepth", "viewNormal"), "reflections", ColorFormat.RGB, ColorType.FLOAT16) {
// val p = Matrix44.scale(drawer.width / 2.0, drawer.height / 2.0, 1.0) * Matrix44.translate(Vector3(1.0, 1.0, 0.0)) * drawer.projection
// this.projection = p
// this.projectionMatrixInverse = drawer.projection.inversed
// }
// )
// renderer.postSteps.add(
// FilterPostStep(1.0, VolumetricIrradiance(), listOf("color", "clipDepth"), "volumetric-irradiance", ColorFormat.RGB, ColorType.FLOAT16) {
// this.irradianceSH = scene.features[0] as IrradianceSH
// this.projectionMatrixInverse = drawer.projection.inversed
// this.viewMatrixInverse = drawer.view.inversed
// }
// )
renderer.postSteps.add(
FilterPostStep(1.0, Delinearize(), listOf("color"), "ldr", ColorFormat.RGB, ColorType.FLOAT16)
)
val orb = extend(Orbital()) {
this.fov = 20.0
camera.setView(Vector3(-0.49, -0.24, 0.20), Spherical(26.56, 90.0, 6.533), 40.0)
}
renderer.draw(drawer, scene)
val dynNode = SceneNode()
val dynMaterial = PBRMaterial()
val dynPrimitive = MeshPrimitive(probeGeometry, dynMaterial)
val dynMesh = Mesh(listOf(dynPrimitive))
dynNode.entities.add(dynMesh)
scene.root.children.add(dynNode)
scene.dispatcher.launch {
while (true) {
dynNode.transform = transform {
translate(cos(seconds) * 0.5, 0.5, sin(seconds) * 0.5)
scale(2.0)
}
yield()
}
}
val viz = colorBuffer(64,64)
extend {
drawer.clear(ColorRGBa.BLACK)
renderer.draw(drawer, scene)
drawer.defaults()
for (i in 0 until 128) {
vctFeature.voxelMap?.let {
it.copyTo(viz, i)
}
drawer.image(viz, (i * 128) % width + 0.0, ((i * 128)/width * 128 + 0.0 ))
}
drawer.image(vctFeature.voxelRenderTarget!!.colorBuffer(0))
}
}
}

View File

@@ -102,7 +102,10 @@ private fun SceneRenderer.processIrradiance(drawer: Drawer, scene: Scene, featur
feature.shMap?.let {
buffer.rewind()
it.write(buffer)
it.saveToFile(File("data/scene-cache/sh-$hash.orb"))
val f = File("data/scene-cache/sh-$hash.orb")
if (f.canWrite()) {
it.saveToFile(f)
}
}
}
}