예제 #1
0
        private void SaveTexture(crVTMapEntry textureToExport, String FileName, crVTPage vtPage)
        {
            Properties.Settings.Default.LastExportDirectory = Path.GetDirectoryName(FileName);
            Properties.Settings.Default.Save();

            var         fileType  = Path.GetExtension(FileName).ToUpper();
            ImageFormat imgFormat = ImageFormat.Png;

            if (fileType == ".TGA")
            {
                vtPage.SaveTexture(textureToExport, FileName, false, true, false, ImageFormat.Png);
            }
            else if (fileType == ".TDX")
            {
                vtPage.SaveTexture(textureToExport, FileName, true, false, false, ImageFormat.Png);
            }
            else
            {
                switch (fileType)
                {
                case ".JPG":
                    imgFormat = ImageFormat.Jpeg;
                    break;

                case ".JPEG":
                    imgFormat = ImageFormat.Jpeg;
                    break;

                case ".TIFF":
                    imgFormat = ImageFormat.Tiff;
                    break;

                case ".TIF":
                    imgFormat = ImageFormat.Tiff;
                    break;

                case ".BMP":
                    imgFormat = ImageFormat.Bmp;
                    break;

                case ".PNG":
                    imgFormat = ImageFormat.Png;
                    break;
                }
                vtPage.SaveTexture(textureToExport, FileName, imgFormat);
            }
        }
예제 #2
0
        public void SetTexture(crVTMapEntry vtEntry)
        {
            currentEntry = vtEntry;
            if (vtEntry == null || vtPage == null)
            {
                return;
            }
            var tiles = vtPage.GetTiles(vtEntry);

            if (tiles.Count == 0)
            {
                return;
            }
            mainForm.tileListSource.DataSource = tiles;
            var    uniqueTiles   = (from tile in tiles select tile.TDXTile.Texture.Name).Distinct();
            Format textureformat = Format.BC3_UNorm;

            if (tiles[0].TDXTile.Texture == null)
            {
                tiles[0].TDXTile.GetTextureFromZAD();
            }
            if (tiles[0].TDXTile.Texture == null)
            {
                return;
            }
            switch (tiles[0].TDXTile.Texture.Format)
            {
            case ToxicRagers.Helpers.D3DFormat.DXT1:
                textureformat = Format.BC1_UNorm;
                break;

            case ToxicRagers.Helpers.D3DFormat.DXT5:
                textureformat = Format.BC3_UNorm;
                break;

            case ToxicRagers.Helpers.D3DFormat.ATI2:
                textureformat = Format.BC5_UNorm;
                break;

            case ToxicRagers.Helpers.D3DFormat.A8R8G8B8:
                textureformat = Format.B8G8R8A8_UNorm_SRGB;
                break;

            case ToxicRagers.Helpers.D3DFormat.A8:
                textureformat = Format.A8_UNorm;
                break;
            }
            List <ShaderResourceView> resourceViews = new List <ShaderResourceView>();
            List <DataRectangle>      rects         = new List <DataRectangle>();
            List <Int32> TileRows = new List <int>();
            List <Int32> TileCols = new List <int>();

            List <float> IndirectionData = new List <float>();
            int          divisor         = vtPage.GetDivisor();

            var cb = new VTConstantBuffer();

            cb.Width          = vtEntry.Width / vtPage.GetDivisor();
            cb.Height         = vtEntry.Height / vtPage.GetDivisor();
            cb.TilesX         = (int)Math.Ceiling(cb.Width / 120.0f) + 1;
            cb.TilesY         = (int)Math.Ceiling(cb.Height / 120.0f) + 1;
            cb.ViewportWidth  = targetControl.ClientSize.Width;
            cb.ViewportHeight = targetControl.ClientSize.Height;
            cb.PosOffsetX     = vtEntry.Column / divisor - tiles[0].Column * 120;
            cb.PosOffsetY     = vtEntry.Row / divisor - tiles[0].Row * 120;
            float widthRatio  = (float)cb.Height / cb.Width;
            float heightRatio = (float)cb.Width / cb.Height;
            float polyWidth   = 1f;
            float polyHeight  = 1f;

            if (cb.ViewportWidth > cb.ViewportHeight)
            {
                polyWidth = cb.ViewportWidth / cb.ViewportHeight;
            }
            else if (cb.ViewportWidth < cb.ViewportHeight)
            {
                polyHeight = cb.ViewportHeight / cb.ViewportWidth;
            }
            if (cb.Width > cb.Height)
            {
                if (cb.ViewportWidth > cb.Width)
                {
                    //polyWidth = (float)cb.Width / cb.ViewportWidth;
                    //polyHeight = (float)cb.Height / cb.ViewportHeight;
                }
                cb.TextureWidth  = cb.ViewportWidth < cb.Width ? cb.ViewportWidth : cb.Width;
                cb.TextureHeight = (int)(cb.TextureWidth * ((float)cb.Height / cb.Width));
                polyHeight       = (1f - ((float)cb.TextureHeight / cb.ViewportHeight) * widthRatio) * 2 - 1;
                polyWidth        = ((float)cb.TextureWidth / cb.ViewportWidth) * 2 - 1;
            }
            else if (cb.Width < cb.Height)
            {
                if (cb.ViewportHeight > cb.Height)
                {
                    //polyHeight = (float)cb.Height / cb.ViewportHeight;
                    //polyWidth = (float)cb.Height / cb.ViewportHeight;
                }
                cb.TextureHeight = cb.ViewportHeight < cb.Height ? cb.ViewportHeight : cb.Height;
                cb.TextureWidth  = (int)(cb.TextureHeight * ((float)cb.Width / cb.Height));
                polyHeight       = (1f - ((float)cb.TextureHeight / cb.ViewportHeight)) * 2 - 1;
                polyWidth        = ((float)cb.TextureWidth / cb.ViewportWidth) * heightRatio * 2 - 1;
            }
            else
            {
                if (cb.ViewportWidth < cb.ViewportHeight)
                {
                    if (cb.ViewportWidth < cb.Width)
                    {
                        cb.TextureWidth  = cb.ViewportWidth;
                        cb.TextureHeight = (int)Math.Floor(cb.ViewportWidth * widthRatio);
                        //polyWidth = (float)cb.Width / cb.ViewportWidth;
                        //polyHeight = (float)cb.Height / cb.ViewportHeight; // polyWidth;
                    }
                }
                cb.TextureHeight = cb.ViewportHeight < cb.Height ? cb.ViewportHeight : cb.Height;
                cb.TextureWidth  = cb.ViewportWidth < cb.Width ? cb.ViewportWidth : cb.Width;
                polyHeight       = (1f - ((float)cb.TextureHeight / cb.ViewportHeight)) * 2 - 1;
                polyWidth        = ((float)cb.TextureWidth / cb.ViewportWidth) * 2 - 1;
            }

            var mappedData = context.MapSubresource(vertexBuffer, 0, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None);


            mappedData.Data.Write(new Vector3(-1f, polyHeight, 0.5f)); mappedData.Data.Write(new Vector2(0f, 1f));
            mappedData.Data.Write(new Vector3(-1f, 1f, 0.5f)); mappedData.Data.Write(new Vector2(0f, 0f));
            mappedData.Data.Write(new Vector3(polyWidth, polyHeight, 0.5f)); mappedData.Data.Write(new Vector2(1f, 1f));
            mappedData.Data.Write(new Vector3(polyWidth, 1f, 0.5f)); mappedData.Data.Write(new Vector2(1f, 0f));

            context.UnmapSubresource(vertexBuffer, 0);
            if (cb.PosOffsetX > 0 || cb.PosOffsetY > 0)
            {
                Console.Write("");
            }
            //cb.PosX = vtEntry.Column / vtPage.GetDivisor();
            //cb.PosY = vtEntry.Row / vtPage.GetDivisor();

            for (int y = 0; y <= cb.TilesY; y++)
            {
                for (int x = 0; x <= cb.TilesX; x++)
                {
                    IndirectionData.Add(0);
                }
            }
            int vtDivisor = vtPage.GetDivisor();

            foreach (var tile in tiles)
            {
                //using (MemoryStream stream = new MemoryStream())
                {
                    /*var dds = tile.GetDDS();
                     * BinaryWriter bw = new BinaryWriter(stream);
                     * dds.Save(bw);
                     * stream.Seek(0, SeekOrigin.Begin);
                     * Texture2D tex = Texture2D.FromStream(device, stream, (int)stream.Length);*/
                    DataRectangle rect = new DataRectangle(128 * 4, new DataStream(tile.TDXTile.Texture.DecompressToBytes(), false, false));
                    rects.Add(rect);
                    TileRows.Add(tile.Row);
                    TileCols.Add(tile.Column);

                    int indIndex = (((tile.Row * 120 - (vtEntry.Row / vtDivisor)) / 120) * cb.TilesX) + (tile.Column * 120 - vtEntry.Column / vtDivisor) / 120;
                    IndirectionData[indIndex] = (float)((rects.Count - 1) / tiles.Count);
                    //resourceViews.Add(new ShaderResourceView(device, tex));
                    //bw.Dispose();
                }
            }
            Texture2D textureArray = new Texture2D(device, new Texture2DDescription
            {
                BindFlags         = BindFlags.ShaderResource,
                ArraySize         = rects.Count,
                Width             = 128,
                Height            = 128,
                Usage             = ResourceUsage.Default,
                CpuAccessFlags    = CpuAccessFlags.None,
                Format            = Format.B8G8R8A8_UNorm,
                SampleDescription = new SampleDescription(1, 0),
                MipLevels         = 1,
                OptionFlags       = ResourceOptionFlags.None
            }
                                                   , rects.ToArray());
            ShaderResourceView resourceView = new ShaderResourceView(device, textureArray);

            context.PixelShader.SetShaderResource(resourceView, 0);
            //cb.TilePosX = TileCols.ToArray();
            //cb.TilePosY = TileRows.ToArray();
            int sizeOfCB = ((sizeof(Int32) * 10 + 15) / 16) * 16;

            using (DataStream data = new DataStream(sizeOfCB, true, true))
            {
                data.Write(cb);
                data.Position = 0;
                context.PixelShader.SetConstantBuffer(new SlimDX.Direct3D11.Buffer(device, data, new BufferDescription
                {
                    Usage       = ResourceUsage.Default,
                    SizeInBytes = sizeOfCB,// + cb.TilePosX.Length + cb.TilePosY.Length),
                    BindFlags   = BindFlags.ConstantBuffer
                }), 0);
            }
            Texture2D inderectionTexture = new Texture2D(device, new Texture2DDescription
            {
                BindFlags         = BindFlags.ShaderResource,
                ArraySize         = 1,
                Width             = cb.TilesX,
                Height            = cb.TilesY,
                Usage             = ResourceUsage.Default,
                CpuAccessFlags    = CpuAccessFlags.None,
                Format            = Format.R32_Float,
                SampleDescription = new SampleDescription(1, 0),
                MipLevels         = 1,
                OptionFlags       = ResourceOptionFlags.None
            }
                                                         , new DataRectangle(cb.TilesX * 4, new DataStream(IndirectionData.ToArray(), true, true)));
            ShaderResourceView indresourceview = new ShaderResourceView(device, inderectionTexture);

            context.PixelShader.SetShaderResource(indresourceview, 1);
            UpdateRenderer = true;
            //fx.GetVariableByName("shaderTexture").AsResource().SetResourceArray(resourceViews.ToArray());

            /*fx.GetVariableByName("Width").AsScalar().Set(vtEntry.Width);
             * fx.GetVariableByName("Height").AsScalar().Set(vtEntry.Height);
             * fx.GetVariableByName("TilesX").AsScalar().Set((int)(vtEntry.Width / 128.0f));
             * fx.GetVariableByName("TilesY").AsScalar().Set((int)(vtEntry.Height / 128.0f));
             * device.ImmediateContext.PixelShader.SetShaderResource(resourceView, 0);*/
            //context.PixelShader.SetShaderResource(resourceView, 0);
            //context.PixelShader.SetSampler(sampleState, 0);
        }
예제 #3
0
        private void SaveTextureTiles(crVTMapEntry textureToExport, String FileName)
        {
            Properties.Settings.Default.LastExportDirectory = Path.GetDirectoryName(FileName);
            Properties.Settings.Default.Save();

            var fileType = Path.GetExtension(FileName).ToUpper();

            var path = Path.GetDirectoryName(FileName);
            var filenameprefix = Path.GetFileNameWithoutExtension(FileName);
            ImageFormat imgFormat = ImageFormat.Png;

            List<crVTPage> vtPages = diffusePages;
            if (PageType.SelectedItem == "Specular") vtPages = specularPages;
            else if (PageType.SelectedItem == "Normal") vtPages = normalPages;

            foreach (var vtPage in vtPages)
            {
                var tiles = vtPage.GetTiles(textureToExport);
                int tileNum = 0;
                foreach (var tile in tiles)
                {
                    if (tile.TDXTile.Texture == null) tile.TDXTile.GetTextureFromZAD();
                    tileNum++;
                    string tileFileName = Path.Combine(path, filenameprefix + "_p"+vtPage.PageNum+ "_t" + String.Format("{0}", tileNum) + fileType);
                    if (fileType == ".TGA")
                    {
                        //vtPage.SaveTexture(textureToExport, FileName, false, true, false, ImageFormat.Png);
                    }
                    else if (fileType == ".TDX")
                    {
                        ZAD tilezad = ZAD.Load(tile.TDXTile.ZADFile);
                        tilezad.Extract(tilezad.Contents.Find(entry => entry.Name == tile.TDXTile.ZADEntryLocation), path+"/");
                        //tile.TDXTile.Texture.Save(tileFileName);
                        //vtPage.SaveTexture(textureToExport, FileName, true, false, false, ImageFormat.Png);
                    }
                    else
                    {
                        switch (fileType)
                        {
                            case ".JPG":
                                imgFormat = ImageFormat.Jpeg;
                                break;
                            case ".JPEG":
                                imgFormat = ImageFormat.Jpeg;
                                break;
                            case ".TIFF":
                                imgFormat = ImageFormat.Tiff;
                                break;
                            case ".TIF":
                                imgFormat = ImageFormat.Tiff;
                                break;
                            case ".BMP":
                                imgFormat = ImageFormat.Bmp;
                                break;
                            case ".PNG":
                                imgFormat = ImageFormat.Png;
                                break;
                        }
                        Bitmap b = tile.TDXTile.Texture.Decompress(0, false);
                        b.Save(tileFileName);
                    }
                }
            }
        }
예제 #4
0
        private void SaveTexture(crVTMapEntry textureToExport, String FileName, crVTPage vtPage)
        {
            Properties.Settings.Default.LastExportDirectory = Path.GetDirectoryName(FileName);
            Properties.Settings.Default.Save();

            var fileType = Path.GetExtension(FileName).ToUpper();
            ImageFormat imgFormat = ImageFormat.Png;

            if (fileType == ".TGA")
            {
                vtPage.SaveTexture(textureToExport, FileName, false, true, false, ImageFormat.Png);
            }
            else if (fileType == ".TDX")
            {
                vtPage.SaveTexture(textureToExport, FileName, true, false, false, ImageFormat.Png);
            }
            else
            {
                switch (fileType)
                {
                    case ".JPG":
                        imgFormat = ImageFormat.Jpeg;
                        break;
                    case ".JPEG":
                        imgFormat = ImageFormat.Jpeg;
                        break;
                    case ".TIFF":
                        imgFormat = ImageFormat.Tiff;
                        break;
                    case ".TIF":
                        imgFormat = ImageFormat.Tiff;
                        break;
                    case ".BMP":
                        imgFormat = ImageFormat.Bmp;
                        break;
                    case ".PNG":
                        imgFormat = ImageFormat.Png;
                        break;
                }
                vtPage.SaveTexture(textureToExport, FileName, imgFormat);
            }
        }
예제 #5
0
 private void SaveTexture(crVTMapEntry textureToExport, String FileName)
 {
     SaveTexture(textureToExport, FileName, (crVTPage)PageNumSelect.SelectedItem);
 }
예제 #6
0
        public void SetTexture(crVTMapEntry vtEntry)
        {
            currentEntry = vtEntry;
            if (vtEntry == null || vtPage == null) return;
            var tiles = vtPage.GetTiles(vtEntry);
            if (tiles.Count == 0) return;
            mainForm.tileListSource.DataSource = tiles;
            var uniqueTiles = (from tile in tiles select tile.TDXTile.Texture.Name).Distinct();
            Format textureformat = Format.BC3_UNorm;
            if (tiles[0].TDXTile.Texture == null) tiles[0].TDXTile.GetTextureFromZAD();
            if (tiles[0].TDXTile.Texture == null)
            {
                return;
            }
            switch (tiles[0].TDXTile.Texture.Format)
            {
                case ToxicRagers.Helpers.D3DFormat.DXT1:
                    textureformat = Format.BC1_UNorm;
                    break;
                case ToxicRagers.Helpers.D3DFormat.DXT5:
                    textureformat = Format.BC3_UNorm;
                    break;
                case ToxicRagers.Helpers.D3DFormat.ATI2:
                    textureformat = Format.BC5_UNorm;
                    break;
                case ToxicRagers.Helpers.D3DFormat.A8R8G8B8:
                    textureformat = Format.B8G8R8A8_UNorm_SRGB;
                    break;
                case ToxicRagers.Helpers.D3DFormat.A8:
                    textureformat = Format.A8_UNorm;
                    break;

            }
            List<ShaderResourceView> resourceViews = new List<ShaderResourceView>();
            List<DataRectangle> rects = new List<DataRectangle>();
            List<Int32> TileRows = new List<int>();
            List<Int32> TileCols = new List<int>();

            List<float> IndirectionData = new List<float>();
            int divisor = vtPage.GetDivisor();

            var cb = new VTConstantBuffer();
            cb.Width = vtEntry.Width / vtPage.GetDivisor();
            cb.Height = vtEntry.Height / vtPage.GetDivisor();
            cb.TilesX = (int)Math.Ceiling(cb.Width / 120.0f) + 1;
            cb.TilesY = (int)Math.Ceiling(cb.Height / 120.0f) + 1;
            cb.ViewportWidth = targetControl.ClientSize.Width;
            cb.ViewportHeight = targetControl.ClientSize.Height;
            cb.PosOffsetX = vtEntry.Column / divisor - tiles[0].Column * 120;
            cb.PosOffsetY = vtEntry.Row / divisor - tiles[0].Row * 120;
            float widthRatio = (float)cb.Height / cb.Width;
            float heightRatio = (float)cb.Width / cb.Height;
            float polyWidth = 1f;
            float polyHeight = 1f;
            if (cb.ViewportWidth > cb.ViewportHeight)
            {
                polyWidth = cb.ViewportWidth / cb.ViewportHeight;
            }
            else if (cb.ViewportWidth < cb.ViewportHeight)
            {
                polyHeight = cb.ViewportHeight / cb.ViewportWidth;
            }
            if (cb.Width > cb.Height)
            {
                if (cb.ViewportWidth > cb.Width)
                {
                    //polyWidth = (float)cb.Width / cb.ViewportWidth;
                    //polyHeight = (float)cb.Height / cb.ViewportHeight;
                }
                cb.TextureWidth = cb.ViewportWidth < cb.Width ? cb.ViewportWidth : cb.Width;
                cb.TextureHeight = (int)(cb.TextureWidth * ((float)cb.Height / cb.Width));
                polyHeight = (1f - ((float)cb.TextureHeight / cb.ViewportHeight) * widthRatio) * 2 - 1;
                polyWidth = ((float)cb.TextureWidth / cb.ViewportWidth) * 2 - 1;
            }
            else if (cb.Width < cb.Height)
            {
                if (cb.ViewportHeight > cb.Height)
                {
                    //polyHeight = (float)cb.Height / cb.ViewportHeight;
                    //polyWidth = (float)cb.Height / cb.ViewportHeight;
                }
                cb.TextureHeight = cb.ViewportHeight < cb.Height ? cb.ViewportHeight : cb.Height;
                cb.TextureWidth = (int)(cb.TextureHeight * ((float)cb.Width / cb.Height));
                polyHeight = (1f - ((float)cb.TextureHeight / cb.ViewportHeight)) * 2 - 1;
                polyWidth = ((float)cb.TextureWidth / cb.ViewportWidth) * heightRatio * 2 - 1;

            }
            else
            {
                if (cb.ViewportWidth < cb.ViewportHeight)
                {
                    if (cb.ViewportWidth < cb.Width)
                    {
                        cb.TextureWidth = cb.ViewportWidth;
                        cb.TextureHeight = (int)Math.Floor(cb.ViewportWidth * widthRatio);
                        //polyWidth = (float)cb.Width / cb.ViewportWidth;
                        //polyHeight = (float)cb.Height / cb.ViewportHeight; // polyWidth;
                    }
                }
                cb.TextureHeight = cb.ViewportHeight < cb.Height ? cb.ViewportHeight : cb.Height;
                cb.TextureWidth = cb.ViewportWidth < cb.Width ? cb.ViewportWidth : cb.Width;
                polyHeight = (1f - ((float)cb.TextureHeight / cb.ViewportHeight)) * 2 - 1;
                polyWidth = ((float)cb.TextureWidth / cb.ViewportWidth) * 2 - 1;
            }

            var mappedData = context.MapSubresource(vertexBuffer, 0, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None);

            mappedData.Data.Write(new Vector3(-1f, polyHeight, 0.5f)); mappedData.Data.Write(new Vector2(0f, 1f));
            mappedData.Data.Write(new Vector3(-1f, 1f, 0.5f)); mappedData.Data.Write(new Vector2(0f, 0f));
            mappedData.Data.Write(new Vector3(polyWidth, polyHeight, 0.5f)); mappedData.Data.Write(new Vector2(1f, 1f));
            mappedData.Data.Write(new Vector3(polyWidth, 1f, 0.5f)); mappedData.Data.Write(new Vector2(1f, 0f));

            context.UnmapSubresource(vertexBuffer, 0);
            if (cb.PosOffsetX > 0 || cb.PosOffsetY > 0)
            {
                Console.Write("");
            }
            //cb.PosX = vtEntry.Column / vtPage.GetDivisor();
            //cb.PosY = vtEntry.Row / vtPage.GetDivisor();

            for (int y = 0; y <= cb.TilesY; y++)
            {
                for (int x = 0; x <= cb.TilesX; x++)
                {
                    IndirectionData.Add(0);
                }
            }
            int vtDivisor = vtPage.GetDivisor();
            foreach (var tile in tiles)
            {
                //using (MemoryStream stream = new MemoryStream())
                {
                    /*var dds = tile.GetDDS();
                    BinaryWriter bw = new BinaryWriter(stream);
                    dds.Save(bw);
                    stream.Seek(0, SeekOrigin.Begin);
                    Texture2D tex = Texture2D.FromStream(device, stream, (int)stream.Length);*/
                    DataRectangle rect = new DataRectangle(128 * 4, new DataStream(tile.TDXTile.Texture.DecompressToBytes(), false, false));
                    rects.Add(rect);
                    TileRows.Add(tile.Row);
                    TileCols.Add(tile.Column);

                    int indIndex = (((tile.Row * 120 - (vtEntry.Row / vtDivisor)) / 120) * cb.TilesX) + (tile.Column * 120 - vtEntry.Column / vtDivisor) / 120;
                    IndirectionData[indIndex] = (float)((rects.Count - 1) / tiles.Count);
                    //resourceViews.Add(new ShaderResourceView(device, tex));
                    //bw.Dispose();
                }
            }
            Texture2D textureArray = new Texture2D(device, new Texture2DDescription
            {
                BindFlags = BindFlags.ShaderResource,
                ArraySize = rects.Count,
                Width = 128,
                Height = 128,
                Usage = ResourceUsage.Default,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = Format.B8G8R8A8_UNorm,
                SampleDescription = new SampleDescription(1, 0),
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None
            }
                , rects.ToArray());
            ShaderResourceView resourceView = new ShaderResourceView(device, textureArray);
            context.PixelShader.SetShaderResource(resourceView, 0);
            //cb.TilePosX = TileCols.ToArray();
            //cb.TilePosY = TileRows.ToArray();
            int sizeOfCB = ((sizeof(Int32) * 10 + 15) / 16) * 16;
            using (DataStream data = new DataStream(sizeOfCB, true, true))
            {
                data.Write(cb);
                data.Position = 0;
                context.PixelShader.SetConstantBuffer(new SlimDX.Direct3D11.Buffer(device, data, new BufferDescription
                {
                    Usage = ResourceUsage.Default,
                    SizeInBytes = sizeOfCB,// + cb.TilePosX.Length + cb.TilePosY.Length),
                    BindFlags = BindFlags.ConstantBuffer
                }), 0);
            }
            Texture2D inderectionTexture = new Texture2D(device, new Texture2DDescription
            {
                BindFlags = BindFlags.ShaderResource,
                ArraySize = 1,
                Width = cb.TilesX,
                Height = cb.TilesY,
                Usage = ResourceUsage.Default,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = Format.R32_Float,
                SampleDescription = new SampleDescription(1, 0),
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None
            }
                , new DataRectangle(cb.TilesX * 4, new DataStream(IndirectionData.ToArray(), true, true)));
            ShaderResourceView indresourceview = new ShaderResourceView(device, inderectionTexture);
            context.PixelShader.SetShaderResource(indresourceview, 1);
            UpdateRenderer = true;
            //fx.GetVariableByName("shaderTexture").AsResource().SetResourceArray(resourceViews.ToArray());
            /*fx.GetVariableByName("Width").AsScalar().Set(vtEntry.Width);
            fx.GetVariableByName("Height").AsScalar().Set(vtEntry.Height);
            fx.GetVariableByName("TilesX").AsScalar().Set((int)(vtEntry.Width / 128.0f));
            fx.GetVariableByName("TilesY").AsScalar().Set((int)(vtEntry.Height / 128.0f));
            device.ImmediateContext.PixelShader.SetShaderResource(resourceView, 0);*/
            //context.PixelShader.SetShaderResource(resourceView, 0);
            //context.PixelShader.SetSampler(sampleState, 0);
        }
예제 #7
0
        private void SaveTextureTiles(crVTMapEntry textureToExport, String FileName)
        {
            Properties.Settings.Default.LastExportDirectory = Path.GetDirectoryName(FileName);
            Properties.Settings.Default.Save();

            var fileType = Path.GetExtension(FileName).ToUpper();

            var         path           = Path.GetDirectoryName(FileName);
            var         filenameprefix = Path.GetFileNameWithoutExtension(FileName);
            ImageFormat imgFormat      = ImageFormat.Png;

            List <crVTPage> vtPages = diffusePages;

            if (PageType.SelectedItem == "Specular")
            {
                vtPages = specularPages;
            }
            else if (PageType.SelectedItem == "Normal")
            {
                vtPages = normalPages;
            }

            foreach (var vtPage in vtPages)
            {
                var tiles   = vtPage.GetTiles(textureToExport);
                int tileNum = 0;
                foreach (var tile in tiles)
                {
                    if (tile.TDXTile.Texture == null)
                    {
                        tile.TDXTile.GetTextureFromZAD();
                    }
                    tileNum++;
                    string tileFileName = Path.Combine(path, filenameprefix + "_p" + vtPage.PageNum + "_t" + String.Format("{0}", tileNum) + fileType);
                    if (fileType == ".TGA")
                    {
                        //vtPage.SaveTexture(textureToExport, FileName, false, true, false, ImageFormat.Png);
                    }
                    else if (fileType == ".TDX")
                    {
                        ZAD tilezad = ZAD.Load(tile.TDXTile.ZADFile);
                        tilezad.Extract(tilezad.Contents.Find(entry => entry.Name == tile.TDXTile.ZADEntryLocation), path + "/");
                        //tile.TDXTile.Texture.Save(tileFileName);
                        //vtPage.SaveTexture(textureToExport, FileName, true, false, false, ImageFormat.Png);
                    }
                    else
                    {
                        switch (fileType)
                        {
                        case ".JPG":
                            imgFormat = ImageFormat.Jpeg;
                            break;

                        case ".JPEG":
                            imgFormat = ImageFormat.Jpeg;
                            break;

                        case ".TIFF":
                            imgFormat = ImageFormat.Tiff;
                            break;

                        case ".TIF":
                            imgFormat = ImageFormat.Tiff;
                            break;

                        case ".BMP":
                            imgFormat = ImageFormat.Bmp;
                            break;

                        case ".PNG":
                            imgFormat = ImageFormat.Png;
                            break;
                        }
                        Bitmap b = tile.TDXTile.Texture.Decompress(0, false);
                        b.Save(tileFileName);
                    }
                }
            }
        }
예제 #8
0
 private void SaveTexture(crVTMapEntry textureToExport, String FileName)
 {
     SaveTexture(textureToExport, FileName, (crVTPage)PageNumSelect.SelectedItem);
 }