Esempio n. 1
0
        void BlockCompressLocalTile(ref RawTexContainer layer, uint tileIdx)
        {
            uint tileSizeInBlocks0 = mlmask._atlasTileSize / 4;

            uint tx = (tileIdx % layer._widthInTiles0);
            uint ty = (tileIdx / layer._widthInTiles0);

            var layerTile = layer.tiles[Convert.ToInt32(tileIdx)];

            layerTile._atlasBlockCompressed = new UInt64[(tileSizeInBlocks0 * tileSizeInBlocks0)];

            for (uint yBlock = 0; yBlock < tileSizeInBlocks0; yBlock++)
            {
                for (uint xBlock = 0; xBlock < tileSizeInBlocks0; xBlock++)
                {
                    List <float> referenceData = new List <float>();
                    float[]      toBBCValues   = new float[16];

                    for (uint j = 0; j < 4; j++)
                    {
                        for (uint i = 0; i < 4; i++)
                        {
                            uint  px = xBlock * 4 + i;
                            uint  py = yBlock * 4 + j;
                            float v  = Convert.ToSingle(layerTile._atlasUnCompressed[px + py * mlmask._atlasTileSize]) / 255.0f;
                            toBBCValues[i + j * 4] = v;
                            referenceData.Add(v);
                        }
                    }

                    if ((tx > 0) && (xBlock == 0))
                    {
                        PushBlockReferenceData(ref referenceData, layer, tx - 1, ty, tileSizeInBlocks0 - 1, yBlock);
                    }
                    else if ((tx < layer._widthInTiles0 - 1) && (xBlock == tileSizeInBlocks0 - 1))
                    {
                        PushBlockReferenceData(ref referenceData, layer, tx + 1, ty, 0, yBlock);
                    }

                    if ((ty > 0) && (yBlock == 0))
                    {
                        PushBlockReferenceData(ref referenceData, layer, tx, ty - 1, xBlock, tileSizeInBlocks0 - 1);
                    }
                    else if ((ty < layer._heightInTiles0 - 1) && (yBlock == tileSizeInBlocks0 - 1))
                    {
                        PushBlockReferenceData(ref referenceData, layer, tx, ty + 1, xBlock, 0);
                    }

                    if (((tx > 0) && (xBlock == 0)) && ((ty > 0) && (yBlock == 0)))
                    {
                        PushBlockReferenceData(ref referenceData, layer, tx - 1, ty - 1, tileSizeInBlocks0 - 1, tileSizeInBlocks0 - 1);
                    }
                    else if (((tx < layer._widthInTiles0 - 1) && (xBlock == tileSizeInBlocks0 - 1)) && ((ty > 0) && (yBlock == 0)))
                    {
                        PushBlockReferenceData(ref referenceData, layer, tx + 1, ty - 1, 0, tileSizeInBlocks0 - 1);
                    }
                    else if (((tx > 0) && (xBlock == 0)) && ((ty < layer._heightInTiles0 - 1) && (yBlock == tileSizeInBlocks0 - 1)))
                    {
                        PushBlockReferenceData(ref referenceData, layer, tx - 1, ty + 1, tileSizeInBlocks0 - 1, 0);
                    }
                    else if (((tx < layer._widthInTiles0 - 1) && (xBlock == tileSizeInBlocks0 - 1)) && ((ty < layer._heightInTiles0 - 1) && (yBlock == tileSizeInBlocks0 - 1)))
                    {
                        PushBlockReferenceData(ref referenceData, layer, tx + 1, ty + 1, 0, 0);
                    }

                    UInt64 blockCompressed = 0;
                    D3DX.D3DXEncodeBC4U(ref blockCompressed, toBBCValues, referenceData);

                    layerTile._atlasBlockCompressed[xBlock + yBlock * tileSizeInBlocks0] = blockCompressed;
                }
            }

            layer.tiles[Convert.ToInt32(tileIdx)] = layerTile;
        }
        private void BlockCompressLocalTile(ref RawTexContainer layer, uint tileIdx)
        {
            var tileSizeInBlocks0 = _mlmask.AtlasTileSize / 4;

            var tx = tileIdx % layer.WidthInTiles0;
            var ty = tileIdx / layer.WidthInTiles0;

            var layerTile = layer.Tiles[Convert.ToInt32(tileIdx)];

            layerTile.AtlasBlockCompressed = new ulong[tileSizeInBlocks0 * tileSizeInBlocks0];

            for (uint yBlock = 0; yBlock < tileSizeInBlocks0; yBlock++)
            {
                for (uint xBlock = 0; xBlock < tileSizeInBlocks0; xBlock++)
                {
                    var referenceData = new List <float>();
                    var toBBCValues   = new float[16];

                    for (uint j = 0; j < 4; j++)
                    {
                        for (uint i = 0; i < 4; i++)
                        {
                            var px = (xBlock * 4) + i;
                            var py = (yBlock * 4) + j;
                            var v  = Convert.ToSingle(layerTile.AtlasUnCompressed[px + (py * _mlmask.AtlasTileSize)]) / 255.0f;
                            toBBCValues[i + (j * 4)] = v;
                            referenceData.Add(v);
                        }
                    }

                    if (tx > 0 && xBlock == 0)
                    {
                        PushBlockReferenceData(ref referenceData, layer, tx - 1, ty, tileSizeInBlocks0 - 1, yBlock);
                    }
                    else if (tx < layer.WidthInTiles0 - 1 && xBlock == tileSizeInBlocks0 - 1)
                    {
                        PushBlockReferenceData(ref referenceData, layer, tx + 1, ty, 0, yBlock);
                    }

                    if (ty > 0 && yBlock == 0)
                    {
                        PushBlockReferenceData(ref referenceData, layer, tx, ty - 1, xBlock, tileSizeInBlocks0 - 1);
                    }
                    else if (ty < layer.HeightInTiles0 - 1 && yBlock == tileSizeInBlocks0 - 1)
                    {
                        PushBlockReferenceData(ref referenceData, layer, tx, ty + 1, xBlock, 0);
                    }

                    if (tx > 0 && xBlock == 0 && ty > 0 && yBlock == 0)
                    {
                        PushBlockReferenceData(ref referenceData, layer, tx - 1, ty - 1, tileSizeInBlocks0 - 1, tileSizeInBlocks0 - 1);
                    }
                    else if (tx < layer.WidthInTiles0 - 1 && xBlock == tileSizeInBlocks0 - 1 && ty > 0 && yBlock == 0)
                    {
                        PushBlockReferenceData(ref referenceData, layer, tx + 1, ty - 1, 0, tileSizeInBlocks0 - 1);
                    }
                    else if (tx > 0 && xBlock == 0 && ty < layer.HeightInTiles0 - 1 && yBlock == tileSizeInBlocks0 - 1)
                    {
                        PushBlockReferenceData(ref referenceData, layer, tx - 1, ty + 1, tileSizeInBlocks0 - 1, 0);
                    }
                    else if (tx < layer.WidthInTiles0 - 1 && xBlock == tileSizeInBlocks0 - 1 && ty < layer.HeightInTiles0 - 1 && yBlock == tileSizeInBlocks0 - 1)
                    {
                        PushBlockReferenceData(ref referenceData, layer, tx + 1, ty + 1, 0, 0);
                    }

                    ulong blockCompressed = 0;
                    D3DX.D3DXEncodeBC4U(ref blockCompressed, toBBCValues, referenceData);

                    layerTile.AtlasBlockCompressed[xBlock + (yBlock * tileSizeInBlocks0)] = blockCompressed;
                }
            }

            layer.Tiles[Convert.ToInt32(tileIdx)] = layerTile;
        }