OpenGL ES 2.0 defining normals for vertex shader

I cannot get the correct shading on all the faces of the cube that I drew. I get a smooth transition from one person to another person that does not show edges properly.

On the other face (where I get the desired edge), I get the shading so that it shows the two triangles that make up this face. I believe the problem is with the normals that I point out. I attach my vertex and normal matrix, as well as my vertex and fragment code. the vertex and the normal matrix are the same.

I think the problem is with normals, but I tried almost everything with them, but the effect does not change.

//normal matrix and vertex matrix are same

static const float normals[]=

    {
         //v0,v1,v2,v3,
         //v4,v5,v6,v7
        0.5,0.5,0.5, -0.5,0.5,0.5, -0.5,-0.5,0.5, 0.5,-0.5,0.5, 

        0.5,0.5,-0.5, -0.5,0.5,-0.5, -0.5,-0.5,-0.5, 0.5,-0.5,-0.5 

    };

//vertex shader

attribute vec4 color;
attribute vec4 position; 

attribute vec4 normal;

uniform mat4 u_mvpMatrix;
uniform vec4 lightDirection;
uniform vec4 lightDiffuseColor;
uniform float translate;

varying vec4 frontColor;



//varying vec4 colorVarying;



void main()

{

   vec4 normalizedNormal = normalize(u_mvpMatrix* normal);
   vec4 normalizedLightDirection = normalize(lightDirection);

   float nDotL = max(dot(normalizedNormal, normalizedLightDirection), 0.0);


   frontColor =  color * nDotL * lightDiffuseColor;


  gl_Position = u_mvpMatrix * position;


}

//fragment shader

varying lowp vec4 frontColor;

void main()
{


        gl_FragColor = frontColor;


}

Please, help? Thanks in advance!

+3
source share
1

, .

, , 8 , , , ; , .

, : 4 , . , 6x4 = 24 ( ).

: http://www.songho.ca/opengl/gl_vertexarray.html

+2

All Articles