I hope someone can help me with this as I don’t seem to be making any progress. I am trying to do a (fairly) simple shader that will be a timer. It will remove segments of a image I pass in like a clock until it is all gone. My shaders are below and I have tested them running in a emulator through Visual Studio and it looks fine. When I load onto a Playbook through Momentics though it draws nothing.
Vertex Shader:
attribute vec4 a_position;
attribute vec2 a_texCoord;
attribute vec4 a_color;
uniform mat4 u_MVPMatrix;
#ifdef GL_ES
varying lowp vec4 v_fragmentColor;
varying mediump vec2 v_texCoord;
#else
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
#endif
void main()
{
gl_Position = u_MVPMatrix * a_position;
v_fragmentColor = a_color;
v_texCoord = a_texCoord;
}
Fragment Shader:
#ifdef GL_ES
precision highp float;
#endif
#define pi 3.141592653589793238462643383279
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
uniform sampler2D u_texture;
uniform float u_percent;
void main()
{
vec4 text = texture2D(u_texture, v_texCoord);
vec4 frag = v_fragmentColor;
float pointX = v_texCoord.x - 0.5;
float pointY = v_texCoord.y - 0.5;
float tangent = atan(pointX,pointY * -1.0);
tangent += pi;
float within = pi * 2.0 * u_percent;
bool test = tangent > within;
if(test)
{
frag.a = 0.0;
frag.r = 0.0;
frag.g = 0.0;
frag.b = 0.0;
}
gl_FragColor = frag * text;
}
To load my shader I do the following:
CCSprite* mTimerImageOuter = CCSprite::spriteWithFile(ResourceSelector::getInstance()->layoutPath("player_avatar_timer_bg_outer.png").c_str());
mTimerImageOuter->setPosition(ccp(mFrame->getContentSize().width * 0.5f, mFrame->getContentSize().height * 0.5f));
mFrame->addChild(mTimerImageOuter);
mTimerImageOuter->setVisible(false);
std::string fragmentSource = ResourceSelector::getInstance()->path("circle_shader_frag.fsh");
std::string vertexSource = ResourceSelector::getInstance()->path("circle_shader_vert.vsh");
CCGLProgram *glProgram = new CCGLProgram();
glProgram->initWithVertexShaderFilename(vertexSource.c_str(), fragmentSource.c_str());
mTimerImageOuter->setShaderProgram(glProgram);
glProgram->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
glProgram->link();
glProgram->use();
ccBlendFunc blendFunc;
blendFunc.src = GL_SRC_ALPHA;
blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
mTimerImageOuter->setBlendFunc(blendFunc);
The only thing I have learned so far is if I change “gl_Position = u_MVPMatrix * a_position;” to “gl_Position = a_position;” in my vertex shader, I will draw a filled cube in the top right corner of the Playbook screen. So I think something is going wrong with my Model View Projection matrix but I have no idea what it could be.
Any help or guidance would be useful.