[openrndr-demos] Add DemoTessShader04
This commit is contained in:
@@ -8,13 +8,12 @@ sourceSets {
|
||||
}
|
||||
}
|
||||
|
||||
def boofcvVersion = "0.36"
|
||||
|
||||
dependencies {
|
||||
demoImplementation(project(":orx-mesh-generators"))
|
||||
demoImplementation(project(":orx-camera"))
|
||||
demoImplementation(project(":orx-parameters"))
|
||||
|
||||
demoImplementation(project(":orx-noise"))
|
||||
demoImplementation(project(":orx-shader-phrases"))
|
||||
demoImplementation("org.openrndr:openrndr-core:$openrndrVersion")
|
||||
demoImplementation("org.openrndr:openrndr-extensions:$openrndrVersion")
|
||||
demoImplementation("org.openrndr:openrndr-ffmpeg:$openrndrVersion")
|
||||
|
||||
73
openrndr-demos/src/demo/kotlin/DemoTessShader04.kt
Normal file
73
openrndr-demos/src/demo/kotlin/DemoTessShader04.kt
Normal file
@@ -0,0 +1,73 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.*
|
||||
import org.openrndr.extra.noise.uniform
|
||||
import org.openrndr.extra.noise.uniformRing
|
||||
import org.openrndr.extras.camera.Orbital
|
||||
import org.openrndr.extras.camera.OrbitalCamera
|
||||
import org.openrndr.extras.meshgenerators.sphereMesh
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.resourceUrl
|
||||
import org.openrndr.shape.Ellipse
|
||||
import org.openrndr.shape.path3D
|
||||
|
||||
import org.openrndr.extra.shaderphrases.preprocessedFromUrls
|
||||
import kotlin.math.cos
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
extend(Orbital())
|
||||
|
||||
val path = path3D {
|
||||
moveTo(Vector3.ZERO)
|
||||
for (i in 0 until 100) {
|
||||
continueTo(anchor + Vector3.uniformRing(0.0, 10.0),anchor + Vector3.uniformRing(0.0, 10.0))
|
||||
}
|
||||
}
|
||||
val vb = vertexBuffer(vertexFormat {
|
||||
position(3)
|
||||
}, path.segments.size * 4)
|
||||
|
||||
val shader = Shader.preprocessedFromUrls(
|
||||
vsUrl = resourceUrl("/shaders/ts-04.vert"),
|
||||
tcsUrl = resourceUrl("/shaders/ts-04.tesc"),
|
||||
tesUrl = resourceUrl("/shaders/ts-04.tese"),
|
||||
gsUrl = resourceUrl("/shaders/ts-04.geom"),
|
||||
fsUrl = resourceUrl("/shaders/ts-04.frag")
|
||||
)
|
||||
|
||||
val mesh = sphereMesh()
|
||||
extend {
|
||||
val vc = vb.put {
|
||||
for (segment in path.sub(0.0, cos(seconds*0.1)*0.5+ 0.5).segments) {
|
||||
val cubic = segment.cubic
|
||||
write(cubic.start)
|
||||
write(cubic.control[0])
|
||||
write(cubic.control[1])
|
||||
write(cubic.end)
|
||||
}
|
||||
}
|
||||
drawer.clear(ColorRGBa.PINK)
|
||||
drawer.depthTestPass = DepthTestPass.LESS_OR_EQUAL
|
||||
drawer.depthWrite = true
|
||||
drawer.vertexBuffer(mesh, DrawPrimitive.TRIANGLES)
|
||||
|
||||
shader.begin()
|
||||
shader.uniform("offset", mouse.position.xy0)
|
||||
shader.uniform("view", drawer.view)
|
||||
shader.uniform("proj", drawer.projection)
|
||||
shader.uniform("model", drawer.model)
|
||||
shader.uniform("resolution", 32)
|
||||
shader.uniform("weight", 3.0 + cos(seconds))
|
||||
shader.uniform("time", seconds*0.0)
|
||||
drawer.depthWrite = false
|
||||
|
||||
driver.setState(drawer.drawStyle)
|
||||
driver.drawVertexBuffer(shader, listOf(vb), DrawPrimitive.PATCHES, 0, vc)
|
||||
shader.end()
|
||||
drawer.fill = ColorRGBa.WHITE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
openrndr-demos/src/demo/resources/shaders/ts-04.frag
Normal file
11
openrndr-demos/src/demo/resources/shaders/ts-04.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 = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
77
openrndr-demos/src/demo/resources/shaders/ts-04.geom
Normal file
77
openrndr-demos/src/demo/resources/shaders/ts-04.geom
Normal file
@@ -0,0 +1,77 @@
|
||||
#version 430 core
|
||||
|
||||
layout (lines) in;
|
||||
layout (triangle_strip, max_vertices = 4) 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;
|
||||
in vec3 derivative[];
|
||||
in vec3 position[];
|
||||
|
||||
uniform mat4 proj;
|
||||
uniform mat4 view;
|
||||
uniform mat4 model;
|
||||
uniform float weight;
|
||||
|
||||
|
||||
|
||||
|
||||
void main() {
|
||||
|
||||
mat4 pvm = proj * view * model;
|
||||
|
||||
// vec2 direction0 = normalize(derivative[0].xy);
|
||||
// vec4 perp0 = vec4(direction0.y, -direction0.x, 0.0, 0.0);
|
||||
//
|
||||
// vec2 direction1 = normalize(derivative[1].xy);
|
||||
// vec4 perp1 = vec4(direction1.y, -direction1.x, 0.0, 0.0);
|
||||
|
||||
vec4 p00 = (pvm * vec4(position[0], 1.0));
|
||||
//p00 /= p00.w;
|
||||
vec4 p01 = (pvm * vec4(position[0] + derivative[0], 1.0));
|
||||
//p01 /= p01.w;
|
||||
vec4 p10 = (pvm * vec4(position[1], 1.0));
|
||||
//p10 /= p10.w;
|
||||
vec4 p11 = (pvm * vec4(position[1] + derivative[1], 1.0));
|
||||
//p11 /= p11.w;
|
||||
|
||||
vec2 direction0 = normalize(p01.xy - p00.xy);
|
||||
vec2 direction1 = normalize(p11.xy - p10.xy);
|
||||
vec4 perp0 = vec4(direction0.y, -direction0.x, 0.0, 0.0);
|
||||
vec4 perp1 = vec4(direction1.y, -direction1.x, 0.0, 0.0);
|
||||
|
||||
v_addedProperty = vertices[0].v_addedProperty;
|
||||
va_normal = vertices[0].va_normal;
|
||||
va_position = vertices[0].va_position;
|
||||
gl_Position = pvm * vec4(vec4(position[0], 1.0)) + perp0 * weight * 0.01;
|
||||
EmitVertex();
|
||||
|
||||
v_addedProperty = vertices[0].v_addedProperty;
|
||||
va_normal = vertices[0].va_normal;
|
||||
va_position = vertices[0].va_position;
|
||||
gl_Position = pvm * vec4(vec4(position[0], 1.0)) - perp0 * weight * 0.01;
|
||||
EmitVertex();
|
||||
|
||||
v_addedProperty = vertices[1].v_addedProperty;
|
||||
va_normal = vertices[1].va_normal;
|
||||
va_position = vertices[1].va_position;
|
||||
gl_Position = pvm * vec4(vec4(position[1], 1.0)) + perp1 * weight * 0.01;
|
||||
EmitVertex();
|
||||
|
||||
v_addedProperty = vertices[1].v_addedProperty;
|
||||
va_normal = vertices[1].va_normal;
|
||||
va_position = vertices[1].va_position;
|
||||
gl_Position = pvm * vec4(vec4(position[1], 1.0)) - perp1 * weight * 0.01;
|
||||
EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
17
openrndr-demos/src/demo/resources/shaders/ts-04.tesc
Normal file
17
openrndr-demos/src/demo/resources/shaders/ts-04.tesc
Normal file
@@ -0,0 +1,17 @@
|
||||
#version 430 core
|
||||
|
||||
layout(vertices = 4) out; // 4 points per patch
|
||||
|
||||
uniform int resolution;
|
||||
|
||||
|
||||
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] = resolution; // tessellate the line into 100 segments
|
||||
}
|
||||
}
|
||||
48
openrndr-demos/src/demo/resources/shaders/ts-04.tese
Normal file
48
openrndr-demos/src/demo/resources/shaders/ts-04.tese
Normal file
@@ -0,0 +1,48 @@
|
||||
#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[];
|
||||
|
||||
out vec3 derivative;
|
||||
out vec3 position;
|
||||
|
||||
uniform int resolution;
|
||||
|
||||
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);
|
||||
|
||||
// calculate derivative using Hodograph
|
||||
derivative = bezier3(cva_position[1] - cva_position[0], cva_position[2]-cva_position[1], cva_position[3]-cva_position[2], t);
|
||||
|
||||
// output model space positions
|
||||
position = ePos;
|
||||
|
||||
float r = resolution + 1.0;
|
||||
//gl_Position = proj * view * model * vec4(ePos, 1);
|
||||
}
|
||||
17
openrndr-demos/src/demo/resources/shaders/ts-04.vert
Normal file
17
openrndr-demos/src/demo/resources/shaders/ts-04.vert
Normal file
@@ -0,0 +1,17 @@
|
||||
#version 430 core
|
||||
|
||||
#pragma import org.openrndr.extra.noise.phrases.SimplexKt.phraseSimplex3;
|
||||
|
||||
in vec3 a_position;
|
||||
|
||||
out vec3 va_position;
|
||||
|
||||
uniform mat4 view;
|
||||
uniform mat4 proj;
|
||||
uniform mat4 model;
|
||||
|
||||
uniform float time;
|
||||
|
||||
void main() {
|
||||
va_position = a_position; //4.0* vec3(simplex31(a_position + vec3(time, time, -time) ), 4.0*simplex31(a_position.zxy + vec3(-time, time, time)), 4.0*simplex31(a_position.yzx + vec3(time, -time, time))) ;
|
||||
}
|
||||
Reference in New Issue
Block a user