Add Normal in vertex. And add light in shader.

This commit is contained in:
Troispoils 2024-02-28 17:07:45 +01:00
parent 8908ef1332
commit 0e96615b32
16 changed files with 221 additions and 85 deletions

View file

@ -70,7 +70,7 @@ namespace Map3DRendering {
}
}
private void InitializeBlock(int x, int y, BlockStruct block, Shader _shader) {
int lenghPacket = 18;
int lenghPacket = 21;
// Initialisez le VAO, VBO et EBO pour le bloc à (x, y)...
// Utilisez le code de votre méthode OnLoad originale pour configurer le VAO, VBO et EBO.
int tempVertexArray = GL.GenVertexArray();
@ -93,25 +93,29 @@ namespace Map3DRendering {
GL.EnableVertexAttribArray(vertexLocation);
GL.VertexAttribPointer(vertexLocation, 3, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 0);
var vertexNormal = _shader.GetAttribLocation("aNormal");
GL.EnableVertexAttribArray(vertexNormal);
GL.VertexAttribPointer(vertexNormal, 3, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 3 * sizeof(float));
var colorLocation = _shader.GetAttribLocation("aColor");
GL.EnableVertexAttribArray(colorLocation);
GL.VertexAttribPointer(colorLocation, 4, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 3 * sizeof(float));
GL.VertexAttribPointer(colorLocation, 4, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 6 * sizeof(float));
var farcolorLocation = _shader.GetAttribLocation("aColorFar");
GL.EnableVertexAttribArray(farcolorLocation);
GL.VertexAttribPointer(farcolorLocation, 4, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 7 * sizeof(float));
GL.VertexAttribPointer(farcolorLocation, 4, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 10 * sizeof(float));
var texturecoordLocation = _shader.GetAttribLocation("aTexCoord");
GL.EnableVertexAttribArray(texturecoordLocation);
GL.VertexAttribPointer(texturecoordLocation, 2, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 11 * sizeof(float));
GL.VertexAttribPointer(texturecoordLocation, 2, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 14 * sizeof(float));
var terraintypeLocation = _shader.GetAttribLocation("aTexType");
GL.EnableVertexAttribArray(terraintypeLocation);
GL.VertexAttribPointer(terraintypeLocation, 4, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 13 * sizeof(float));
GL.VertexAttribPointer(terraintypeLocation, 4, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 16 * sizeof(float));
var realterraintypeLocation = _shader.GetAttribLocation("aRealTexType");
GL.EnableVertexAttribArray(realterraintypeLocation);
GL.VertexAttribPointer(realterraintypeLocation, 1, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 13 * sizeof(float));
GL.VertexAttribPointer(realterraintypeLocation, 1, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 20 * sizeof(float));
}
public void Render(Shader shader) {
for (int y = startY; y <= endY; y++) {