Results 1 to 6 of 6

Thread: Geometry shaders

  1. #1
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    318

    Geometry shaders

    Hi,
    I have just started with geometric shaders and stuck-up at basics only
    I am trying to draw GL_TRIANGLE_STRIP.

    My vertex array:

    Code :
     
    	const   GLfloat data[] = 
    		{
    			-0.9f,  -0.2f, 
    			-0.9f,  -0.9f, 
    			-0.2f,  -0.9f, 
    			-0.2f, -0.2f,
     
    			-0.1f,-0.2f, 
    			-0.1f,-0.9f, 
    			0.4f,-0.9f,
    			0.4f,-0.2f,
     
    		0.5, -0.2,
    		0.5, -0.9,
    		0.8, -0.9,
    		0.8, -0.2
     
    	};

    Vertex shader:
    Code :
    in  vec4 v_color;
    flat varying vec4 out_color;
    in vec2 Position;
     
    void main()
    {	
    	gl_Position = vec4(Position,0.0,1.0);
    	out_color = v_color;
    }

    geo shader

    Code :
    in vec4 pos[3];
     
    void main()
    {
       int i;
       vec4 vertex;
     
        gl_Position = pos[0];
        EmitVertex();
     
        gl_Position = pos[1];
        EmitVertex();
     
        gl_Position = pos[2];
        EmitVertex();
     
        gl_Position = pos[0] + vec4(0.0,0.5,0.0,0.0);
        EmitVertex();
     
        EndPrimitive();
    }

    Also, i am setting input and output modes for geo shader and making call to glDrawArrays
    Code :
    	glProgramParameteriEXT(shader_data.psId, GL_GEOMETRY_INPUT_TYPE_EXT, GL_TRIANGLES);
     
    	glProgramParameteriEXT(shader_data.psId, GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP);
     
    glDrawArrays(GL_TRIANGLE_STRIP,0,4);

    Here, the program is behaving like geo shaders are not included. In geo shader, i am assigning my own coords to 4th vertex but it is taking the one from data array. Geo shader is compiling with success but whatever changes done in geo shader are not getting reflected while rendering. What am i missing here?
    Also, as i dont want to mess with colors passed to vert shader, i have not included them in geo shader. And it applies colors successfully to geometry.
    When i call glDraw with 3 instead of 4 (as shown above) it renders 1 triangle.

  2. #2
    Newbie Newbie
    Join Date
    Jan 2013
    Posts
    2

    layout

    Should you declare the input and output primitive types in geometry shader?
    like
    "
    layout ( triangles) in;
    layout (triangle_strip, max_vertices = 4) out;

    "


    Quote Originally Posted by debonair View Post
    Hi,
    I have just started with geometric shaders and stuck-up at basics only
    I am trying to draw GL_TRIANGLE_STRIP.

    My vertex array:

    Code :
     
    	const   GLfloat data[] = 
    		{
    			-0.9f,  -0.2f, 
    			-0.9f,  -0.9f, 
    			-0.2f,  -0.9f, 
    			-0.2f, -0.2f,
     
    			-0.1f,-0.2f, 
    			-0.1f,-0.9f, 
    			0.4f,-0.9f,
    			0.4f,-0.2f,
     
    		0.5, -0.2,
    		0.5, -0.9,
    		0.8, -0.9,
    		0.8, -0.2
     
    	};

    Vertex shader:
    Code :
    in  vec4 v_color;
    flat varying vec4 out_color;
    in vec2 Position;
     
    void main()
    {	
    	gl_Position = vec4(Position,0.0,1.0);
    	out_color = v_color;
    }

    geo shader

    Code :
    in vec4 pos[3];
     
    void main()
    {
       int i;
       vec4 vertex;
     
        gl_Position = pos[0];
        EmitVertex();
     
        gl_Position = pos[1];
        EmitVertex();
     
        gl_Position = pos[2];
        EmitVertex();
     
        gl_Position = pos[0] + vec4(0.0,0.5,0.0,0.0);
        EmitVertex();
     
        EndPrimitive();
    }

    Also, i am setting input and output modes for geo shader and making call to glDrawArrays
    Code :
    	glProgramParameteriEXT(shader_data.psId, GL_GEOMETRY_INPUT_TYPE_EXT, GL_TRIANGLES);
     
    	glProgramParameteriEXT(shader_data.psId, GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP);
     
    glDrawArrays(GL_TRIANGLE_STRIP,0,4);

    Here, the program is behaving like geo shaders are not included. In geo shader, i am assigning my own coords to 4th vertex but it is taking the one from data array. Geo shader is compiling with success but whatever changes done in geo shader are not getting reflected while rendering. What am i missing here?
    Also, as i dont want to mess with colors passed to vert shader, i have not included them in geo shader. And it applies colors successfully to geometry.
    When i call glDraw with 3 instead of 4 (as shown above) it renders 1 triangle.

  3. #3
    Newbie Newbie
    Join Date
    Jan 2013
    Posts
    2
    or add something like this:
    "
    glProgramParameteriEXT(shader_data.psId, GL_GEOMETRY_VERTICES_OUT_EXT, 4);
    "

  4. #4
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    318
    Quote Originally Posted by kevinz View Post
    or add something like this:
    "
    glProgramParameteriEXT(shader_data.psId, GL_GEOMETRY_VERTICES_OUT_EXT, 4);
    "
    Actually, tried with that too..

  5. #5
    Newbie Newbie
    Join Date
    Jan 2013
    Posts
    1
    I'm new at GS too, but a couple of things look odd at first glance.

    In VS you write to gl_Position, but in GS you read from pos[] array. Built-in varyings live in the gl_in[] array, so write gl_in[i].gl_Position. If VS had an out variable named pos, I think that would work too, but I've only used the built-in array.

    Did you specify "layout (primtype) in;" & "layout (primtype, max_vertices = x);" in the geometry shader? I'm not familiar with glProgramParameteriEXT as used in your example.

    Also, is the compiled GS attached to the program (just like the VS) before link time? If not, that would explain why it's acting like GS doesn't exist.

    Hope one of these things is helpful!

  6. #6
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    318
    Guess what, i forgot to attach geometry shader, lolz

    BTW, thank you all for your reply..

Similar Threads

  1. Geometry shaders
    By V-man in forum OpenGL: GLSL
    Replies: 6
    Last Post: 09-21-2008, 09:42 PM
  2. geometry shaders
    By Pswin in forum OpenGL: GLSL
    Replies: 6
    Last Post: 08-07-2008, 04:35 PM
  3. Geometry Shaders...
    By tooltech in forum OpenGL: macOS
    Replies: 2
    Last Post: 02-11-2008, 08:09 AM
  4. Geometry Shaders
    By tooltech in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 12-03-2007, 06:10 PM
  5. geometry instance (geometry shaders)
    By azazello in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 05-05-2004, 02:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean