gfxwork
Posts: 1
Joined: Wed Sep 18, 2013 9:13 am

Is it mandatory to have attributes in vertex shader?

Wed Sep 18, 2013 9:25 am

Working on opengl es3

Code: Select all

#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);
}



#version 300 es
in mediump vec4 basecolor;

out vec4 FragColor;
void main(void)
{
        FragColor =  basecolor;
}
Above is giving incorrect output. Adding attribute gives correct output .

Thanks.

User avatar
Paeryn
Posts: 2952
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

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

Wed Sep 18, 2013 10:43 am

Where are you putting the attribute? attribute is used to pass per-vertex data to the vertex shader and cannot be written to from within the shader.
The in and out qualifiers in opengl es2 only apply to function parameters. To pass a variable from the vertex shader to the fragment shader it needs to be declared as varying in both shaders.

Code: Select all

#version 100
varying 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);
}



#version 100
varying mediump vec4 basecolor;

out vec4 FragColor;
void main(void)
{
        FragColor =  basecolor;
}
She who travels light — forgot something.

OtherCrashOverride
Posts: 582
Joined: Sat Feb 02, 2013 3:25 am

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

Wed Sep 18, 2013 2:54 pm

The PI does not support OpenGL ES3.

The specification for the version of GLSL (1.0) used by OpenGL ES 2 is here: http://www.khronos.org/registry/gles/sp ... 1.0.17.pdf
Page 29 states the valid storage qualifiers are "const, attribute, uniform, and varying". Page 32 states that "in, out, inout" are only valid as parameter qualifiers to function arguments.

Return to “OpenGLES”