ofMesh and Shadow

Hello
I program a 3d waveform,
So i build my 3d waveform :

  
for(int i=0;i<waveForms.size()-1;i++){  
			if(i%2==0){  
			for(int j=0;j<waveForms[i].size();j++){  
				ofVec3f vec0(waveForms[i][j].x,waveForms[i][j].y,i*20);  
				ofVec3f vec1(waveForms[i+1][j].x,waveForms[i+1][j].y,(i+1)*20);  
				plan.addVertex(vec0);  
				plan.addVertex(vec1);  
			}		  
			}else {  
				  
			  
  
			for(int j=waveForms[i].size()-1;j>0;j--){  
				ofVec3f vec0(waveForms[i][j].x,waveForms[i][j].y,i*20);  
				ofVec3f vec1(waveForms[i+1][j].x,waveForms[i+1][j].y,(i+1)*20);  
				plan.addVertex(vec0);  
				plan.addVertex(vec1);  
			}		  
			}  
  

So one time i go to left to right and after to right to left.
I use some polyline for my coordinate ( a vector called waveForms )
My problem is when i render my mesh, i obtain a totally white 3d, without any shadow ( i added a light , and the brightness of my mesh change when i move my easycam, so the light affect the mesh ). But i got any relief…
What i miss for obtain a shadowed mesh ?

you’ll have to add normals, so your mesh renders correctly. Normals are used to compute the shading for a specific vertice.

HTH,
Stephan

ok thanks.
So i added normal, i placed it on the middle of hypothenus of my vertices triangles ( center of my face )

But i obtain something strange, like if i had both mesh, one shadowed and other bright, covering one by other , depend of angle i look my mesh.
Do you see where is my problem ?

Have you added a normal per vertex? Can you post a screenshot?


and how i add normal to my vertices :

  
	for(int i=0;i<waveForms.size()-1;i++){  
			// if odd, go to left to right  
			if(i%2==0){  
			for(int j=0;j<waveForms[i].size();j++){  
				ofVec3f vec0(waveForms[i][j].x,waveForms[i][j].y,i*20);  
				ofVec3f vec1(waveForms[i+1][j].x,waveForms[i+1][j].y,(i+1)*20);  
				ofVec3f vec2(waveForms[i][j+1].x,waveForms[i][j+1].y,i*20);  
				ofVec3f vecN((vec1+vec2)/2);  
				plan.addVertex(vec0);  
				plan.addColor(couleur);  
				plan.addNormal(vecN);  
				plan.addVertex(vec1);  
				plan.addColor(couleur);  
				plan.addNormal(vecN);  
			}  
				// if even go to right to left  
			}else {  
				  
			  
  
			for(int j=waveForms[i].size()-1;j>0;j--){  
				ofVec3f vec0(waveForms[i][j].x,waveForms[i][j].y,i*20);  
				ofVec3f vec1(waveForms[i+1][j].x,waveForms[i+1][j].y,(i+1)*20);  
				ofVec3f vec2(waveForms[i][j-1].x,waveForms[i][j-1].y,i*20);  
				ofVec3f vecN((vec1+vec2)/2);  
				plan.addVertex(vec0);  
				plan.addNormal(vecN);  
				plan.addColor(couleur);  
				plan.addVertex(vec1);  
				plan.addNormal(vecN);  
				plan.addColor(couleur);  
			}		  
			}  
		}  

Hi,

please have a read about normals and lighting in Open GL.

Your computation of the normals seems incorrect, your normals seems not to be normalized, this will result in wrong shading.

Thanks, i will read about it, and i hope find a way for do this work
But i must place my normal before or after add my vertex ?

So it’s working.
I tried first to use glEnable(GL_NORMALIZE), but the result is not very pretty.
Finally by using a getPerpendicular of ofVec3, i obtained working normal.