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

@ -2,7 +2,6 @@
using LandblockExtraction.AtlasMaker;
using LandblockExtraction.DatEngine;
using LandblockExtraction.Tools;
using System.Dynamic;
using System.Numerics;
namespace LandblockExtraction.LandBlockExtractor {
@ -25,11 +24,11 @@ namespace LandblockExtraction.LandBlockExtractor {
}
public BlockStruct? GetBlock(int landX, int landY) {
CellId landBlockId = new CellId((byte)landX, (byte)landY, 0xFF, 0xFF);
var landBlock = cellEngine.GetLandBlockData(landBlockId.id);
if (landBlock == null) return null;
CellId landBlockId = new CellId((byte)landX, (byte)landY, 0xFF, 0xFF);
var landBlock = cellEngine.GetLandBlockData(landBlockId.id);
if (landBlock == null) return null;
return GenerateBlockStructByData(landBlock, landX, landY);
return GenerateBlockStructByData(landBlock, landX, landY);
}
public BlockStruct GenerateBlockStructByData(CLandBlockData blockData, int landX, int landY) {
@ -120,6 +119,7 @@ namespace LandblockExtraction.LandBlockExtractor {
//TEST
public void DoubleEdgeVertices(BlockStruct blockStruct) {
List<Vector3> newPositions = new List<Vector3>();
List<Vector3> newNormals = new List<Vector3>();
List<Vector4> newColors = new List<Vector4>();
List<Vector4> newFarColors = new List<Vector4>();
List<Vector2> newTexCoord = new List<Vector2>();
@ -131,7 +131,7 @@ namespace LandblockExtraction.LandBlockExtractor {
// Doubler les sommets sur le bord supérieur et inférieur
for(int i = 0; i < originalIndicesCount; i = i + 6) {
for (int i = 0; i < originalIndicesCount; i = i + 6) {
var one = blockStruct.indices[i + 0];
var two = blockStruct.indices[i + 1];
@ -179,11 +179,22 @@ namespace LandblockExtraction.LandBlockExtractor {
newTexCoord.Add(new(0, 1));
newTexCoord.Add(new(1, 0));
newTexCoord.Add(new(1, 1));
var normal = MathOperations.CalculateQuadNormal(blockStruct.verticesStruct.position[one],
blockStruct.verticesStruct.position[two],
blockStruct.verticesStruct.position[three],
blockStruct.verticesStruct.position[foor]);
newNormals.Add(normal);
newNormals.Add(normal);
newNormals.Add(normal);
newNormals.Add(normal);
}
// Ajouter les nouveaux sommets à la structure BlockStruct (étape 2)
// Vous devez également mettre à jour les indices dans blockStruct.indices
blockStruct.verticesStruct.position = newPositions.ToArray();
blockStruct.verticesStruct.normal = newNormals.ToArray();
blockStruct.verticesStruct.color = newColors.ToArray();
blockStruct.verticesStruct.farcolor = newFarColors.ToArray();
blockStruct.verticesStruct.texturecoord = newTexCoord.ToArray();
@ -195,7 +206,7 @@ namespace LandblockExtraction.LandBlockExtractor {
private int[] GenerateNewsIndices(int count) {
List<int> indices = new List<int>();
for(int i = 0; i < count; i = i + 4) {
for (int i = 0; i < count; i = i + 4) {
indices.Add(i);
indices.Add(i + 1);
indices.Add(i + 2);