Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: bend geometry in vertexShader

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2018
    Posts
    4

    bend geometry in vertexShader

    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:

    Code cpp:
    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:

    Code glsl:
    #version 150
     
    #define PROCESSING_COLOR_SHADER
     
    #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:

    Click image for larger version. 

Name:	frameCount_010899.jpg 
Views:	50 
Size:	25.9 KB 
ID:	2804

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

    Click image for larger version. 

Name:	frameCount_010828.jpg 
Views:	64 
Size:	28.9 KB 
ID:	2805

    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
    Last edited by Dark Photon; 07-17-2018 at 05:38 PM.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,984
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •