changed terrain normals to consider 8 vertices, looks the same

This commit is contained in:
Steffen Fündgens 2014-11-18 13:09:55 +01:00
parent 6a8182ab8d
commit 5a92765518
2 changed files with 12 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -114,12 +114,20 @@ void Terrain::set_abData(float* abData, unsigned int dataCount, unsigned int row
glm::vec3 sumNormals = glm::vec3(0.0f, 0.0f, 0.0f);
for (int i=-1; i<2; i+=2) {
for (int j=-1; j<2; j+=2) {
glm::vec3 vecA, vecB, normal;
vecA = glm::vec3((float)i, (heightmap[rowNum+i][columnNum] - heightmap[rowNum][columnNum]), 0.0f);
vecB = glm::vec3(0.0f, (heightmap[rowNum][columnNum+j] - heightmap[rowNum][columnNum]), (float)j);
glm::vec3 vecA, vecB, vecC, normal;
vecA = glm::normalize(glm::vec3((float)i, (heightmap[rowNum+i][columnNum] - heightmap[rowNum][columnNum]), 0.0f));
vecB = glm::normalize(glm::vec3((float)i, (heightmap[rowNum+i][columnNum+j] - heightmap[rowNum][columnNum]), (float)j));
normal = glm::normalize(glm::cross(vecA, vecB));
if(i+j!=0)
if(i+j!=0){
normal = normal*(-1.0f);
}
sumNormals += normal;
vecC = glm::normalize(glm::vec3(0.0f, (heightmap[rowNum][columnNum+j] - heightmap[rowNum][columnNum]), (float)j));
normal = glm::normalize(glm::cross(vecB, vecC));
if(i+j!=0){
normal = normal*(-1.0f);
}
sumNormals += normal;
}
}