Update Normal calcul
This commit is contained in:
parent
3a7d169b30
commit
2b62d3b9e4
2 changed files with 8 additions and 5 deletions
|
|
@ -64,8 +64,8 @@ namespace LandblockExtraction.LandBlockExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector2 GenerateBasicUV(int x, int y) {
|
private Vector2 GenerateBasicUV(int x, int y) {
|
||||||
float u = (float)x / (BlockSize - 1) * 16;
|
float u = (float)x / (BlockSize - 1) * 8;
|
||||||
float v = (float)y / (BlockSize - 1) * 16;
|
float v = (float)y / (BlockSize - 1) * 8;
|
||||||
|
|
||||||
return new Vector2(u, v);
|
return new Vector2(u, v);
|
||||||
}
|
}
|
||||||
|
|
@ -79,25 +79,28 @@ namespace LandblockExtraction.LandBlockExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parcourt tous les indices et calcule les normales pour chaque triangle
|
// Parcourt tous les indices et calcule les normales pour chaque triangle
|
||||||
for (int i = 0; i < blockStruct.indices.Length; i += 3) {
|
for (int i = 0; i < blockStruct.indices.Length; i += 6) {
|
||||||
int index1 = blockStruct.indices[i];
|
int index1 = blockStruct.indices[i];
|
||||||
int index2 = blockStruct.indices[i + 1];
|
int index2 = blockStruct.indices[i + 1];
|
||||||
int index3 = blockStruct.indices[i + 2];
|
int index3 = blockStruct.indices[i + 2];
|
||||||
|
int index4 = blockStruct.indices[i + 5];
|
||||||
|
|
||||||
Vector3 vertex1 = blockStruct.verticesStruct.position[index1];
|
Vector3 vertex1 = blockStruct.verticesStruct.position[index1];
|
||||||
Vector3 vertex2 = blockStruct.verticesStruct.position[index2];
|
Vector3 vertex2 = blockStruct.verticesStruct.position[index2];
|
||||||
Vector3 vertex3 = blockStruct.verticesStruct.position[index3];
|
Vector3 vertex3 = blockStruct.verticesStruct.position[index3];
|
||||||
|
Vector3 vertex4 = blockStruct.verticesStruct.position[index4];
|
||||||
|
|
||||||
// Calcule la normale du triangle
|
// Calcule la normale du triangle
|
||||||
/*Vector3 edge1 = vertex2 - vertex1;
|
/*Vector3 edge1 = vertex2 - vertex1;
|
||||||
Vector3 edge2 = vertex3 - vertex1;
|
Vector3 edge2 = vertex3 - vertex1;
|
||||||
Vector3 normal = Vector3.Cross(edge1, edge2);
|
Vector3 normal = Vector3.Cross(edge1, edge2);
|
||||||
normal = Vector3.Normalize(normal);*/
|
normal = Vector3.Normalize(normal);*/
|
||||||
var normal = MathOperations.CalculateTriangleNormal(vertex1, vertex2, vertex3);
|
var normal = MathOperations.CalculateQuadNormal(vertex1, vertex2, vertex3, vertex4);
|
||||||
// Ajoute la normale du triangle aux normales des sommets du triangle
|
// Ajoute la normale du triangle aux normales des sommets du triangle
|
||||||
normals[index1] += normal;
|
normals[index1] += normal;
|
||||||
normals[index2] += normal;
|
normals[index2] += normal;
|
||||||
normals[index3] += normal;
|
normals[index3] += normal;
|
||||||
|
normals[index4] += normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalise toutes les normales de sommets pour qu'elles soient de longueur unitaire
|
// Normalise toutes les normales de sommets pour qu'elles soient de longueur unitaire
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ void main()
|
||||||
|
|
||||||
float inclineFactor = abs(norm.y);
|
float inclineFactor = abs(norm.y);
|
||||||
|
|
||||||
vec4 finalColor = mix(color0, color1, inclineFactor);
|
vec4 finalColor = mix(color0, color1, norm.y);
|
||||||
|
|
||||||
vec3 lightDir = normalize(lightPos - FragPos);
|
vec3 lightDir = normalize(lightPos - FragPos);
|
||||||
float diff = max(dot(norm, lightDir), 0.0);
|
float diff = max(dot(norm, lightDir), 0.0);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue