[openrndr-demos] Add DemoTessShader04
This commit is contained in:
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