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 8 of 8

Thread: Is it mandatory to have attributes in vertex shader?

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    13

    Is it mandatory to have attributes in vertex shader?

    Hi ,

    I have a vertex shader which do not have any attributes in it

    Code :
    #version 300 es
     
    out mediump vec4 basecolor;
     
    uniform ivec2 x1;
     
    void main(void)
    {
            if(x1 == ivec2(10,20))
                    basecolor = vec4(0.0, 1.0, 0.0, 1.0);
            else
                  basecolor = vec4(1.0, 0.0, 1.0, 1.0);
     
            gl_PointSize = 64.0;
            gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
    }
    Fragment shader:
    Code :
    #version 300 es
    in mediump vec4 basecolor;
     
    out vec4 FragColor;
    void main(void)
    {
            FragColor =  basecolor;
    }

    passing value to 'x1' uniform as glUniform2i(loc, 10,20) and drawing as glDrawArrays(GL_POINTS, 0, 1);
    It should render green color point, but giving random color.

    But if I have any attribute in vertex shader as

    Code :
    #version 300 es
     
    out mediump vec4 basecolor;
     
    in medium vec4 icolor; // add attribute
    uniform ivec2 x1;
     
    void main(void)
    {
            if(x1 == ivec2(10,20))
                    basecolor = vec4(0.0, 1.0, 0.0, 1.0);
            else
                  basecolor = icolor;
     
            gl_PointSize = 64.0;
            gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
    }


    it gives me correct output as green color point.

    Thus, is it mandatory to have attributes in vertex shader?

    Thanks.

  2. #2
    Intern Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    98
    hi,

    yes you are right, you NEED to have attributes at all, cause these are the base data for a vertexshader call.
    without attributes the shaders won´t be called at all, because:
    Code :
    glDrawArrays()  is somthing like:
    foreach(  attrib as $val )
    {
      call vertexshader();
    }

    cu
    uwi
    uwi2k2 - OpenGL Trainer: www.opengl-trainer.com
    ---------------------------------------------------------
    Free Programming Helpline: www.programming-hotline.com
    ---------------------------------------------------------
    A Friday Night Programmer: www.uwiworld.net

  3. #3
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207
    Quote Originally Posted by uwi2k2 View Post
    hi,

    yes you are right, you NEED to have attributes at all, cause these are the base data for a vertexshader call.
    without attributes the shaders won´t be called at all, because:
    Code :
    glDrawArrays()  is somthing like:
    foreach(  attrib as $val )
    {
      call vertexshader();
    }

    cu
    uwi
    what if you have static values for gl_position ?
    Code :
    gl_position=vec4(1.0);

  4. #4
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    325
    Quote Originally Posted by uwi2k2 View Post
    hi,

    yes you are right, you NEED to have attributes at all, cause these are the base data for a vertexshader call.
    without attributes the shaders won´t be called at all, because:
    On desktop GL you don't need any attributes and I often use attribute-less rendering there. I would be surprised if the GLES 3 specs (the shader was GLES 3) would demand an attribute.

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    13
    yes, its not mentioned in the GLES3 spec that we need attribute in vertex shader for rendering.
    Same case is with GLES2 as well.

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,183
    In either case, this isn't the GL ES forum, it's the desktop GL forum. Perhaps you'd be better off asking on the GL ES forum as you're more likely to encounter someone who actually knows?

  7. #7
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    Quote Originally Posted by harsha View Post
    Thus, is it mandatory to have attributes in vertex shader?
    In theory, no. In practice, I've had similar issues with shaders which don't have at least one attribute.

    It may be related to attribute zero being special in the compatibility profile (attribute 0 is the vertex position; calling glVertexAttrib(0,...) between glBegin() and glEnd() causes a new vertex to be emitted, as with glVertex()). It's also a fairly safe bet that the case of a vertex shader which has no inputs doesn't get much testing.

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,183
    Actually a vertex shader with no inputs is the classic use case of drawing a full-screen quad, using gl_VertexID as a source for either looking up or calculating the outputs.

Posting Permissions

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