I have created a project on top of the XCode OpenGL ES template.
Is there a way to customize the shader color for each object?
Shader.vsh:
attribute vec4 position;
attribute vec3 normal;
varying lowp vec4 colorVarying;
uniform mat4 modelViewProjectionMatrix;
uniform mat3 normalMatrix;
void main()
{
vec3 eyeNormal = normalize(normalMatrix * normal);
vec3 lightPosition = vec3(1.0, 1.0, 1.0);
vec4 diffuseColor = vec4(1, 0.4, 1.0, 1.0);
float nDotVP = max(0.0, dot(eyeNormal, normalize(lightPosition)));
colorVarying = diffuseColor * nDotVP;
gl_Position = modelViewProjectionMatrix * position;
}
Shader.fsh:
varying lowp vec4 colorVarying;
void main()
{
gl_FragColor = colorVarying;
}
Do i need to create an extra attribute in Shader.vsh which parses the color to replace diffuse variable or how is this done?
I suggest using uniform variables for colors
and in the code just set the value:
the same can be done with light position as well.