Exemplo n.º 1
0
        // converts a lat long texture to a cubemap
        public TextureArray2D ConvertToCube(TextureArray2D latlong, int resolution)
        {
            Debug.Assert(latlong.NumLayers == 1);

            var dst = new TextureArray2D(new LayerMipmapCount(6, 1), new Size3(resolution, resolution), Format.R32G32B32A32_Float, false);

            var dev = Device.Get();

            quad.Bind(false);
            dev.Pixel.Set(toCube.Pixel);

            dev.Pixel.SetShaderResource(0, latlong.GetSrView(LayerMipmapSlice.Mip0));
            dev.Pixel.SetSampler(0, sampler);
            dev.OutputMerger.SetRenderTargets(null,
                                              dst.GetRtView(new LayerMipmapSlice(0, 0)),
                                              dst.GetRtView(new LayerMipmapSlice(1, 0)),
                                              dst.GetRtView(new LayerMipmapSlice(2, 0)),
                                              dst.GetRtView(new LayerMipmapSlice(3, 0)),
                                              dst.GetRtView(new LayerMipmapSlice(4, 0)),
                                              dst.GetRtView(new LayerMipmapSlice(5, 0)));
            dev.SetViewScissors(resolution, resolution);
            dev.DrawQuad();

            dev.Pixel.SetShaderResource(0, null);
            dev.Pixel.SetSampler(0, null);
            dev.OutputMerger.SetRenderTargets((RenderTargetView)null);
            quad.Unbind();

            return(dst);
        }
        private void Apply(TextureArray2D src, TextureArray2D dst, int dirX, int dirY)
        {
            quad.Bind(false);
            var dev = Device.Get();

            dev.Pixel.Set(shader.Pixel);

            cbuffer.SetData(new DirSizeData
            {
                DirX  = dirX,
                DirY  = dirY,
                SizeX = src.Size.Width,
                SizeY = src.Size.Height
            });

            dev.Pixel.SetConstantBuffer(0, cbuffer.Handle);
            dev.SetViewScissors(dst.Size.Width, dst.Size.Height);

            foreach (var lm in src.LayerMipmap.LayersOfMipmap(0))
            {
                dev.Pixel.SetShaderResource(0, src.GetSrView(lm));
                dev.OutputMerger.SetRenderTargets(dst.GetRtView(lm));
                dev.DrawQuad();
            }

            dev.Pixel.SetShaderResource(0, null);
            dev.OutputMerger.SetRenderTargets((RenderTargetView)null);
            quad.Unbind();
        }
Exemplo n.º 3
0
        private async Task CreateGifAsync(TextureArray2D left, TextureArray2D right, Config cfg, IProgress progress)
        {
            // delay in milliseconds
            var numFrames = cfg.FramesPerSecond * cfg.NumSeconds;

            try
            {
                progressModel.EnableDllProgress = false;
                var leftView  = left.GetSrView(LayerMipmapSlice.Mip0);
                var rightView = right.GetSrView(LayerMipmapSlice.Mip0);

                var curProg = progress.CreateSubProgress(0.9f);
                // create frames
                using (var dst = IO.CreateImage(new ImageFormat(Format.R8G8B8A8_UNorm_SRgb), left.Size, LayerMipmapCount.One))
                {
                    var dstMip  = dst.GetMipmap(LayerMipmapSlice.Mip0);
                    var dstPtr  = dstMip.Bytes;
                    var dstSize = dstMip.ByteSize;

                    // render frames into texture
                    using (var frame = new TextureArray2D(LayerMipmapCount.One, left.Size,
                                                          Format.R8G8B8A8_UNorm_SRgb, false))
                    {
                        var frameView = frame.GetRtView(LayerMipmapSlice.Mip0);

                        for (int i = 0; i < numFrames; ++i)
                        {
                            float t         = (float)i / (numFrames);
                            int   borderPos = (int)(t * frame.Size.Width);

                            // render frame
                            shader.Run(leftView, rightView, frameView, cfg.SliderWidth, borderPos,
                                       frame.Size.Width, frame.Size.Height);

                            // save frame as png
                            frame.CopyPixels(LayerMipmapSlice.Mip0, dstPtr, dstSize);
                            var filename = $"{cfg.TmpFilename}{i:D4}";
                            await Task.Run(() => IO.SaveImage(dst, filename, "png", GliFormat.RGBA8_SRGB), progress.Token);

                            curProg.Progress = i / (float)numFrames;
                            curProg.What     = "creating frames";
                        }
                    }
                }

                // convert video
                await FFMpeg.ConvertAsync(cfg, progress.CreateSubProgress(1.0f));
            }
            finally
            {
                progressModel.EnableDllProgress = true;
            }
        }