Bump to OPENRNDR 0.3.44-rc.2
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
@file:ShaderPhrases([])
|
||||
|
||||
import kotlinx.coroutines.yield
|
||||
import org.openrndr.*
|
||||
import org.openrndr.color.ColorRGBa
|
||||
@@ -39,9 +37,7 @@ fun main() = application {
|
||||
}
|
||||
|
||||
program {
|
||||
extend(ScreenRecorder()) {
|
||||
multisample = BufferMultisample.SampleCount(8)
|
||||
}
|
||||
|
||||
if (System.getProperty("takeScreenshot") == "true") {
|
||||
extend(SingleScreenshot()) {
|
||||
this.outputFile = System.getProperty("screenshotPath")
|
||||
@@ -113,6 +109,7 @@ fun main() = application {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
renderer.draw(drawer, scene)
|
||||
drawer.defaults()
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
114
orx-dnk3/src/demo/kotlin/DemoVoxelConeTracing01.kt
Normal file
114
orx-dnk3/src/demo/kotlin/DemoVoxelConeTracing01.kt
Normal file
@@ -0,0 +1,114 @@
|
||||
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.extras.camera.Orbital
|
||||
import org.openrndr.extras.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))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ data class MaterialContext(val pass: RenderPass,
|
||||
val meshCubemaps: Map<Mesh, Cubemap>,
|
||||
val irradianceProbeCount: Int
|
||||
) {
|
||||
|
||||
var irradianceSH: IrradianceSH? = null
|
||||
}
|
||||
|
||||
|
||||
@@ -541,7 +541,7 @@ class PBRMaterial : Material {
|
||||
fragmentTransform = fs
|
||||
|
||||
materialContext.pass.combiners.map {
|
||||
if (rt is ProgramRenderTarget || materialContext.pass === DefaultPass || materialContext.pass === DefaultOpaquePass || materialContext.pass == DefaultTransparentPass || materialContext.pass == IrradianceProbePass) {
|
||||
if (rt is ProgramRenderTarget || materialContext.pass === DefaultPass || materialContext.pass === DefaultOpaquePass || materialContext.pass == DefaultTransparentPass || materialContext.pass == IrradianceProbePass || materialContext.pass.skipTarget ) {
|
||||
this.output(it.targetOutput, ShadeStyleOutput(0))
|
||||
} else {
|
||||
val index = rt.colorAttachmentIndexByName(it.targetOutput)?:error("attachment ${it.targetOutput} not found")
|
||||
|
||||
@@ -6,10 +6,12 @@ import org.openrndr.draw.RenderTarget
|
||||
import org.openrndr.draw.renderTarget
|
||||
|
||||
data class RenderPass(val combiners: List<FacetCombiner>,
|
||||
val renderOpaque: Boolean = true,
|
||||
val renderTransparent: Boolean = false,
|
||||
val depthWrite: Boolean = true,
|
||||
val multisample: BufferMultisample = BufferMultisample.Disabled)
|
||||
val renderOpaque: Boolean = true,
|
||||
val renderTransparent: Boolean = false,
|
||||
val depthWrite: Boolean = true,
|
||||
val multisample: BufferMultisample = BufferMultisample.Disabled,
|
||||
val skipTarget: Boolean = false
|
||||
)
|
||||
|
||||
|
||||
val DefaultPass = RenderPass(listOf(LDRColorFacet()))
|
||||
|
||||
@@ -180,7 +180,7 @@ class SceneRenderer {
|
||||
}
|
||||
|
||||
internal fun drawPass(drawer: Drawer, pass: RenderPass, materialContext: MaterialContext,
|
||||
context: RenderContext
|
||||
context: RenderContext, shadeStyleTransformer: ((ShadeStyle)->Unit)? = null
|
||||
) {
|
||||
|
||||
drawer.depthWrite = pass.depthWrite
|
||||
@@ -204,6 +204,8 @@ class SceneRenderer {
|
||||
val shadeStyle = primitive.material.generateShadeStyle(materialContext, primitiveContext)
|
||||
shadeStyle.parameter("viewMatrixInverse", drawer.view.inversed)
|
||||
primitive.material.applyToShadeStyle(materialContext, shadeStyle)
|
||||
shadeStyleTransformer?.invoke(shadeStyle)
|
||||
|
||||
drawer.shadeStyle = shadeStyle
|
||||
drawer.model = it.node.worldTransform
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ fun Scene.addIrradianceSH(xCount: Int,
|
||||
}
|
||||
}
|
||||
|
||||
fun SceneRenderer.processIrradiance(drawer: Drawer, scene: Scene, feature: IrradianceSH, context: RenderContext) {
|
||||
private fun SceneRenderer.processIrradiance(drawer: Drawer, scene: Scene, feature: IrradianceSH, context: RenderContext) {
|
||||
val irradianceProbes = scene.root.findContent { this as? IrradianceProbe }
|
||||
val irradianceProbePositions = irradianceProbes.map { it.node.worldPosition }
|
||||
|
||||
|
||||
71
orx-dnk3/src/main/kotlin/features/VoxelConeTracing.kt
Normal file
71
orx-dnk3/src/main/kotlin/features/VoxelConeTracing.kt
Normal file
@@ -0,0 +1,71 @@
|
||||
package org.openrndr.extra.dnk3.features
|
||||
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.*
|
||||
import org.openrndr.extra.dnk3.*
|
||||
import org.openrndr.math.Matrix44
|
||||
import org.openrndr.math.Vector3
|
||||
|
||||
data class VoxelConeTracing(val xCount: Int, val yCount: Int, val zCount: Int, val spacing: Double, val offset: Vector3) : Feature {
|
||||
var voxelMap: VolumeTexture? = null
|
||||
var voxelRenderTarget = null as? RenderTarget?
|
||||
override fun <T : Feature> update(drawer: Drawer, sceneRenderer: SceneRenderer, scene: Scene, feature: T, context: RenderContext) {
|
||||
sceneRenderer.processVoxelConeTracing(drawer, scene, this, context)
|
||||
}
|
||||
|
||||
var initialized = false
|
||||
val voxelPass = RenderPass(listOf(VoxelFacet(this)), renderOpaque = true, renderTransparent = false, depthWrite = false, skipTarget = true)
|
||||
}
|
||||
|
||||
fun Scene.addVoxelConeTracing(xCount: Int, yCount: Int, zCount: Int, spacing: Double, offset: Vector3 = Vector3.ZERO) : VoxelConeTracing {
|
||||
val feature = VoxelConeTracing(xCount, yCount, zCount, spacing, offset)
|
||||
features.add(feature)
|
||||
return feature
|
||||
}
|
||||
|
||||
class VoxelFacet(val voxelConeTracing: VoxelConeTracing) : ColorBufferFacetCombiner(setOf(FacetType.DIFFUSE, FacetType.SPECULAR, FacetType.EMISSIVE), "color", ColorFormat.RGBa, ColorType.FLOAT16) {
|
||||
override fun generateShader() = """
|
||||
vec3 finalColor = (max(vec3(0.0), f_diffuse.rgb) + max(vec3(0.0), f_emission.rgb) + max(vec3(0.0), f_ambient.rgb));
|
||||
vec3 p = v_worldPosition;
|
||||
{
|
||||
float x = (p.x - ${voxelConeTracing.offset.x}) / ${voxelConeTracing.spacing};
|
||||
float y = (p.y - ${voxelConeTracing.offset.y}) / ${voxelConeTracing.spacing};
|
||||
float z = (p.z - ${voxelConeTracing.offset.z}) / ${voxelConeTracing.spacing};
|
||||
|
||||
int ix = int(floor(x+0.5)) + ${voxelConeTracing.xCount} / 2;
|
||||
int iy = int(floor(y+0.5)) + ${voxelConeTracing.yCount} / 2;
|
||||
int iz = int(floor(z+0.5)) + ${voxelConeTracing.zCount} / 2;
|
||||
imageStore(p_voxelMap, ivec3(ix, iy, iz), vec4(finalColor, 1.0));
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
private fun SceneRenderer.processVoxelConeTracing(drawer: Drawer, scene: Scene, feature: VoxelConeTracing, context: RenderContext) {
|
||||
if (feature.voxelMap == null) {
|
||||
feature.voxelMap = volumeTexture(feature.xCount * 2 + 1, feature.yCount * 2 + 1, feature.zCount * 2 + 1, format = ColorFormat.RGBa, type = ColorType.FLOAT16)
|
||||
}
|
||||
if (feature.voxelRenderTarget == null) {
|
||||
feature.voxelRenderTarget = renderTarget(2048, 2048, 1.0, BufferMultisample.SampleCount(8)) {
|
||||
colorBuffer()
|
||||
}
|
||||
}
|
||||
if (!feature.initialized) {
|
||||
println("drawing voxelmap")
|
||||
for (side in CubemapSide.values()) {
|
||||
drawer.isolatedWithTarget(feature.voxelRenderTarget ?: error("no render target")) {
|
||||
val pass = feature.voxelPass
|
||||
val materialContext = MaterialContext(pass, context.lights, emptyList(), shadowLightTargets, emptyMap(), 0)
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
drawer.ortho(-10.0, 10.0, -10.0, 10.0, -40.0, 40.0)
|
||||
drawer.view = Matrix44.IDENTITY
|
||||
drawer.model = Matrix44.IDENTITY
|
||||
val position = Vector3.ZERO
|
||||
drawer.lookAt(position + side.forward*40.0, position , side.up)
|
||||
drawPass(drawer, pass, materialContext, context) {
|
||||
it.parameter("voxelMap", feature.voxelMap!!.imageBinding(0, ImageAccess.WRITE))
|
||||
}
|
||||
}
|
||||
}
|
||||
feature.initialized = true
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ fun preprocessedFilterShaderFromUrl(url: String): Shader {
|
||||
}
|
||||
|
||||
fun preprocessedFilterShaderFromCode(fragmentShaderCode: String, name: String): Shader {
|
||||
return Shader.createFromCode(Filter.filterVertexCode, fragmentShaderCode, name)
|
||||
return Shader.createFromCode(vsCode = Filter.filterVertexCode, fsCode = fragmentShaderCode, name = name)
|
||||
}
|
||||
|
||||
class VolumetricIrradiance : Filter(preprocessedFilterShaderFromUrl(resourceUrl("/shaders/volumetric-irradiance.frag"))) {
|
||||
|
||||
Reference in New Issue
Block a user