Final version of this Renderer, will improve upon it in the next prototype

This commit is contained in:
Halbear
2026-02-19 18:06:18 +00:00
parent 70acbd2526
commit eb4b979843
3 changed files with 41 additions and 29 deletions

View File

@@ -12,11 +12,12 @@ namespace VoxelIsometricRenderer
public static class PlayerObject
{
static int BlockID = 0;
static int VoxelID = 0;
static float PositionX = 0;
static float PositionY = 0;
static float PositionZ = 0;
static int BlockposX = 5;
static int BlockposY = 17;
static int BlockposY = 16;
static int BlockposZ =5;
static float PrecisePositionX = 0.0f;
static float PrecisePositionY = 0.0f;
@@ -24,10 +25,14 @@ namespace VoxelIsometricRenderer
static Rectangle CameraCentre = new Rectangle(0,0,100,100);
static int[] LastPositions = new int[] { 0, -192 };
static Rectangle PlayerPosition = new Rectangle(0,0,100,100);
public static int GetVoxelID()
{
return VoxelID;
}
public static void Draw(Graphics g)
{
Chunk PlayerChunk = ChunkRegistry.FetchChunk(String.Format("x={0};y={1};z={2}", (int)Math.Floor(BlockposX / (double)ChunkRegistry.FetchDimensions()[0]), (int)Math.Floor(BlockposY / (double)ChunkRegistry.FetchDimensions()[1]), (int)Math.Floor(BlockposZ / (double)ChunkRegistry.FetchDimensions()[2])));
BlockRegistry.RenderBlock(g,BlockID, BlockposX, BlockposY, BlockposZ, PlayerChunk != null ? PlayerChunk.SkyLightHeightMap[Math.Min(BlockposX - (PlayerChunk.ChunkPos[0] * ChunkRegistry.FetchDimensions()[0]) + 1, PlayerChunk.SkyLightHeightMap.GetLength(0) - 1), Math.Min(BlockposY - (PlayerChunk.ChunkPos[1] * ChunkRegistry.FetchDimensions()[1]) + 1, ChunkRegistry.FetchDimensions()[1] - 1), Math.Max(BlockposZ - (PlayerChunk.ChunkPos[2] * ChunkRegistry.FetchDimensions()[2]) - 1, 0)] : 1);
BlockRegistry.RenderBlock(g, BlockID, BlockposX, BlockposY, BlockposZ, PlayerChunk != null ? PlayerChunk.SkyLightHeightMap[Math.Max(BlockposX - (PlayerChunk.ChunkPos[0] * ChunkRegistry.FetchDimensions()[0]), 0), Math.Max(BlockposY - (PlayerChunk.ChunkPos[1] * ChunkRegistry.FetchDimensions()[1]), 0), Math.Max(BlockposZ - (PlayerChunk.ChunkPos[2] * ChunkRegistry.FetchDimensions()[2]), 0)] : 1);
int[] Positions = BlockRegistry.GetDrawLocation(BlockposX, BlockposY, BlockposZ, PositionX, PositionY, PositionZ);
if (Positions[0] != LastPositions[0] || Positions[1] != LastPositions[1])
{
@@ -117,6 +122,7 @@ namespace VoxelIsometricRenderer
{
index = VoxelRegistry.IndexVoxel(voxel);
}
VoxelID = index;
Block newBlock = new Block(index, BlockstateRegistry.GetBlockstateIndex(blockState), -1);
int x = BlockposX;
int y = BlockposY;

View File

@@ -59,8 +59,9 @@ namespace VoxelIsometricRenderer
PlayerObject.CreatePlayer(new int[] { 0, 0, 0, 0, 0, 0 }, 0, new BlockState(false, BlockType.Ground, false));
Chunk TestChunk = ChunkRegistry.IndexChunk(0, 0, 0);
Chunk TestChunk2 = ChunkRegistry.IndexChunk(0, 1, 0);
//Chunk TestChunk3 = ChunkRegistry.IndexChunk(0, 0, -1);
//Chunk TestChunk4 = ChunkRegistry.IndexChunk(0, 1, -1);
Chunk TestChunk3 = ChunkRegistry.IndexChunk(0, 0, -1);
Chunk TestChunk4 = ChunkRegistry.IndexChunk(-1, 0, -1);
Chunk TestChunk5 = ChunkRegistry.IndexChunk(-1, 0, 0);
Random rnd = new Random();
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
@@ -72,30 +73,33 @@ namespace VoxelIsometricRenderer
TestChunk2.CreateBlock(new int[] { 5,5,5,5,6,6 }, 0, new BlockState(false, BlockType.Ground, true), i, j, k);
}
else TestChunk2.CreateAir(i, j, k);
if (i < 8 && k < 8 && rnd.Next(0,1)==0) TestChunk.CreateBlock(new int[] { rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13) }, 0, new BlockState(false, BlockType.Ground, true), i, j, k);
if (LightSource.IsWithinSphere(8, 4, 8, 4, i, j, k)) TestChunk.CreateBlock(new int[] { rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13) }, 0, new BlockState(false, BlockType.Ground, true), i, j, k);
else TestChunk.CreateAir(i, j, k);
//if (LightSource.IsWithinSphere(7,8,8,8,i,j,k)) TestChunk4.CreateBlock(new int[] { rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13) }, 0, new BlockState(false, BlockType.Ground, true), i, j, k);
//else TestChunk4.CreateAir(i, j, k);
//if (j == 15) TestChunk3.CreateBlock(new int[] {1,1,1,1,2,2 }, 0, new BlockState(false, BlockType.Ground, true), i, j, k);
//else TestChunk3.CreateAir(i, j, k);
if (LightSource.IsWithinSphere(8, 4, 8, 20, i, j, k)) TestChunk3.CreateBlock(new int[] { rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13) }, 0, new BlockState(false, BlockType.Ground, true), i, j, k);
else TestChunk3.CreateAir(i, j, k);
if (LightSource.IsWithinSphere(8, 20, 8, 20, i, j, k)) TestChunk4.CreateBlock(new int[] { rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13) }, 0, new BlockState(false, BlockType.Ground, true), i, j, k);
else TestChunk4.CreateAir(i, j, k);
if (LightSource.IsWithinSphere(8, 20, 8, 4, i, j, k)) TestChunk5.CreateBlock(new int[] { rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13) }, 0, new BlockState(false, BlockType.Ground, true), i, j, k);
else TestChunk5.CreateAir(i, j, k);
}
}
}
//LightingManager.Lights.Add(new LightSource(LightShape.Sphere,7,7,7, 6, 14, 7, new float[] {0.8f,0.8f,0.0f}, 255));
//LightingManager.Lights.Add(new LightSource(LightShape.Sphere, 15, 15, 15, 7,18,7, new float[] {1.8f,0.0f,0.0f},255));
//LightingManager.Lights.Add(new LightSource(LightShape.Sphere,15,15,15, 3, 8, 15, new float[] {0.0f,1.8f,0.0f},255));
LightingManager.Lights.Add(new LightSource(LightShape.Sphere,12,12,12, 10, 18, 10, new float[] {0.0f,0.0f,1.8f}, 255));
LightingManager.Lights.Add(new LightSource(LightShape.Sphere, 7, 7, 7, 4,18,4, new float[] {1.8f,0.0f,0.0f},255));
LightingManager.Lights.Add(new LightSource(LightShape.Sphere,9,9,9, 12, 18, 12, new float[] {0.0f,0.0f,1.8f}, 255));
LightingManager.Lights.Add(new LightSource(LightShape.Sphere, 8, 8, 8, 4,18,4, new float[] {1.8f,0.0f,0.0f},255));
TestChunk2.GenerateLightMap();
//TestChunk4.GenerateLightMap();
// TestChunk3.GenerateLightMap();
TestChunk4.GenerateLightMap();
TestChunk5.GenerateLightMap();
TestChunk3.GenerateLightMap();
TestChunk.GenerateLightMap();
TestChunk.CalculateCull();
//ChunksToRender.Add(2);
//ChunksToRender.Add(3);
TestChunk3.CalculateCull();
TestChunk4.CalculateCull();
TestChunk5.CalculateCull();
ChunksToRender.Add(2);
ChunksToRender.Add(3);
ChunksToRender.Add(4);
ChunksToRender.Add(0);
ChunksToRender.Add(1);
//TestChunk2.CalculateCull();
MainThread = new Thread(Runtime);
MainThread.SetApartmentState(ApartmentState.STA);
MainThread.Start();

View File

@@ -211,7 +211,7 @@ namespace VoxelIsometricRenderer
// MessageBox.Show(LightLevel + "");
}
}
return LightLevel;
return LightLevel > 0 ? LightLevel : 1;
}
public static bool IsWithinCircle(int Radius, int CentreX, int CentreY, int posX, int PosY)
{
@@ -256,7 +256,7 @@ namespace VoxelIsometricRenderer
}
}
TotalLightLevel /= Dimensions;
return (byte)Math.Min(Math.Max(TotalLightLevel,0),255);
return (byte)Math.Min(Math.Max(TotalLightLevel,1),255);
}
private void SetUpLightLevels()
{
@@ -474,7 +474,7 @@ namespace VoxelIsometricRenderer
new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face, Lights), 0, 0, 0}, // green
new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face, Lights), 0, 0}, // blue
new float[] {0, 0, 0, 1, 0}, // alpha
new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2
new float[] {0, 0, 0, 0, 1}};
colorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes = new ImageAttributes();
@@ -486,7 +486,7 @@ namespace VoxelIsometricRenderer
new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face, Lights), 0, 0, 0}, // green
new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face, Lights), 0, 0}, // blue
new float[] {0, 0, 0, 1, 0}, // alpha
new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2
new float[] {0, 0, 0, 0, 1}};
colorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes = new ImageAttributes();
@@ -498,7 +498,7 @@ namespace VoxelIsometricRenderer
new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face, Lights), 0, 0, 0}, // green
new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face, Lights), 0, 0}, // blue
new float[] {0, 0, 0, 1, 0}, // alpha
new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2
new float[] {0, 0, 0, 0, 1}};
colorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes = new ImageAttributes();
@@ -510,7 +510,7 @@ namespace VoxelIsometricRenderer
new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face, Lights), 0, 0, 0}, // green
new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face, Lights), 0, 0}, // blue
new float[] {0, 0, 0, 1, 0}, // alpha
new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2
new float[] {0, 0, 0, 0, 1}};
colorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes = new ImageAttributes();
@@ -522,7 +522,7 @@ namespace VoxelIsometricRenderer
new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face, Lights), 0, 0, 0}, // green
new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face, Lights), 0, 0}, // blue
new float[] {0, 0, 0, 1, 0}, // alpha
new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2
new float[] {0, 0, 0, 0, 1}};
colorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes = new ImageAttributes();
@@ -534,7 +534,7 @@ namespace VoxelIsometricRenderer
new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face, Lights), 0, 0, 0}, // green
new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face, Lights), 0, 0}, // blue
new float[] {0, 0, 0, 1, 0}, // alpha
new float[] {0, 0, -0, 0, 1}}; // three translations of 0.2
new float[] {0, 0, -0, 0, 1}};
colorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes = new ImageAttributes();
@@ -1088,6 +1088,7 @@ namespace VoxelIsometricRenderer
{
if (BlockReg[x, y, z] != -1 && Culled[x, y, z] == false)
{
if (SkyLightHeightMap[x, y, z] == 0 ) SkyLightHeightMap[x, y, z] = 255;
BlockRegistry.RenderBlock(g, BlockReg[x, y, z], x + ChunkPos[0] * ChunkRegistry.FetchDimensions()[0], y + ChunkPos[1] * ChunkRegistry.FetchDimensions()[1], z + ChunkPos[2] * ChunkRegistry.FetchDimensions()[2], SkyLightHeightMap[x, y, z]);
}
}
@@ -1098,7 +1099,8 @@ namespace VoxelIsometricRenderer
{
for (int i = 0; i < DrawList.Count; i++)
{
BlockRegistry.RenderBlock(g, DrawList[i], DrawPositions[i][0] + ChunkPos[0] * ChunkRegistry.FetchDimensions()[0], DrawPositions[i][1] + ChunkPos[1] * ChunkRegistry.FetchDimensions()[1], DrawPositions[i][2] + ChunkPos[1] * ChunkRegistry.FetchDimensions()[1], SkyLightHeightMap[DrawPositions[i][0], DrawPositions[i][1], DrawPositions[i][2]]);
if (SkyLightHeightMap[DrawPositions[i][0], DrawPositions[i][1], DrawPositions[i][2]] == 0 ) SkyLightHeightMap[DrawPositions[i][0], DrawPositions[i][1], DrawPositions[i][2]] = 255;
BlockRegistry.RenderBlock(g, DrawList[i], DrawPositions[i][0] + ChunkPos[0] * ChunkRegistry.FetchDimensions()[0], DrawPositions[i][1] + ChunkPos[1] * ChunkRegistry.FetchDimensions()[1], DrawPositions[i][2] + ChunkPos[2] * ChunkRegistry.FetchDimensions()[2], SkyLightHeightMap[DrawPositions[i][0], DrawPositions[i][1], DrawPositions[i][2]]);
}
}
}