Im trying to implement basic lighting in Opengl 3+ (a sun) with this tutorial :
http://www.mbsoftworks.sk/index.php?page=tutorials&series=1&tutorial=11
Im building a basic terrain and its working well. Now im trying to add normals, and I think its not working well :
As you can see I dont think my normals are good.
This is how I get them :
for(x = 0; x < this.m_size.width - 1 ; x++)
{
for(y = 0; y < this.m_size.height - 1 ; y++)
{
immutable uint indice1 = y * this.m_size.width + x;
immutable uint indice2 = y * this.m_size.width + (x + 1);
immutable uint indice3 = (y + 1) * this.m_size.width + x;
immutable uint indice4 = (y + 1) * this.m_size.width + x;
immutable uint indice5 = y * this.m_size.width + (x + 1);
immutable uint indice6 = (y + 1) * this.m_size.width + (x + 1);
Vector3 v1 = vertexes[indice3] - vertexes[indice1];
Vector3 v2 = vertexes[indice2] - vertexes[indice1];
Vector3 normal = v1.cross(v2);
normal.normalize();
normals[indice1] = normal;
indices ~= [indice1,
indice2,
indice3,
indice4,
indice5,
indice6];
}
}
I use this basic shader : http://ogldev.atspace.co.uk/www/tutorial18/tutorial18.html or in the link I posted at the top.
Thanks.