I managed to implement an infinite 2d texture scrolling using the following shader. btw I'm using cocos2d-x 2.2.1.
The vertex shader:
attribute vec4 a_position;
attribute vec2 a_texCoord;
#ifdef GL_ES
varying mediump vec2 v_texCoord;
#else
varying vec2 v_texCoord;
#endif
void main()
{
gl_Position = CC_MVPMatrix * a_position;
v_texCoord = a_texCoord;
}
The fragment shader:
#ifdef GL_ES
precision lowp float;
#endif
uniform vec2 u_time;
uniform vec4 u_color;
varying vec2 v_texCoord;
uniform sampler2D CC_Texture0;
void main()
{
gl_FragColor = texture2D(CC_Texture0, v_texCoord + u_time);
}
But once I try to add some uniform color the texture is no more repeated correctly (and performance decreases drastically):
/// Texture not repeated correctly and performance degradation
gl_FragColor = texture2D(CC_Texture0, v_texCoord + u_time) * u_color;
However the following repeat the texture correctly (but of course there's no scrolling)
gl_FragColor = texture2D(CC_Texture0, v_texCoord) * u_color;
What am I doing wrong?