// vertices in order: top right, bottom right, bottom left, top left public TerrainVertex(IntVector3 p0, IntVector3 p1, IntVector3 p2, IntVector3 p3, int occ0, int occ1, int occ2, int occ3, FaceTexture tex, byte sliceHack = 0) { // last bytes of positions are unused this.Position0 = new Byte4(p3.X, p3.Y, p3.Z, 0); this.Position1 = new Byte4(p0.X, p0.Y, p0.Z, 0); this.Position2 = new Byte4(p2.X, p2.Y, p2.Z, 0); this.Position3 = new Byte4(p1.X, p1.Y, p1.Z, 0); this.Occlusion = new SByte4(occ3, occ0, occ2, occ1); this.TexPack = new Byte4((byte)0, (byte)tex.Symbol1, (byte)tex.Symbol2, sliceHack); this.ColorPack = new Byte4((byte)tex.Color0, (byte)tex.Color1, (byte)tex.Color2, (byte)0); }
void CreateCube(IntVector3 p, Direction visibleFaces, ref FaceTexture baseTexture, ref FaceTexture topTexture, VertexList <TerrainVertex> vertexList, Direction sliceFaces) { var offset = p - this.ChunkOffset; int sides = (int)visibleFaces; for (int side = 0; side < 6 && sides != 0; ++side, sides >>= 1) { if ((sides & 1) == 0) { continue; } var vertices = s_cubeFaceInfo[side].Vertices; IntVector3 v0, v1, v2, v3; v0 = vertices[0] + offset; v1 = vertices[1] + offset; v2 = vertices[2] + offset; v3 = vertices[3] + offset; Direction dir = (Direction)(1 << side); bool isSliceFace = (sliceFaces & dir) != 0; int occ0, occ1, occ2, occ3; if (isSliceFace) { occ0 = occ1 = occ2 = occ3 = 0; } else { GetOcclusionsForFace(p, (DirectionOrdinal)side, out occ0, out occ1, out occ2, out occ3); } var tex = side == (int)DirectionOrdinal.PositiveZ ? topTexture : baseTexture; byte sliceHack = isSliceFace ? (byte)1 : (byte)0; var vd = new TerrainVertex(v0, v1, v2, v3, occ0, occ1, occ2, occ3, tex, sliceHack); vertexList.Add(vd); } }
void GetTextures(IntVector3 p, ref Voxel vox, out FaceTexture baseTexture, out FaceTexture topTexture, Direction sliceFaces) { var td = m_map.GetTileData(p); baseTexture = new FaceTexture(); topTexture = new FaceTexture(); if (td.IsUndefined) { baseTexture = Chunk.UndefinedFaceTexture; topTexture = baseTexture; return; } if (td.WaterLevel > 0) { baseTexture.Symbol1 = SymbolID.Water; baseTexture.Color0 = GameColor.MediumBlue; baseTexture.Color1 = GameColor.SeaGreen; topTexture = baseTexture; return; } switch (td.ID) { case TileID.NaturalWall: var matInfo = Materials.GetMaterial(td.MaterialID); var color = matInfo.Color; baseTexture.Color0 = GameColor.None; baseTexture.Symbol1 = SymbolID.Wall; baseTexture.Color1 = color; var secondaryMatInfo = Materials.GetMaterial(td.SecondaryMaterialID); switch (secondaryMatInfo.Category) { case MaterialCategory.Gem: baseTexture.Symbol2 = SymbolID.GemOre; baseTexture.Color2 = secondaryMatInfo.Color; break; case MaterialCategory.Mineral: baseTexture.Symbol2 = SymbolID.ValuableOre; baseTexture.Color2 = secondaryMatInfo.Color; break; default: break; } // If the top face of the tile is visible, and it's not the slice level, we have a "floor" if ((sliceFaces & Direction.Up) == 0 && (vox.VisibleFaces & Direction.PositiveZ) != 0) { if (m_map.Contains(p.Up) && m_map.GetTileData(p.Up).IsGreen) { var tdUp = m_map.GetTileData(p.Up); var matInfoUp = Materials.GetMaterial(tdUp.MaterialID); SymbolID symbol; switch (matInfoUp.ID) { case MaterialID.ReedGrass: symbol = SymbolID.Grass4; break; case MaterialID.RyeGrass: symbol = SymbolID.Grass2; break; case MaterialID.MeadowGrass: symbol = SymbolID.Grass3; break; case MaterialID.HairGrass: symbol = SymbolID.Grass; break; default: symbol = SymbolID.Undefined; break; } topTexture.Color0 = GameColor.Green; topTexture.Symbol1 = symbol; topTexture.Color1 = GameColor.Green; } else if (matInfo.Category == MaterialCategory.Soil) { topTexture.Color0 = color; topTexture.Symbol1 = SymbolID.Sand; topTexture.Color1 = color; } else { topTexture.Color0 = color; topTexture.Symbol1 = SymbolID.Floor; topTexture.Color1 = color; } //floorTile.BgColor = GetTerrainBackgroundColor(matInfoDown); } else { topTexture = baseTexture; } return; case TileID.Stairs: baseTexture.Symbol1 = SymbolID.StairsDown; baseTexture.Color1 = GameColor.Red; topTexture = baseTexture; return; default: throw new Exception(); } }
void CreateCube(IntVector3 p, Direction visibleFaces, ref FaceTexture baseTexture, ref FaceTexture topTexture, VertexList<TerrainVertex> vertexList, Direction sliceFaces) { var offset = p - this.ChunkOffset; int sides = (int)visibleFaces; for (int side = 0; side < 6 && sides != 0; ++side, sides >>= 1) { if ((sides & 1) == 0) continue; var vertices = s_cubeFaceInfo[side].Vertices; IntVector3 v0, v1, v2, v3; v0 = vertices[0] + offset; v1 = vertices[1] + offset; v2 = vertices[2] + offset; v3 = vertices[3] + offset; Direction dir = (Direction)(1 << side); bool isSliceFace = (sliceFaces & dir) != 0; int occ0, occ1, occ2, occ3; if (isSliceFace) { occ0 = occ1 = occ2 = occ3 = 0; } else { GetOcclusionsForFace(p, (DirectionOrdinal)side, out occ0, out occ1, out occ2, out occ3); } var tex = side == (int)DirectionOrdinal.PositiveZ ? topTexture : baseTexture; byte sliceHack = isSliceFace ? (byte)1 : (byte)0; var vd = new TerrainVertex(v0, v1, v2, v3, occ0, occ1, occ2, occ3, tex, sliceHack); vertexList.Add(vd); } }
void CreateUndefinedChunk(ref IntGrid3 viewGrid, ref IntGrid3 chunkGrid, VertexList <TerrainVertex> vertexList, Direction visibleChunkFaces) { // Faces that are visible due to viewgrid Direction sliceFaces = GetGridSliceDirections(ref chunkGrid, ref viewGrid) & visibleChunkFaces; // Only faces revealed by viewgrid are visible Direction visibleFaces = sliceFaces; if (visibleFaces == 0) { return; } int sides = (int)visibleFaces; FaceTexture tex = Chunk.UndefinedFaceTexture; const int occlusion = 0; var offset = chunkGrid.Corner1 - this.ChunkOffset; var size = new IntVector3(chunkGrid.Size.Width, chunkGrid.Size.Height, chunkGrid.Size.Depth); // All faces are revealed by viewgrid byte sliceHack = (byte)1; if (Chunk.UseBigUnknownChunk) { /* Note: Using chunk sized quads causes t-junction problems */ for (int side = 0; side < 6 && sides != 0; ++side, sides >>= 1) { if ((sides & 1) == 0) { continue; } var vertices = s_cubeFaceInfo[side].Vertices; IntVector3 v0 = vertices[0] * size + offset; IntVector3 v1 = vertices[1] * size + offset; IntVector3 v2 = vertices[2] * size + offset; IntVector3 v3 = vertices[3] * size + offset; var vd = new TerrainVertex(v0, v1, v2, v3, occlusion, occlusion, occlusion, occlusion, tex, sliceHack); vertexList.Add(vd); } } else { for (int side = 0; side < 6 && sides != 0; ++side, sides >>= 1) { if ((sides & 1) == 0) { continue; } int d0 = side / 2; int d1 = (d0 + 1) % 3; int d2 = (d0 + 2) % 3; bool posFace = (side & 1) == 1; var vertices = s_cubeFaceInfo[side].Vertices; IntVector3 v0 = vertices[0] + offset; IntVector3 v1 = vertices[1] + offset; IntVector3 v2 = vertices[2] + offset; IntVector3 v3 = vertices[3] + offset; var vec1 = new IntVector3(); vec1[d1] = 1; var vec2 = new IntVector3(); vec2[d2] = 1; for (int v = 0; v < size[d1]; ++v) { for (int u = 0; u < size[d2]; ++u) { var off = vec1 * v + vec2 * u; if (posFace) { off[d0] = size[d0] - 1; } var vd = new TerrainVertex(v0 + off, v1 + off, v2 + off, v3 + off, occlusion, occlusion, occlusion, occlusion, tex, sliceHack); vertexList.Add(vd); } } } } }