Android Shader Issue

Android Shader Issue
0.0 0


Hi. I am developing a small prototype and I wrote a small shader for the main character. It just multiplies pixel colors by custom value(from 0 to 1 to make a character become more dark) calculated in the game.

It works fine on PC but on android it doesn’t show a texture.
This is my first experience width shaders so I am not sure what the problem can be.

Fragment shader:

#ifdef GL_ES								
precision lowp float;						
varying vec4 v_fragmentColor;				
varying vec2 v_texCoord;					
uniform sampler2D CC_Texture0;	

uniform float u_m_1;		
void main()									
	gl_FragColor = vec4(u_m_1, u_m_1, u_m_1, 255) * v_fragmentColor * texture2D(CC_Texture0, v_texCoord);		

Creating a shader:


    CCGLProgram *shader = new CCGLProgram(); 
    shader->initWithVertexShaderFilename("user_vertex_shader.vsh", "user_fragment_shader.fsh");
    shader->addAttribute("u_m_1", _multiplier_attr);

    CCShaderCache::sharedShaderCache()->addProgram(shader, "user_shader");

Applying this shader to user sprite:

CCGLProgram *program = CCShaderCache::sharedShaderCache()->programForKey("user_shader");

Later updating the value:

CCGLProgram *program = CCShaderCache::sharedShaderCache()->programForKey("user_shader");
glUniform1f(  glGetUniformLocation(program->getProgram(), "u_m_1"), params );

Really need someone’s help.


BTW: on Genymotion emulator works fine. But on real device - no success.


I don’t know what’s the real problem, but this part is not correct gl_FragColor = vec4(u_m_1, u_m_1, u_m_1, 255), since components of the color should be in range [0.0, 1.0]