Is it mandatory to have attributes in vertex shader?

Hi ,

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


#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:


#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


#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.

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:

glDrawArrays()  is somthing like:
foreach(  attrib as $val )
{
  call vertexshader();
}

cu
uwi

[QUOTE=uwi2k2;1254926]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:

glDrawArrays()  is somthing like:
foreach(  attrib as $val )
{
  call vertexshader();
}

cu
uwi[/QUOTE]

what if you have static values for gl_position ?


gl_position=vec4(1.0);

[QUOTE=uwi2k2;1254926]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:
[/QUOTE]

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.

yes, its not mentioned in the GLES3 spec that we need attribute in vertex shader for rendering.
Same case is with GLES2 as well.

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?

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.

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.