Sign in to follow this  
VansFannel

OpenGL OpenGL ES 2.0: attribute not bound on vertex shader.

Recommended Posts

Hello.

I'm developing an Android application.

I have the following vertex shader.

"attribute vec4 vertexPosition;
attribute vec4 vertexNormal;
attribute vec2 vertexTexCoord;

varying vec2 texCoord;
varying vec4 normal;

uniform mat4 modelViewProjectionMatrix;

void main()
{
gl_Position = modelViewProjectionMatrix * vertexPosition;
normal = vertexNormal;
texCoord = vertexTexCoord;
}
";

And this is the fragment shader:

precision mediump float;

varying vec2 texCoord;
varying vec4 normal;

uniform sampler2D texSampler2D;

void main()
{
gl_FragColor = texture2D(texSampler2D, texCoord);
}
";

Is there any problem if I left vertexTexCoord unbound? I think I must use a different vertex and fragment shader if my model doesn't have a texture, isn't?

Thanks.

Share this post


Link to post
Share on other sites
In general I don't think there is a problem with leaving a vertex attribute unbound if you don't need it for whatever reason, but what are you expecting to happen in your particular shader?

Your output color is directly dependent on the texcoord and a texture being bound, so you're going to get garbage output from this.

You should probably have a separate shader (or some kind of compile time IFDEF) for rendering with/without textures.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this