Add Normal in vertex. And add light in shader.
This commit is contained in:
parent
8908ef1332
commit
0e96615b32
16 changed files with 221 additions and 85 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace LandblockExtraction.LandBlockExtractor {
|
||||
namespace LandblockExtraction.LandBlockExtractor {
|
||||
public class BlockStruct {
|
||||
public readonly static int BlockSize = 17;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace LandblockExtraction.LandBlockExtractor {
|
||||
public class VerticesStruct {
|
||||
public Vector3[] position { get; set; }
|
||||
public Vector3[] normal { get; set; }
|
||||
public Vector4[] color { get; set; }
|
||||
public Vector4[] farcolor { get; set; }
|
||||
public Vector2[] texturecoord { get; set; }
|
||||
|
|
@ -11,6 +12,7 @@ namespace LandblockExtraction.LandBlockExtractor {
|
|||
|
||||
public VerticesStruct(int blockSize) {
|
||||
position = new Vector3[blockSize * blockSize];
|
||||
normal = new Vector3[blockSize * blockSize];
|
||||
color = new Vector4[blockSize * blockSize];
|
||||
farcolor = new Vector4[blockSize * blockSize];
|
||||
texturecoord = new Vector2[blockSize * blockSize];
|
||||
|
|
@ -20,26 +22,29 @@ namespace LandblockExtraction.LandBlockExtractor {
|
|||
|
||||
public float[] Vertices() {
|
||||
int length = position.Length;
|
||||
float[] vertices = new float[length * 18]; // 3 pour position, 4 pour color, et 4 pour farcolor
|
||||
for (int i = 0, vi = 0; i < length; i++, vi += 18) {
|
||||
float[] vertices = new float[length * 21]; // 3 pour position, 4 pour color, et 4 pour farcolor
|
||||
for (int i = 0, vi = 0; i < length; i++, vi += 21) {
|
||||
vertices[vi] = position[i].X;
|
||||
vertices[vi + 1] = position[i].Y;
|
||||
vertices[vi + 2] = position[i].Z;
|
||||
vertices[vi + 3] = color[i].X;
|
||||
vertices[vi + 4] = color[i].Y;
|
||||
vertices[vi + 5] = color[i].Z;
|
||||
vertices[vi + 6] = color[i].W;
|
||||
vertices[vi + 7] = farcolor[i].X;
|
||||
vertices[vi + 8] = farcolor[i].Y;
|
||||
vertices[vi + 9] = farcolor[i].Z;
|
||||
vertices[vi + 10] = farcolor[i].W;
|
||||
vertices[vi + 11] = texturecoord[i].X;
|
||||
vertices[vi + 12] = texturecoord[i].Y;
|
||||
vertices[vi + 13] = terraintype[i].X;
|
||||
vertices[vi + 14] = terraintype[i].Y;
|
||||
vertices[vi + 15] = terraintype[i].Z;
|
||||
vertices[vi + 16] = terraintype[i].W;
|
||||
vertices[vi + 17] = realtype[i];
|
||||
vertices[vi + 3] = normal[i].X;
|
||||
vertices[vi + 4] = normal[i].Y;
|
||||
vertices[vi + 5] = normal[i].Z;
|
||||
vertices[vi + 6] = color[i].X;
|
||||
vertices[vi + 7] = color[i].Y;
|
||||
vertices[vi + 8] = color[i].Z;
|
||||
vertices[vi + 9] = color[i].W;
|
||||
vertices[vi + 10] = farcolor[i].X;
|
||||
vertices[vi + 11] = farcolor[i].Y;
|
||||
vertices[vi + 12] = farcolor[i].Z;
|
||||
vertices[vi + 13] = farcolor[i].W;
|
||||
vertices[vi + 14] = texturecoord[i].X;
|
||||
vertices[vi + 15] = texturecoord[i].Y;
|
||||
vertices[vi + 16] = terraintype[i].X;
|
||||
vertices[vi + 17] = terraintype[i].Y;
|
||||
vertices[vi + 18] = terraintype[i].Z;
|
||||
vertices[vi + 19] = terraintype[i].W;
|
||||
vertices[vi + 20] = realtype[i];
|
||||
}
|
||||
return vertices;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue