Bump to OPENRNDR 0.3.44-rc.2
This commit is contained in:
@@ -14,9 +14,9 @@ buildscript {
|
|||||||
apply plugin: 'org.jetbrains.dokka'
|
apply plugin: 'org.jetbrains.dokka'
|
||||||
|
|
||||||
project.ext {
|
project.ext {
|
||||||
openrndrVersion = "0.3.44-rc.1"
|
openrndrVersion = "0.3.44-rc.2"
|
||||||
kotlinVersion = "1.3.72"
|
kotlinVersion = "1.3.72"
|
||||||
spekVersion = "2.0.10"
|
spekVersion = "2.0.11"
|
||||||
libfreenectVersion = "0.5.7-1.5.3"
|
libfreenectVersion = "0.5.7-1.5.3"
|
||||||
gsonVersion = "2.8.6"
|
gsonVersion = "2.8.6"
|
||||||
antlrVersion = "4.8-1"
|
antlrVersion = "4.8-1"
|
||||||
|
|||||||
18
openrndr-demos/src/demo/kotlin/DemoCircleBatch01.kt
Normal file
18
openrndr-demos/src/demo/kotlin/DemoCircleBatch01.kt
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
|
||||||
|
/*
|
||||||
|
This demo just verifies that drawing a single circle still works with revamped circle drawing code
|
||||||
|
*/
|
||||||
|
fun main() = application {
|
||||||
|
program {
|
||||||
|
extend {
|
||||||
|
drawer.clear(ColorRGBa.GRAY)
|
||||||
|
drawer.fill = ColorRGBa.PINK
|
||||||
|
drawer.stroke = ColorRGBa.WHITE
|
||||||
|
drawer.strokeWeight = 2.0
|
||||||
|
drawer.circle(100.0, 100.0, 50.0)
|
||||||
|
drawer.rectangle(100.0, 100.0, 50.0, 50.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
28
openrndr-demos/src/demo/kotlin/DemoCircleBatch02.kt
Normal file
28
openrndr-demos/src/demo/kotlin/DemoCircleBatch02.kt
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.draw.circleBatch
|
||||||
|
|
||||||
|
/*
|
||||||
|
This program demonstrates creating "pre-baked" batches of circles. Batches can have varying fill, stroke and
|
||||||
|
strokeWeight settings.
|
||||||
|
|
||||||
|
Batches are (currently) static but stored in GPU memory. Batches are fast to draw.
|
||||||
|
*/
|
||||||
|
|
||||||
|
fun main() = application {
|
||||||
|
program {
|
||||||
|
|
||||||
|
val batch = drawer.circleBatch {
|
||||||
|
this.fill = ColorRGBa.PINK
|
||||||
|
for (i in 0 until 100) {
|
||||||
|
this.strokeWeight = Math.random() * 5.0
|
||||||
|
this.circle(Math.random() * width, Math.random() * height, 50.0 * Math.random() + 50.0 )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extend {
|
||||||
|
drawer.clear(ColorRGBa.GRAY)
|
||||||
|
drawer.circles(batch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
openrndr-demos/src/demo/kotlin/DemoColorBufferCopy01.kt
Normal file
15
openrndr-demos/src/demo/kotlin/DemoColorBufferCopy01.kt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.draw.*
|
||||||
|
import org.openrndr.extras.camera.Orbital
|
||||||
|
import org.openrndr.extras.meshgenerators.boxMesh
|
||||||
|
|
||||||
|
fun main() = application {
|
||||||
|
program {
|
||||||
|
val cb0 = loadImage("demo-data/images/image-001.png")
|
||||||
|
val cb1 = cb0.createEquivalent()
|
||||||
|
extend {
|
||||||
|
cb0.copyTo(cb1)
|
||||||
|
drawer.image(cb1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
37
openrndr-demos/src/demo/kotlin/DemoGeometryShader01.kt
Normal file
37
openrndr-demos/src/demo/kotlin/DemoGeometryShader01.kt
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.draw.DrawPrimitive
|
||||||
|
import org.openrndr.draw.Shader
|
||||||
|
import org.openrndr.draw.shadeStyle
|
||||||
|
import org.openrndr.extras.camera.Orbital
|
||||||
|
import org.openrndr.extras.meshgenerators.boxMesh
|
||||||
|
import org.openrndr.resourceUrl
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
application {
|
||||||
|
program {
|
||||||
|
val vb = boxMesh()
|
||||||
|
val shader = Shader.Companion.createFromUrls(
|
||||||
|
vsUrl = resourceUrl("/shaders/gs-01.vert"),
|
||||||
|
gsUrl = resourceUrl("/shaders/gs-01.geom"),
|
||||||
|
fsUrl = resourceUrl("/shaders/gs-01.frag")
|
||||||
|
)
|
||||||
|
extend(Orbital())
|
||||||
|
extend {
|
||||||
|
drawer.clear(ColorRGBa.PINK)
|
||||||
|
shader.begin()
|
||||||
|
shader.uniform("offset", mouse.position.xy0)
|
||||||
|
shader.uniform("view", drawer.view)
|
||||||
|
shader.uniform("proj", drawer.projection)
|
||||||
|
shader.uniform("model", drawer.model)
|
||||||
|
driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.TRIANGLES, 0, vb.vertexCount)
|
||||||
|
shader.end()
|
||||||
|
|
||||||
|
drawer.shadeStyle = shadeStyle {
|
||||||
|
vertexPreamble = "krak"
|
||||||
|
}
|
||||||
|
//drawer.vertexBuffer(vb, DrawPrimitive.TRIANGLES, 0, vb.vertexCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
openrndr-demos/src/demo/kotlin/DemoImageLoadStore01.kt
Normal file
51
openrndr-demos/src/demo/kotlin/DemoImageLoadStore01.kt
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.draw.*
|
||||||
|
import org.openrndr.extras.meshgenerators.planeMesh
|
||||||
|
import org.openrndr.internal.Driver
|
||||||
|
import org.openrndr.math.Vector3
|
||||||
|
|
||||||
|
|
||||||
|
fun main() = application {
|
||||||
|
program {
|
||||||
|
|
||||||
|
val shader = Shader.createFromCode(vsCode =
|
||||||
|
"""
|
||||||
|
#version 430
|
||||||
|
in vec3 a_position;
|
||||||
|
in vec2 a_texCoord0;
|
||||||
|
in vec3 a_normal;
|
||||||
|
uniform mat4 projMatrix;
|
||||||
|
uniform mat4 viewMatrix;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = projMatrix * vec4(a_position, 1.0);
|
||||||
|
}
|
||||||
|
""",
|
||||||
|
fsCode = """
|
||||||
|
#version 430
|
||||||
|
out vec4 o_color;
|
||||||
|
layout(rgba8) uniform image2D bla;
|
||||||
|
void main() {
|
||||||
|
imageStore(bla, ivec2(30,30), vec4(1.0, 0.0, 0.0, 1.0));
|
||||||
|
o_color = vec4(1.0);
|
||||||
|
}
|
||||||
|
""", name = "ils")
|
||||||
|
val cb = colorBuffer(128, 128)
|
||||||
|
val mesh = planeMesh(Vector3.ZERO, Vector3.UNIT_X, Vector3.UNIT_Y, -Vector3.UNIT_Z, 100.0, 100.0)
|
||||||
|
|
||||||
|
extend {
|
||||||
|
drawer.clear(ColorRGBa.PINK)
|
||||||
|
shader.begin()
|
||||||
|
shader.image("bla", 0, cb.imageBinding(0, ImageAccess.READ_WRITE))
|
||||||
|
shader.uniform("viewMatrix", drawer.view)
|
||||||
|
shader.uniform("projMatrix", drawer.projection)
|
||||||
|
|
||||||
|
Driver.instance.drawVertexBuffer(shader, listOf(mesh), DrawPrimitive.TRIANGLES, 0, mesh.vertexCount)
|
||||||
|
shader.end()
|
||||||
|
drawer.clear(ColorRGBa.BLACK)
|
||||||
|
drawer.image(cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
26
openrndr-demos/src/demo/kotlin/DemoImageLoadStore02.kt
Normal file
26
openrndr-demos/src/demo/kotlin/DemoImageLoadStore02.kt
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.draw.*
|
||||||
|
import org.openrndr.extras.meshgenerators.planeMesh
|
||||||
|
import org.openrndr.internal.Driver
|
||||||
|
import org.openrndr.math.Vector3
|
||||||
|
|
||||||
|
|
||||||
|
fun main() = application {
|
||||||
|
program {
|
||||||
|
val cb = colorBuffer(128, 128)
|
||||||
|
extend {
|
||||||
|
val ss = shadeStyle {
|
||||||
|
fragmentTransform = """
|
||||||
|
imageStore(p_image, ivec2(30.0, 30.0), vec4(1.0, 0.0, 0.0, 1.0));
|
||||||
|
""".trimIndent()
|
||||||
|
|
||||||
|
parameter("image", cb.imageBinding(0, ImageAccess.READ_WRITE))
|
||||||
|
}
|
||||||
|
drawer.shadeStyle = ss
|
||||||
|
drawer.clear(ColorRGBa.PINK)
|
||||||
|
drawer.rectangle(0.0, 0.0, 100.0, 100.0)
|
||||||
|
drawer.image(cb, 0.0, 200.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
29
openrndr-demos/src/demo/kotlin/DemoImageLoadStore03.kt
Normal file
29
openrndr-demos/src/demo/kotlin/DemoImageLoadStore03.kt
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.draw.*
|
||||||
|
|
||||||
|
|
||||||
|
fun main() = application {
|
||||||
|
program {
|
||||||
|
val cb = colorBuffer(128, 128)
|
||||||
|
val at = arrayTexture(128, 128, 32)
|
||||||
|
val vt = volumeTexture(32, 32, 32)
|
||||||
|
extend {
|
||||||
|
val ss = shadeStyle {
|
||||||
|
fragmentTransform = """
|
||||||
|
imageStore(p_image, ivec2(30.0, 30.0), vec4(1.0, 0.0, 0.0, 1.0));
|
||||||
|
imageStore(p_vt, ivec3(2, 2, 2), vec4(1.0, 0.0, 0.0, 1.0));
|
||||||
|
imageStore(p_at, ivec3(2, 2, 2), vec4(1.0, 0.0, 0.0, 1.0));
|
||||||
|
""".trimIndent()
|
||||||
|
|
||||||
|
parameter("at", at.imageBinding(0, ImageAccess.READ_WRITE))
|
||||||
|
parameter("image", cb.imageBinding(0, ImageAccess.READ_WRITE))
|
||||||
|
parameter("vt", vt.imageBinding(0, ImageAccess.READ_WRITE))
|
||||||
|
}
|
||||||
|
drawer.shadeStyle = ss
|
||||||
|
drawer.clear(ColorRGBa.PINK)
|
||||||
|
drawer.rectangle(0.0, 0.0, 100.0, 100.0)
|
||||||
|
drawer.image(cb, 0.0, 200.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
33
openrndr-demos/src/demo/kotlin/DemoLineDash01.kt
Normal file
33
openrndr-demos/src/demo/kotlin/DemoLineDash01.kt
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.draw.shadeStyle
|
||||||
|
import org.openrndr.extensions.Screenshots
|
||||||
|
import org.openrndr.math.Polar
|
||||||
|
import org.openrndr.shape.contour
|
||||||
|
fun main() = application {
|
||||||
|
program {
|
||||||
|
val style = shadeStyle {
|
||||||
|
//fragmentTransform = "x_stroke.a *= step(0.5, fract(c_contourPosition / p_dashLen));"
|
||||||
|
fragmentTransform = "x_stroke.a *= smoothstep(0.0, 1.0, mod(c_contourPosition, p_dashLen)) * smoothstep(p_dashLen, p_dashLen-1.0, mod(c_contourPosition, p_dashLen));"
|
||||||
|
parameter("dashLen", 20.0)
|
||||||
|
}
|
||||||
|
extend {
|
||||||
|
drawer.run {
|
||||||
|
clear(ColorRGBa.WHITE)
|
||||||
|
stroke = ColorRGBa.BLACK.opacify(0.5)
|
||||||
|
val c = contour {
|
||||||
|
moveTo(100.0, 100.0)
|
||||||
|
continueTo(100.0, 300.0)
|
||||||
|
continueTo(bounds.center + Polar(seconds * 30, 100.0).cartesian)
|
||||||
|
continueTo(500.0, 100.0)
|
||||||
|
continueTo(600.0, 100.0)
|
||||||
|
}
|
||||||
|
shadeStyle = style
|
||||||
|
contour(c)
|
||||||
|
|
||||||
|
drawer.lineSegment(0.0, 0.0, width*1.0, height*1.0)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
53
openrndr-demos/src/demo/kotlin/DemoTessShader01.kt
Normal file
53
openrndr-demos/src/demo/kotlin/DemoTessShader01.kt
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.draw.*
|
||||||
|
import org.openrndr.extras.camera.Orbital
|
||||||
|
import org.openrndr.extras.meshgenerators.boxMesh
|
||||||
|
import org.openrndr.math.Vector3
|
||||||
|
import org.openrndr.resourceUrl
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
application {
|
||||||
|
program {
|
||||||
|
val vb = vertexBuffer(vertexFormat {
|
||||||
|
position(3)
|
||||||
|
}, 12)
|
||||||
|
val shader = Shader.Companion.createFromUrls(
|
||||||
|
vsUrl = resourceUrl("/shaders/ts-01.vert"),
|
||||||
|
tcsUrl = resourceUrl("/shaders/ts-01.tesc"),
|
||||||
|
tesUrl = resourceUrl("/shaders/ts-01.tese"),
|
||||||
|
fsUrl = resourceUrl("/shaders/ts-01.frag")
|
||||||
|
)
|
||||||
|
|
||||||
|
vb.put {
|
||||||
|
write(Vector3(0.0, 0.0, 0.0))
|
||||||
|
write(Vector3(100.0, 0.0, 0.0))
|
||||||
|
write(Vector3(140.0, 200.0, 0.0))
|
||||||
|
write(Vector3(200.0, 300.0, 0.0))
|
||||||
|
write(Vector3(0.0, 0.0, 0.0))
|
||||||
|
write(Vector3(100.0, 0.0, 0.0))
|
||||||
|
write(Vector3(140.0, 200.0, 0.0))
|
||||||
|
write(Vector3(200.0, 400.0, 0.0))
|
||||||
|
write(Vector3(0.0, 0.0, 0.0))
|
||||||
|
write(Vector3(100.0, 0.0, 0.0))
|
||||||
|
write(Vector3(140.0, 200.0, 0.0))
|
||||||
|
write(Vector3(200.0, 500.0, 0.0))
|
||||||
|
}
|
||||||
|
|
||||||
|
extend {
|
||||||
|
drawer.clear(ColorRGBa.PINK)
|
||||||
|
shader.begin()
|
||||||
|
shader.uniform("offset", mouse.position.xy0)
|
||||||
|
shader.uniform("view", drawer.view)
|
||||||
|
shader.uniform("proj", drawer.projection)
|
||||||
|
shader.uniform("model", drawer.model)
|
||||||
|
driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.PATCHES, 0, vb.vertexCount)
|
||||||
|
|
||||||
|
|
||||||
|
shader.end()
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
openrndr-demos/src/demo/kotlin/DemoTessShader02.kt
Normal file
51
openrndr-demos/src/demo/kotlin/DemoTessShader02.kt
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.draw.*
|
||||||
|
import org.openrndr.extras.camera.Orbital
|
||||||
|
import org.openrndr.extras.meshgenerators.boxMesh
|
||||||
|
import org.openrndr.math.Vector3
|
||||||
|
import org.openrndr.resourceUrl
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
application {
|
||||||
|
program {
|
||||||
|
val vb = vertexBuffer(vertexFormat {
|
||||||
|
position(3)
|
||||||
|
}, 12)
|
||||||
|
|
||||||
|
val shader = Shader.createFromUrls(
|
||||||
|
vsUrl = resourceUrl("/shaders/ts-02.vert"),
|
||||||
|
tcsUrl = resourceUrl("/shaders/ts-02.tesc"),
|
||||||
|
tesUrl = resourceUrl("/shaders/ts-02.tese"),
|
||||||
|
gsUrl = resourceUrl("/shaders/ts-02.geom"),
|
||||||
|
fsUrl = resourceUrl("/shaders/ts-02.frag")
|
||||||
|
)
|
||||||
|
|
||||||
|
vb.put {
|
||||||
|
write(Vector3(0.0, 0.0, 0.0))
|
||||||
|
write(Vector3(100.0, 0.0, 0.0))
|
||||||
|
write(Vector3(140.0, 200.0, 0.0))
|
||||||
|
write(Vector3(200.0, 300.0, 0.0))
|
||||||
|
write(Vector3(0.0, 0.0, 0.0))
|
||||||
|
write(Vector3(100.0, 0.0, 0.0))
|
||||||
|
write(Vector3(140.0, 200.0, 0.0))
|
||||||
|
write(Vector3(200.0, 400.0, 0.0))
|
||||||
|
write(Vector3(0.0, 0.0, 0.0))
|
||||||
|
write(Vector3(100.0, 0.0, 0.0))
|
||||||
|
write(Vector3(140.0, 200.0, 0.0))
|
||||||
|
write(Vector3(200.0, 500.0, 0.0))
|
||||||
|
}
|
||||||
|
|
||||||
|
extend {
|
||||||
|
drawer.clear(ColorRGBa.PINK)
|
||||||
|
shader.begin()
|
||||||
|
shader.uniform("offset", mouse.position.xy0)
|
||||||
|
shader.uniform("view", drawer.view)
|
||||||
|
shader.uniform("proj", drawer.projection)
|
||||||
|
shader.uniform("model", drawer.model)
|
||||||
|
driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.PATCHES, 0, vb.vertexCount)
|
||||||
|
shader.end()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
33
openrndr-demos/src/demo/kotlin/DemoVolumeTexture01.kt
Normal file
33
openrndr-demos/src/demo/kotlin/DemoVolumeTexture01.kt
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.draw.*
|
||||||
|
import org.openrndr.extensions.Screenshots
|
||||||
|
|
||||||
|
|
||||||
|
fun main() = application {
|
||||||
|
program {
|
||||||
|
|
||||||
|
val screenshots = extend(Screenshots()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
val volumeTexture = VolumeTexture.create(128,128,32)
|
||||||
|
val rt = renderTarget(128, 128) {
|
||||||
|
volumeTexture(volumeTexture, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
val cb = colorBuffer(128, 128)
|
||||||
|
extend {
|
||||||
|
|
||||||
|
screenshots.afterScreenshot
|
||||||
|
|
||||||
|
drawer.isolatedWithTarget(rt) {
|
||||||
|
drawer.ortho(rt)
|
||||||
|
drawer.clear(ColorRGBa.PINK)
|
||||||
|
}
|
||||||
|
volumeTexture.copyTo(cb, 0)
|
||||||
|
drawer.image(cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
11
openrndr-demos/src/demo/resources/shaders/gs-01.frag
Normal file
11
openrndr-demos/src/demo/resources/shaders/gs-01.frag
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#version 430 core
|
||||||
|
|
||||||
|
out vec4 o_color;
|
||||||
|
|
||||||
|
in vec3 va_position;
|
||||||
|
in vec3 va_normal;
|
||||||
|
in vec4 v_addedProperty;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
o_color = v_addedProperty;
|
||||||
|
}
|
||||||
29
openrndr-demos/src/demo/resources/shaders/gs-01.geom
Normal file
29
openrndr-demos/src/demo/resources/shaders/gs-01.geom
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#version 430 core
|
||||||
|
|
||||||
|
layout (triangles) in;
|
||||||
|
layout (triangle_strip, max_vertices = 3) out;
|
||||||
|
|
||||||
|
in InVertex {
|
||||||
|
vec3 va_position;
|
||||||
|
vec3 va_normal;
|
||||||
|
vec4 v_addedProperty;
|
||||||
|
} vertices[];
|
||||||
|
|
||||||
|
out vec3 va_position;
|
||||||
|
out vec3 va_normal;
|
||||||
|
out vec4 v_addedProperty;
|
||||||
|
|
||||||
|
|
||||||
|
uniform vec3 offset;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
int i;
|
||||||
|
for(i = 0;i < gl_in.length();i++) {
|
||||||
|
v_addedProperty = vertices[i].v_addedProperty;
|
||||||
|
va_normal = vertices[i].va_normal;
|
||||||
|
va_position = vertices[i].va_position;
|
||||||
|
gl_Position = gl_in[i].gl_Position;
|
||||||
|
EmitVertex();
|
||||||
|
}
|
||||||
|
EndPrimitive();
|
||||||
|
}
|
||||||
22
openrndr-demos/src/demo/resources/shaders/gs-01.vert
Normal file
22
openrndr-demos/src/demo/resources/shaders/gs-01.vert
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#version 430 core
|
||||||
|
|
||||||
|
in vec3 a_position;
|
||||||
|
in vec3 a_normal;
|
||||||
|
in vec2 a_texCoord0;
|
||||||
|
|
||||||
|
out InVertex {
|
||||||
|
vec3 va_position;
|
||||||
|
vec3 va_normal;
|
||||||
|
vec4 v_addedProperty;
|
||||||
|
} vertexOut;
|
||||||
|
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 proj;
|
||||||
|
uniform mat4 model;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vertexOut.v_addedProperty = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
vertexOut.va_position = a_position;
|
||||||
|
vertexOut.va_normal = a_normal;
|
||||||
|
gl_Position = proj * view * model * vec4(a_position, 1.0);
|
||||||
|
}
|
||||||
13
openrndr-demos/src/demo/resources/shaders/ts-01.frag
Normal file
13
openrndr-demos/src/demo/resources/shaders/ts-01.frag
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#version 430 core
|
||||||
|
|
||||||
|
out vec4 o_color;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//in vec3 va_position;
|
||||||
|
//in vec3 va_normal;
|
||||||
|
//in vec4 v_addedProperty;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
o_color = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
}
|
||||||
16
openrndr-demos/src/demo/resources/shaders/ts-01.tesc
Normal file
16
openrndr-demos/src/demo/resources/shaders/ts-01.tesc
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#version 430 core
|
||||||
|
|
||||||
|
layout(vertices = 4) out; // 4 points per patch
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
in vec3 va_position[];
|
||||||
|
out vec3 cva_position[];
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
cva_position[gl_InvocationID] = va_position[gl_InvocationID];
|
||||||
|
if(gl_InvocationID == 0) { // levels only need to be set once per patch
|
||||||
|
gl_TessLevelOuter[0] = 1; // we're only tessellating one line
|
||||||
|
gl_TessLevelOuter[1] = 4; // tessellate the line into 100 segments
|
||||||
|
}
|
||||||
|
}
|
||||||
41
openrndr-demos/src/demo/resources/shaders/ts-01.tese
Normal file
41
openrndr-demos/src/demo/resources/shaders/ts-01.tese
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
|
||||||
|
#version 430 core
|
||||||
|
|
||||||
|
vec3 bezier2(vec3 a, vec3 b, float t) {
|
||||||
|
return mix(a, b, t);
|
||||||
|
}
|
||||||
|
vec3 bezier3(vec3 a, vec3 b, vec3 c, float t) {
|
||||||
|
return mix(bezier2(a, b, t), bezier2(b, c, t), t);
|
||||||
|
}
|
||||||
|
vec3 bezier4(vec3 a, vec3 b, vec3 c, vec3 d, float t) {
|
||||||
|
return mix(bezier3(a, b, c, t), bezier3(b, c, d, t), t);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Vertex {
|
||||||
|
vec3 va_position;
|
||||||
|
vec3 va_normal;
|
||||||
|
vec4 v_addedProperty;
|
||||||
|
};
|
||||||
|
|
||||||
|
layout(isolines) in;
|
||||||
|
in vec3 cva_position[];
|
||||||
|
|
||||||
|
|
||||||
|
uniform mat4 proj;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 model;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
float t = gl_TessCoord.x;
|
||||||
|
vec3 ePos = bezier4(
|
||||||
|
cva_position[0],
|
||||||
|
cva_position[1],
|
||||||
|
cva_position[2],
|
||||||
|
cva_position[3],
|
||||||
|
|
||||||
|
|
||||||
|
t);
|
||||||
|
|
||||||
|
|
||||||
|
gl_Position = proj * view * model * vec4(ePos, 1);
|
||||||
|
}
|
||||||
15
openrndr-demos/src/demo/resources/shaders/ts-01.vert
Normal file
15
openrndr-demos/src/demo/resources/shaders/ts-01.vert
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#version 430 core
|
||||||
|
|
||||||
|
in vec3 a_position;
|
||||||
|
|
||||||
|
|
||||||
|
out vec3 va_position;
|
||||||
|
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 proj;
|
||||||
|
uniform mat4 model;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
va_position = a_position;
|
||||||
|
gl_Position = proj * view * model * vec4(a_position, 1.0);
|
||||||
|
}
|
||||||
13
openrndr-demos/src/demo/resources/shaders/ts-02.frag
Normal file
13
openrndr-demos/src/demo/resources/shaders/ts-02.frag
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#version 430 core
|
||||||
|
|
||||||
|
out vec4 o_color;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//in vec3 va_position;
|
||||||
|
//in vec3 va_normal;
|
||||||
|
//in vec4 v_addedProperty;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
o_color = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
}
|
||||||
29
openrndr-demos/src/demo/resources/shaders/ts-02.geom
Normal file
29
openrndr-demos/src/demo/resources/shaders/ts-02.geom
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#version 430 core
|
||||||
|
|
||||||
|
layout (lines) in;
|
||||||
|
layout (line_strip, max_vertices = 2) out;
|
||||||
|
|
||||||
|
in InVertex {
|
||||||
|
vec3 va_position;
|
||||||
|
vec3 va_normal;
|
||||||
|
vec4 v_addedProperty;
|
||||||
|
} vertices[];
|
||||||
|
|
||||||
|
out vec3 va_position;
|
||||||
|
out vec3 va_normal;
|
||||||
|
out vec4 v_addedProperty;
|
||||||
|
|
||||||
|
|
||||||
|
uniform vec3 offset;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
int i;
|
||||||
|
for(i = 0;i < gl_in.length();i++) {
|
||||||
|
v_addedProperty = vertices[i].v_addedProperty;
|
||||||
|
va_normal = vertices[i].va_normal;
|
||||||
|
va_position = vertices[i].va_position;
|
||||||
|
gl_Position = gl_in[i].gl_Position;
|
||||||
|
EmitVertex();
|
||||||
|
}
|
||||||
|
EndPrimitive();
|
||||||
|
}
|
||||||
16
openrndr-demos/src/demo/resources/shaders/ts-02.tesc
Normal file
16
openrndr-demos/src/demo/resources/shaders/ts-02.tesc
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#version 430 core
|
||||||
|
|
||||||
|
layout(vertices = 4) out; // 4 points per patch
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
in vec3 va_position[];
|
||||||
|
out vec3 cva_position[];
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
cva_position[gl_InvocationID] = va_position[gl_InvocationID];
|
||||||
|
if(gl_InvocationID == 0) { // levels only need to be set once per patch
|
||||||
|
gl_TessLevelOuter[0] = 1; // we're only tessellating one line
|
||||||
|
gl_TessLevelOuter[1] = 4; // tessellate the line into 100 segments
|
||||||
|
}
|
||||||
|
}
|
||||||
41
openrndr-demos/src/demo/resources/shaders/ts-02.tese
Normal file
41
openrndr-demos/src/demo/resources/shaders/ts-02.tese
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
|
||||||
|
#version 430 core
|
||||||
|
|
||||||
|
vec3 bezier2(vec3 a, vec3 b, float t) {
|
||||||
|
return mix(a, b, t);
|
||||||
|
}
|
||||||
|
vec3 bezier3(vec3 a, vec3 b, vec3 c, float t) {
|
||||||
|
return mix(bezier2(a, b, t), bezier2(b, c, t), t);
|
||||||
|
}
|
||||||
|
vec3 bezier4(vec3 a, vec3 b, vec3 c, vec3 d, float t) {
|
||||||
|
return mix(bezier3(a, b, c, t), bezier3(b, c, d, t), t);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Vertex {
|
||||||
|
vec3 va_position;
|
||||||
|
vec3 va_normal;
|
||||||
|
vec4 v_addedProperty;
|
||||||
|
};
|
||||||
|
|
||||||
|
layout(isolines) in;
|
||||||
|
in vec3 cva_position[];
|
||||||
|
|
||||||
|
|
||||||
|
uniform mat4 proj;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 model;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
float t = gl_TessCoord.x;
|
||||||
|
vec3 ePos = bezier4(
|
||||||
|
cva_position[0],
|
||||||
|
cva_position[1],
|
||||||
|
cva_position[2],
|
||||||
|
cva_position[3],
|
||||||
|
|
||||||
|
|
||||||
|
t);
|
||||||
|
|
||||||
|
|
||||||
|
gl_Position = proj * view * model * vec4(ePos, 1);
|
||||||
|
}
|
||||||
15
openrndr-demos/src/demo/resources/shaders/ts-02.vert
Normal file
15
openrndr-demos/src/demo/resources/shaders/ts-02.vert
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#version 430 core
|
||||||
|
|
||||||
|
in vec3 a_position;
|
||||||
|
|
||||||
|
|
||||||
|
out vec3 va_position;
|
||||||
|
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 proj;
|
||||||
|
uniform mat4 model;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
va_position = a_position;
|
||||||
|
gl_Position = proj * view * model * vec4(a_position, 1.0);
|
||||||
|
}
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
@file:ShaderPhrases([])
|
|
||||||
|
|
||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
import org.openrndr.*
|
import org.openrndr.*
|
||||||
import org.openrndr.color.ColorRGBa
|
import org.openrndr.color.ColorRGBa
|
||||||
@@ -39,9 +37,7 @@ fun main() = application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
program {
|
program {
|
||||||
extend(ScreenRecorder()) {
|
|
||||||
multisample = BufferMultisample.SampleCount(8)
|
|
||||||
}
|
|
||||||
if (System.getProperty("takeScreenshot") == "true") {
|
if (System.getProperty("takeScreenshot") == "true") {
|
||||||
extend(SingleScreenshot()) {
|
extend(SingleScreenshot()) {
|
||||||
this.outputFile = System.getProperty("screenshotPath")
|
this.outputFile = System.getProperty("screenshotPath")
|
||||||
@@ -113,6 +109,7 @@ fun main() = application {
|
|||||||
drawer.clear(ColorRGBa.BLACK)
|
drawer.clear(ColorRGBa.BLACK)
|
||||||
renderer.draw(drawer, scene)
|
renderer.draw(drawer, scene)
|
||||||
drawer.defaults()
|
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 meshCubemaps: Map<Mesh, Cubemap>,
|
||||||
val irradianceProbeCount: Int
|
val irradianceProbeCount: Int
|
||||||
) {
|
) {
|
||||||
|
|
||||||
var irradianceSH: IrradianceSH? = null
|
var irradianceSH: IrradianceSH? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -541,7 +541,7 @@ class PBRMaterial : Material {
|
|||||||
fragmentTransform = fs
|
fragmentTransform = fs
|
||||||
|
|
||||||
materialContext.pass.combiners.map {
|
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))
|
this.output(it.targetOutput, ShadeStyleOutput(0))
|
||||||
} else {
|
} else {
|
||||||
val index = rt.colorAttachmentIndexByName(it.targetOutput)?:error("attachment ${it.targetOutput} not found")
|
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
|
import org.openrndr.draw.renderTarget
|
||||||
|
|
||||||
data class RenderPass(val combiners: List<FacetCombiner>,
|
data class RenderPass(val combiners: List<FacetCombiner>,
|
||||||
val renderOpaque: Boolean = true,
|
val renderOpaque: Boolean = true,
|
||||||
val renderTransparent: Boolean = false,
|
val renderTransparent: Boolean = false,
|
||||||
val depthWrite: Boolean = true,
|
val depthWrite: Boolean = true,
|
||||||
val multisample: BufferMultisample = BufferMultisample.Disabled)
|
val multisample: BufferMultisample = BufferMultisample.Disabled,
|
||||||
|
val skipTarget: Boolean = false
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
val DefaultPass = RenderPass(listOf(LDRColorFacet()))
|
val DefaultPass = RenderPass(listOf(LDRColorFacet()))
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ class SceneRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun drawPass(drawer: Drawer, pass: RenderPass, materialContext: MaterialContext,
|
internal fun drawPass(drawer: Drawer, pass: RenderPass, materialContext: MaterialContext,
|
||||||
context: RenderContext
|
context: RenderContext, shadeStyleTransformer: ((ShadeStyle)->Unit)? = null
|
||||||
) {
|
) {
|
||||||
|
|
||||||
drawer.depthWrite = pass.depthWrite
|
drawer.depthWrite = pass.depthWrite
|
||||||
@@ -204,6 +204,8 @@ class SceneRenderer {
|
|||||||
val shadeStyle = primitive.material.generateShadeStyle(materialContext, primitiveContext)
|
val shadeStyle = primitive.material.generateShadeStyle(materialContext, primitiveContext)
|
||||||
shadeStyle.parameter("viewMatrixInverse", drawer.view.inversed)
|
shadeStyle.parameter("viewMatrixInverse", drawer.view.inversed)
|
||||||
primitive.material.applyToShadeStyle(materialContext, shadeStyle)
|
primitive.material.applyToShadeStyle(materialContext, shadeStyle)
|
||||||
|
shadeStyleTransformer?.invoke(shadeStyle)
|
||||||
|
|
||||||
drawer.shadeStyle = shadeStyle
|
drawer.shadeStyle = shadeStyle
|
||||||
drawer.model = it.node.worldTransform
|
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 irradianceProbes = scene.root.findContent { this as? IrradianceProbe }
|
||||||
val irradianceProbePositions = irradianceProbes.map { it.node.worldPosition }
|
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 {
|
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"))) {
|
class VolumetricIrradiance : Filter(preprocessedFilterShaderFromUrl(resourceUrl("/shaders/volumetric-irradiance.frag"))) {
|
||||||
|
|||||||
Reference in New Issue
Block a user