void DrawParts(bool sprite) { if (sprite) { SpriteXQuad(false, false); SpriteXQuad(false, true); SpriteZQuad(false, false); SpriteZQuad(false, true); SpriteZQuad(true, false); SpriteZQuad(true, true); SpriteXQuad(true, false); SpriteXQuad(true, true); } else { drawer.minBB = BlockInfo.MinBB[block]; drawer.minBB.Y = 1 - drawer.minBB.Y; drawer.maxBB = BlockInfo.MaxBB[block]; drawer.maxBB.Y = 1 - drawer.maxBB.Y; Vector3 min = BlockInfo.RenderMinBB[block]; Vector3 max = BlockInfo.RenderMaxBB[block]; drawer.x1 = min.X - 0.5f; drawer.y1 = min.Y; drawer.z1 = min.Z - 0.5f; drawer.x2 = max.X - 0.5f; drawer.y2 = max.Y; drawer.z2 = max.Z - 0.5f; drawer.Tinted = BlockInfo.Tinted[block]; drawer.TintCol = BlockInfo.FogCol[block]; drawer.Bottom(1, cols[1], GetTex(Side.Bottom), cache.vertices, ref index); drawer.Front(1, cols[3], GetTex(Side.Front), cache.vertices, ref index); drawer.Right(1, cols[5], GetTex(Side.Right), cache.vertices, ref index); drawer.Back(1, cols[2], GetTex(Side.Back), cache.vertices, ref index); drawer.Left(1, cols[4], GetTex(Side.Left), cache.vertices, ref index); drawer.Top(1, cols[0], GetTex(Side.Top), cache.vertices, ref index); } }
protected override void RenderTile(int index) { if (BlockInfo.Draw[curBlock] == DrawType.Sprite) { this.fullBright = BlockInfo.FullBright[curBlock]; this.tinted = BlockInfo.Tinted[curBlock]; int count = counts[index + Side.Top]; if (count != 0) { DrawSprite(count); } return; } int leftCount = counts[index++], rightCount = counts[index++], frontCount = counts[index++], backCount = counts[index++], bottomCount = counts[index++], topCount = counts[index++]; if (leftCount == 0 && rightCount == 0 && frontCount == 0 && backCount == 0 && bottomCount == 0 && topCount == 0) { return; } bool fullBright = BlockInfo.FullBright[curBlock]; bool isTranslucent = BlockInfo.Draw[curBlock] == DrawType.Translucent; int lightFlags = BlockInfo.LightOffset[curBlock]; drawer.minBB = BlockInfo.MinBB[curBlock]; drawer.minBB.Y = 1 - drawer.minBB.Y; drawer.maxBB = BlockInfo.MaxBB[curBlock]; drawer.maxBB.Y = 1 - drawer.maxBB.Y; Vector3 min = BlockInfo.RenderMinBB[curBlock], max = BlockInfo.RenderMaxBB[curBlock]; drawer.x1 = X + min.X; drawer.y1 = Y + min.Y; drawer.z1 = Z + min.Z; drawer.x2 = X + max.X; drawer.y2 = Y + max.Y; drawer.z2 = Z + max.Z; drawer.Tinted = BlockInfo.Tinted[curBlock]; drawer.TintCol = BlockInfo.FogCol[curBlock]; if (leftCount != 0) { int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Left]; texLoc += Z % Core.RepeatX[curBlock]; texLoc += 16 * ((Y + 1) % Core.RepeatY[curBlock]); int i = texLoc >> Atlas1D.Shift; int offset = (lightFlags >> Side.Left) & 1; DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i]; PackedCol col = fullBright ? PackedCol.White : X >= offset?light.LightCol_XSide_Fast(X - offset, Y, Z) : light.OutsideXSide; drawer.Left(leftCount, col, texLoc, vertices, ref part.vIndex[Side.Left]); } if (rightCount != 0) { int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Right]; texLoc += (Z + 1) % Core.RepeatX[curBlock]; texLoc += 16 * ((Y + 1) % Core.RepeatY[curBlock]); int i = texLoc >> Atlas1D.Shift; int offset = (lightFlags >> Side.Right) & 1; DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i]; PackedCol col = fullBright ? PackedCol.White : X <= (maxX - offset) ? light.LightCol_XSide_Fast(X + offset, Y, Z) : light.OutsideXSide; drawer.Right(rightCount, col, texLoc, vertices, ref part.vIndex[Side.Right]); } if (frontCount != 0) { int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Front]; texLoc += (X + 1) % Core.RepeatX[curBlock]; texLoc += 16 * ((Y + 1) % Core.RepeatY[curBlock]); int i = texLoc >> Atlas1D.Shift; int offset = (lightFlags >> Side.Front) & 1; DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i]; PackedCol col = fullBright ? PackedCol.White : Z >= offset?light.LightCol_ZSide_Fast(X, Y, Z - offset) : light.OutsideZSide; drawer.Front(frontCount, col, texLoc, vertices, ref part.vIndex[Side.Front]); } if (backCount != 0) { int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Back]; texLoc += X % Core.RepeatX[curBlock]; texLoc += 16 * ((Y + 1) % Core.RepeatY[curBlock]); int i = texLoc >> Atlas1D.Shift; int offset = (lightFlags >> Side.Back) & 1; DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i]; PackedCol col = fullBright ? PackedCol.White : Z <= (maxZ - offset) ? light.LightCol_ZSide_Fast(X, Y, Z + offset) : light.OutsideZSide; drawer.Back(backCount, col, texLoc, vertices, ref part.vIndex[Side.Back]); } if (bottomCount != 0) { int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Bottom]; texLoc += X % Core.RepeatX[curBlock]; texLoc += 16 * (Z % Core.RepeatY[curBlock]); int i = texLoc >> Atlas1D.Shift; int offset = (lightFlags >> Side.Bottom) & 1; DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i]; PackedCol col = fullBright ? PackedCol.White : light.LightCol_YBottom_Fast(X, Y - offset, Z); drawer.Bottom(bottomCount, col, texLoc, vertices, ref part.vIndex[Side.Bottom]); } if (topCount != 0) { int texLoc = BlockInfo.textures[curBlock * Side.Sides + Side.Top]; texLoc += X % Core.RepeatX[curBlock]; texLoc += 16 * (Z % Core.RepeatY[curBlock]); int i = texLoc >> Atlas1D.Shift; int offset = (lightFlags >> Side.Top) & 1; DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i]; PackedCol col = fullBright ? PackedCol.White : light.LightCol_YTop_Fast(X, (Y + 1) - offset, Z); drawer.Top(topCount, col, texLoc, vertices, ref part.vIndex[Side.Top]); } }
private void DrawBlockTransform(Entity p, float dispX, float dispY, float dispZ, float scale) { int lastTexIndex = -1; bool sprite = BlockInfo.Draw[p.ModelBlock] == DrawType.Sprite; if (sprite) { SpriteXQuad(false, false, p.ModelBlock, ref lastTexIndex, game.ModelCache, dispX, dispY, dispZ, scale); SpriteXQuad(false, true, p.ModelBlock, ref lastTexIndex, game.ModelCache, dispX, dispY, dispZ, scale); SpriteZQuad(false, false, p.ModelBlock, ref lastTexIndex, game.ModelCache, dispX, dispY, dispZ, scale); SpriteZQuad(false, true, p.ModelBlock, ref lastTexIndex, game.ModelCache, dispX, dispY, dispZ, scale); SpriteZQuad(true, false, p.ModelBlock, ref lastTexIndex, game.ModelCache, dispX, dispY, dispZ, scale); SpriteZQuad(true, true, p.ModelBlock, ref lastTexIndex, game.ModelCache, dispX, dispY, dispZ, scale); SpriteXQuad(true, false, p.ModelBlock, ref lastTexIndex, game.ModelCache, dispX, dispY, dispZ, scale); SpriteXQuad(true, true, p.ModelBlock, ref lastTexIndex, game.ModelCache, dispX, dispY, dispZ, scale); } else { CuboidDrawer drawer = new CuboidDrawer(); drawer.minBB = BlockInfo.MinBB[p.ModelBlock]; drawer.minBB.Y = 1 - drawer.minBB.Y; drawer.maxBB = BlockInfo.MaxBB[p.ModelBlock]; drawer.maxBB.Y = 1 - drawer.maxBB.Y; Vector3 min = BlockInfo.RenderMinBB[p.ModelBlock]; Vector3 max = BlockInfo.RenderMaxBB[p.ModelBlock]; drawer.x1 = (min.X - 0.5f) * scale + dispX; drawer.y1 = min.Y * scale + dispY; drawer.z1 = (min.Z - 0.5f) * scale + dispZ; drawer.x2 = (max.X - 0.5f) * scale + dispX; drawer.y2 = max.Y * scale + dispY; drawer.z2 = (max.Z - 0.5f) * scale + dispZ; drawer.Tinted = BlockInfo.Tinted[p.ModelBlock]; drawer.TintCol = BlockInfo.FogCol[p.ModelBlock]; drawer.Bottom(1, cols[1], GetTex(Side.Bottom, p.ModelBlock, ref lastTexIndex), game.ModelCache.vertices, ref index); drawer.Front(1, cols[3], GetTex(Side.Front, p.ModelBlock, ref lastTexIndex), game.ModelCache.vertices, ref index); drawer.Right(1, cols[5], GetTex(Side.Right, p.ModelBlock, ref lastTexIndex), game.ModelCache.vertices, ref index); drawer.Back(1, cols[2], GetTex(Side.Back, p.ModelBlock, ref lastTexIndex), game.ModelCache.vertices, ref index); drawer.Left(1, cols[4], GetTex(Side.Left, p.ModelBlock, ref lastTexIndex), game.ModelCache.vertices, ref index); drawer.Top(1, cols[0], GetTex(Side.Top, p.ModelBlock, ref lastTexIndex), game.ModelCache.vertices, ref index); } if (index == 0) { return; } if (sprite) { game.Graphics.FaceCulling = true; } lastTexIndex = texIndex; if (lastTexIndex != -1) { game.Graphics.BindTexture(Atlas1D.TexIds[lastTexIndex]); UpdateVB(); } lastTexIndex = texIndex; index = 0; if (sprite) { game.Graphics.FaceCulling = false; } }
void DrawParts(bool sprite) { // SwitchOrder is needed for held block, which renders without depth testing if (sprite) { if (SwitchOrder) { SpriteZQuad(Side.Back, false); SpriteXQuad(Side.Right, false); } else { SpriteXQuad(Side.Right, false); SpriteZQuad(Side.Back, false); } if (SwitchOrder) { SpriteXQuad(Side.Right, true); SpriteZQuad(Side.Back, true); } else { SpriteZQuad(Side.Back, true); SpriteXQuad(Side.Right, true); } } else { drawer.elementsPerAtlas1D = atlas.elementsPerAtlas1D; drawer.invVerElementSize = atlas.invElementSize; drawer.minBB = game.BlockInfo.MinBB[block]; drawer.minBB.Y = 1 - drawer.minBB.Y; drawer.maxBB = game.BlockInfo.MaxBB[block]; drawer.maxBB.Y = 1 - drawer.maxBB.Y; Vector3 min = game.BlockInfo.RenderMinBB[block]; Vector3 max = game.BlockInfo.RenderMaxBB[block]; drawer.x1 = min.X - 0.5f; drawer.y1 = min.Y; drawer.z1 = min.Z - 0.5f; drawer.x2 = max.X - 0.5f; drawer.y2 = max.Y; drawer.z2 = max.Z - 0.5f; drawer.Tinted = game.BlockInfo.Tinted[block]; drawer.TintColour = game.BlockInfo.FogColour[block]; drawer.Bottom(1, Colour(FastColour.ShadeYBottom), GetTex(Side.Bottom), cache.vertices, ref index); if (SwitchOrder) { drawer.Right(1, Colour(FastColour.ShadeX), GetTex(Side.Right), cache.vertices, ref index); drawer.Back(1, Colour(FastColour.ShadeZ), GetTex(Side.Back), cache.vertices, ref index); drawer.Left(1, Colour(FastColour.ShadeX), GetTex(Side.Left), cache.vertices, ref index); drawer.Front(1, Colour(FastColour.ShadeZ), GetTex(Side.Front), cache.vertices, ref index); } else { drawer.Front(1, Colour(FastColour.ShadeZ), GetTex(Side.Front), cache.vertices, ref index); drawer.Right(1, Colour(FastColour.ShadeX), GetTex(Side.Right), cache.vertices, ref index); drawer.Back(1, Colour(FastColour.ShadeZ), GetTex(Side.Back), cache.vertices, ref index); drawer.Left(1, Colour(FastColour.ShadeX), GetTex(Side.Left), cache.vertices, ref index); } drawer.Top(1, Colour(1.0f), GetTex(Side.Top), cache.vertices, ref index); } }