Hello! im trying to “deform” or “rig” a cylinder shape create in Processing and send it to vertex Shader:
here the piece of code that generate the shape:

``````int rr = 50;
int h = 1000;
int vertices = 25;
beginShape(TRIANGLE_STRIP);

for (int i = 0; i <= vertices; i++) {
float angle = TWO_PI / vertices;
float x = sin(i * angle);
float z = cos(i * angle);
float u = float(i) / vertices;

vertex(x * rr, -h/2, z * rr);
vertex(x * rr, +h/2, z * rr);
}
endShape();

``````

here my default vertex:

``````
#version 150

#ifdef GL_ES
precision mediump float;
#endif

in vec4 position;
in vec3 color;
out vec3 Color;
uniform mat4 transform;
in vec2 texCoord;
out vec2 TexCoord;
in vec4 normal;
uniform float u_time;

uniform mat3 normalMatrix;

void main() {

vec4 pos = position;
TexCoord = texCoord;

Color = color;

gl_Position = transform * pos;

}

``````

and here the result:

[ATTACH=CONFIG]1817[/ATTACH]

what i want is try to put the shape into some kind of “spline”, or something like a ray, just something like that:

[ATTACH=CONFIG]1818[/ATTACH]

how can i “bend” geometry to generate that points of intersection? i assume is something that i can do in vertexShader, but maybe im wrong. thanks a lot

A vertex shader can change the position of vertices, but it can’t create new vertices. So you’d need to subdivide the mesh length-wise, then you can use the vertex shader to move the intermediate vertices (or you could just move them in the application code; there’s no reason to do this in the vertex shader unless the calculation is dynamic).

Or you could use a tessellation shader, which can dynamically subdivide a triangular or quadrilateral patch into triangles. But those require OpenGL 4.0 or the ARB_tessellation_shader extension.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.