// 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); }
/// <summary> /// copies a single mip from one layer of a texture to another layer of a texture. The formats don't have to match /// </summary> /// <param name="src">source texture</param> /// <param name="srcLayer"></param> /// <param name="srcMip"></param> /// <param name="dst">destination texture</param> /// <param name="dstLayer"></param> /// <param name="dstMip"></param> public void CopyLayer(TextureArray2D src, int srcLayer, int srcMip, TextureArray2D dst, int dstLayer, int dstMip) { Debug.Assert(src.Size == dst.Size); var dev = DirectX.Device.Get(); quad.Bind(false); dev.Pixel.Set(convert2D.Pixel); dev.Pixel.SetShaderResource(0, src.View); cbuffer.SetData(new LayerLevelOffsetData { Layer = srcLayer, Level = srcMip, Xoffset = 0, Yoffset = 0, Multiplier = 1.0f }); var dim = dst.Size.GetMip(dstMip); dev.Pixel.SetConstantBuffer(0, cbuffer.Handle); dev.OutputMerger.SetRenderTargets(dst.GetRtView(dstLayer, dstMip)); dev.SetViewScissors(dim.Width, dim.Height); dev.DrawQuad(); // remove bindings dev.Pixel.SetShaderResource(0, null); dev.OutputMerger.SetRenderTargets((RenderTargetView)null); }
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(); }
public void Run(ShaderResourceView left, ShaderResourceView right, RenderTargetView dst, int borderSize, int borderLocation, int width, int height) { Debug.Assert(borderLocation >= 0); Debug.Assert(borderLocation < width); quad.Bind(false); var dev = Device.Get(); dev.Pixel.Set(pixel.Pixel); // update buffer cbuffer.SetData(new BufferData { BorderLocation = borderLocation, BorderSize = borderSize }); // bind and draw dev.Pixel.SetConstantBuffer(0, cbuffer.Handle); dev.Pixel.SetShaderResource(0, left); dev.Pixel.SetShaderResource(1, right); dev.OutputMerger.SetRenderTargets(dst); dev.SetViewScissors(width, height); dev.DrawQuad(); // unbind dev.Pixel.SetShaderResource(0, null); dev.Pixel.SetShaderResource(1, null); dev.OutputMerger.SetRenderTargets((RenderTargetView)null); quad.Unbind(); }
/// <summary> /// copies a single mip from one layer of a texture to another layer of a texture. The formats don't have to match /// </summary> /// <param name="src">source texture</param> /// <param name="dst">destination texture</param> public void CopyLayer(ITexture src, LayerMipmapSlice srcLm, ITexture dst, LayerMipmapSlice dstLm) { Debug.Assert(src.Size == dst.Size); var dev = DirectX.Device.Get(); quad.Bind(src.Is3D); if (src.Is3D) { dev.Pixel.Set(convert3D.Pixel); } else { dev.Pixel.Set(convert2D.Pixel); } dev.Pixel.SetShaderResource(0, src.View); cbuffer.SetData(new LayerLevelOffsetData { Layer = srcLm.Layer, Level = srcLm.Mipmap, Xoffset = 0, Yoffset = 0, Multiplier = 1.0f, UseOverlay = 0, Scale = 1 }); var dim = dst.Size.GetMip(dstLm.Mipmap); dev.Pixel.SetConstantBuffer(0, cbuffer.Handle); dev.OutputMerger.SetRenderTargets(dst.GetRtView(dstLm)); dev.SetViewScissors(dim.Width, dim.Height); dev.DrawFullscreenTriangle(dim.Depth); // remove bindings dev.Pixel.SetShaderResource(0, null); dev.OutputMerger.SetRenderTargets((RenderTargetView)null); quad.Unbind(); }
public Texture3D ConvertTo3D(TextureArray2D src) { var dst = new Texture3D(1, new Size3(src.Size.X, src.Size.Y, src.NumLayers), Format.R32G32B32A32_Float, false); var dev = Device.Get(); quad.Bind(true); dev.Pixel.Set(shader3D.Pixel); dev.Pixel.SetShaderResource(0, src.View); dev.OutputMerger.SetRenderTargets(dst.GetRtView(LayerMipmapSlice.Mip0)); dev.SetViewScissors(dst.Size.Width, dst.Size.Height); dev.DrawFullscreenTriangle(dst.Size.Z); dev.Pixel.SetShaderResource(0, null); dev.OutputMerger.SetRenderTargets((RenderTargetView)null); quad.Unbind(); return(dst); }