PDA

View Full Version : Is it mandatory to have attributes in vertex shader?



harsha
09-18-2013, 12:34 AM
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.

uwi2k2
09-18-2013, 01:01 AM
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

debonair
09-18-2013, 01:40 AM
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

what if you have static values for gl_position ?


gl_position=vec4(1.0);

menzel
09-18-2013, 02:11 AM
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.

harsha
09-18-2013, 02:51 AM
yes, its not mentioned in the GLES3 spec that we need attribute in vertex shader for rendering.
Same case is with GLES2 as well.

mhagain
09-18-2013, 03:00 AM
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 (http://www.khronos.org/message_boards/forumdisplay.php/56) as you're more likely to encounter someone who actually knows?

GClements
09-18-2013, 04:30 AM
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.

mhagain
09-18-2013, 04:51 AM
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.