Shader problem

This is my first question here, i am using opengl es 2.0 and am currently working with a custom shader. My problem is that when i try to use the vertex normal attribute it shows nothing. I know that the normals are set correctly and the shader is seeing the normal because i can add it to position in the vertex shader and all faces will explode outward by 1.0. however if i do anything with it in anyway it simple shows nothing on screen.

below is the code for this i have commented out the parts to allow it to work. if i uncomment the normal part it simple doesn’t show anything with no compile errors.

uniform mediump mat4 ModelViewMatrix;
uniform mediump mat4 ProjectionMatrix;
uniform mediump mat3 NormalMatrix;
uniform mediump vec3 LightPosition;

attribute mediump vec3 VertexPosition;
attribute lowp vec3 VertexNormal;

varying lowp vec3 LightColor;

void main(void)
{
mediump vec3 position = vec3(ModelViewMatrix * vec4(VertexPosition, 1.0));
//lowp vec3 normal = normalize(NormalMatrix * VertexNormal);

/* Calculate the light direction */
mediump vec3 lightdirection = normalize(LightPosition - position);

/* Calculate the intensity of the light with the dot product */
//lowp float ndotl = max(dot(normal, lightdirection), 0.0);

/* Light color = intensity * color of the light */
LightColor = vec3(1.0);

/* Transform the positions from eye coordinates to clip coordinates */
gl_Position = ProjectionMatrix * vec4(position, 1.0);
}

Please help!

Hi ,
I can think of two reasons for this

  1. Give the normal attribute a higher precision (change lowp to mediump) like this
attribute mediump vec3 VertexNormal;
  1. You should actually use the calculated value (i.e.) ndotl in the shader otherwise the GLSL compiler will strip it out during compilation. Change lightcolor to following.

//on top
attribute mediump vec3 VertexNormal;
//...
//in main
mediump vec3 normal = normalize(NormalMatrix * VertexNormal);
/* Calculate the intensity of the light with the dot product */
mediump float ndotl = max(dot(normal, lightdirection), 0.0);
LightColor = vec3(ndotl,ndotl,ndotl);

See if this helps.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.