public void UpdateTexture(TextureModel texture, ITextureResourceManager manager) { var tex = manager.Register(texture, true); RemoveAndDispose(ref textureView); textureView = tex; }
protected override void OnRender(IRenderContext context, DeviceContextProxy deviceContext) { if (resolutionChanged) { RemoveAndDispose(ref viewResource); viewResource = Collect(new ShaderResourceViewProxy(Device, ShadowMapTextureDesc)); viewResource.CreateView(DepthStencilViewDesc); viewResource.CreateView(ShaderResourceViewDesc); resolutionChanged = false; } deviceContext.DeviceContext.ClearDepthStencilView(viewResource, DepthStencilClearFlags.Depth, 1.0f, 0); context.IsShadowPass = true; var orgFrustum = context.BoundingFrustum; context.BoundingFrustum = new BoundingFrustum(LightViewProjectMatrix); #if !TEST deviceContext.DeviceContext.Rasterizer.SetViewport(0, 0, Width, Height); deviceContext.DeviceContext.OutputMerger.SetTargets(viewResource.DepthStencilView, new RenderTargetView[0]); for (int i = 0; i < context.RenderHost.PerFrameGeneralRenderCores.Count; ++i) { var core = context.RenderHost.PerFrameGeneralRenderCores[i]; if (core.IsThrowingShadow && core.RenderType == RenderType.Opaque) { core.Render(context, deviceContext); } } context.IsShadowPass = false; context.BoundingFrustum = orgFrustum; context.RenderHost.SetDefaultRenderTargets(false); context.SharedResource.ShadowView = viewResource.TextureView; #endif }
private ShaderResourceViewProxy CreateRenderTarget(int width, int height, MSAALevel msaa) { #if MSAA MSAA = msaa; #endif TargetWidth = width; TargetHeight = height; DisposeBuffers(); ColorBufferSampleDesc = GetMSAASampleDescription(); OnCreateRenderTargetAndDepthBuffers(width, height, UseDepthStencilBuffer, out colorBuffer, out depthStencilBuffer); backBuffer = OnCreateBackBuffer(width, height); backBuffer.CreateRenderTargetView(); fullResPPBuffer = Collect(new PingPongColorBuffers(Format, width, height, this.deviceResources)); fullResDepthStencilPool = Collect(new TexturePool(this.deviceResources, new Texture2DDescription() { Width = width, Height = height, ArraySize = 1, BindFlags = BindFlags.DepthStencil, CpuAccessFlags = CpuAccessFlags.None, Usage = ResourceUsage.Default, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0) })); Initialized = true; OnNewBufferCreated?.Invoke(this, new Texture2DArgs(backBuffer)); return(backBuffer); }
/// <summary> /// Registers the specified material unique identifier. /// </summary> /// <param name="textureModel">The texture model.</param> /// <param name="enableAutoGenMipMap">Enable generate mipmaps automatically</param> /// <returns></returns> public ShaderResourceViewProxy Register(TextureModel textureModel, bool enableAutoGenMipMap) { if (textureModel == null) { return(null); } var targetDict = enableAutoGenMipMap ? resourceDictionaryMipMaps : resourceDictionaryNoMipMaps; lock (targetDict) { if (targetDict.TryGetValue(textureModel.Guid, out var view)) { Debug.WriteLine("Re-using existing texture resource"); view.IncRef(); return(view); } else { Debug.WriteLine("Creating new texture resource"); var proxy = new ShaderResourceViewProxy(device); proxy.CreateView(textureModel, true, enableAutoGenMipMap); proxy.Guid = textureModel.Guid; proxy.Disposed += (s, e) => { lock (targetDict) { targetDict.Remove(proxy.Guid); } }; targetDict.Add(textureModel.Guid, proxy); return(proxy); } } }
/// <summary> /// Initializes a new instance of the <see cref="UAVBufferViewProxy"/> class. /// </summary> /// <param name="device">The device.</param> /// <param name="bufferDesc">The buffer desc.</param> /// <param name="uavDesc">The uav desc.</param> /// <param name="srvDesc">The SRV desc.</param> public UAVBufferViewProxy(Device device, ref BufferDescription bufferDesc, ref UnorderedAccessViewDescription uavDesc, ref ShaderResourceViewDescription srvDesc) { buffer = new SDX11.Buffer(device, bufferDesc); srv = new ShaderResourceViewProxy(device, buffer); srv.CreateTextureView(); uav = new UnorderedAccessView(device, buffer, uavDesc); }
/// <summary> /// Called when [create vertex buffer]. /// </summary> /// <param name="context">The context.</param> /// <param name="buffer">The buffer.</param> /// <param name="geometry">The geometry.</param> /// <param name="deviceResources">The device resources.</param> /// <param name="bufferIndex"></param> protected override void OnCreateVertexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, int bufferIndex, Geometry3D geometry, IDeviceResources deviceResources) { if (geometry is IBillboardText billboardGeometry) { billboardGeometry.DrawTexture(deviceResources); if (billboardGeometry.BillboardVertices != null && billboardGeometry.BillboardVertices.Count > 0) { Type = billboardGeometry.Type; buffer.UploadDataToBuffer(context, billboardGeometry.BillboardVertices, billboardGeometry.BillboardVertices.Count, 0, geometry.PreDefinedVertexCount); if (textureStream != billboardGeometry.Texture) { RemoveAndDispose(ref textureView); textureStream = billboardGeometry.Texture; if (textureStream != null) { textureView = Collect(deviceResources.MaterialTextureManager.Register(textureStream)); } } } else { RemoveAndDispose(ref textureView); textureStream = null; buffer.UploadDataToBuffer(context, emptyVerts, 0); } } }
/// <summary> /// Create a raw buffer based UAV /// </summary> /// <param name="device">The device.</param> /// <param name="bufferDesc">The buffer desc.</param> /// <param name="uavDesc">The uav desc.</param> /// <param name="srvDesc">The SRV desc.</param> public UAVBufferViewProxy(Device device, ref BufferDescription bufferDesc, ref UnorderedAccessViewDescription uavDesc, ref ShaderResourceViewDescription srvDesc) : this(device, ref bufferDesc, ref uavDesc) { srv = new ShaderResourceViewProxy(device, resource); srv.CreateTextureView(); }
private void OnTextureChanged() { var newView = EffectTechnique.EffectsManager.MaterialTextureManager.Register(ParticleTexture); RemoveAndDispose(ref textureView); textureView = Collect(newView); }
/// <summary> /// Creates ShaderResourceViewProxy from common file formats such as Jpg, Bmp, DDS, Png, etc /// </summary> /// <param name="device">The device.</param> /// <param name="texture">The texture.</param> /// <param name="createSRV">if set to <c>true</c> [create SRV].</param> /// <returns></returns> public static ShaderResourceViewProxy CreateView(Device device, System.IO.Stream texture, bool createSRV = true, bool generateMipMaps = true) { var proxy = new ShaderResourceViewProxy(device); proxy.CreateView(texture, createSRV, generateMipMaps); return(proxy); }
/// <summary> /// Registers the specified material unique identifier. /// </summary> /// <param name="textureStream">The texture steam.</param> /// <param name="disableAutoGenMipMap">Disable generate mipmaps automatically</param> /// <returns></returns> public ShaderResourceViewProxy Register(Stream textureStream, bool disableAutoGenMipMap) { if (textureStream == null) { return(null); } var targetDict = disableAutoGenMipMap ? resourceDictionaryNoMipMaps : resourceDictionaryMipMaps; lock (targetDict) { if (targetDict.TryGetValue(textureStream, out ShaderResourceViewProxy view)) { view.IncRef(); return(view); } else { var proxy = new ShaderResourceViewProxy(device); proxy.CreateView(textureStream, disableAutoGenMipMap); proxy.Disposed += (s, e) => { lock (targetDict) { targetDict.Remove(textureStream); } }; targetDict.Add(textureStream, proxy); return(proxy); } } }
protected override void OnAttached() { previousTime = TimeSpan.Zero; IntPtr context = ImGui.CreateContext(); ImGui.SetCurrentContext(context); ImGui.GetIO().Fonts.AddFontDefault(); bufferModel = new ImGui2DBufferModel(); (RenderCore as ImGuiRenderCore).Buffer = bufferModel; var io = ImGui.GetIO(); unsafe { io.Fonts.GetTexDataAsRGBA32(out IntPtr textureData, out var width, out var height); var textureView = new ShaderResourceViewProxy(EffectsManager.Device); textureView.CreateView(textureData, width, height, Format.R8G8B8A8_UNorm); io.Fonts.SetTexID(fontAtlasID); io.Fonts.ClearTexData(); (RenderCore as ImGuiRenderCore).TextureView = textureView; } ImGui.NewFrame(); newFrame = true; base.OnAttached(); }
private void CreateTextureView(TextureModel texture) { var newRes = texture == null ? null : textureManager.Register(texture); RemoveAndDispose(ref textureResource); textureResource = newRes; }
protected override void OnDetach() { renderTargetFull = null; renderTargetDesc.Width = renderTargetDesc.Height = 0; blurCore = null; base.OnDetach(); }
/// <summary> /// Creates the 1D texture view from color array. /// </summary> /// <param name="device"></param> /// <param name="array">The array.</param> public static ShaderResourceViewProxy CreateViewFromColorArray(Device device, Color4[] array) { var proxy = new ShaderResourceViewProxy(device); proxy.CreateViewFromColorArray(array); return(proxy); }
/// <summary> /// Registers the specified material unique identifier. /// </summary> /// <param name="textureModel">The texture model.</param> /// <param name="enableAutoGenMipMap">Enable generate mipmaps automatically</param> /// <returns></returns> public ShaderResourceViewProxy Register(TextureModel textureModel, bool enableAutoGenMipMap) { if (textureModel == null || textureModel.GetKey() == null) { return(null); } var targetDict = enableAutoGenMipMap ? resourceDictionaryMipMaps : resourceDictionaryNoMipMaps; lock (targetDict) { if (targetDict.TryGetValue(textureModel.GetKey(), out ShaderResourceViewProxy view)) { view.IncRef(); return(view); } else { var proxy = new ShaderResourceViewProxy(device); proxy.CreateView(textureModel, true, enableAutoGenMipMap); proxy.Disposed += (s, e) => { lock (targetDict) { targetDict.Remove(textureModel.GetKey()); } }; targetDict.Add(textureModel.GetKey(), proxy); return(proxy); } } }
private void DrawOutline(RenderContext context, DeviceContextProxy deviceContext, ShaderResourceViewProxy depthStencilBuffer, ShaderResourceViewProxy renderTargetFull) { var buffer = context.RenderHost.RenderBuffer; #region Do Blur Pass BindTarget(null, blurCore.CurrentRTV, deviceContext, blurCore.Width, blurCore.Height, true); blurPassVertical.PixelShader.BindSampler(deviceContext, samplerSlot, sampler); blurPassVertical.PixelShader.BindTexture(deviceContext, textureSlot, buffer.FullResPPBuffer.NextSRV); blurPassVertical.BindShader(deviceContext); blurPassVertical.BindStates(deviceContext, StateType.BlendState | StateType.RasterState | StateType.DepthStencilState); deviceContext.Draw(4, 0); blurCore.Run(deviceContext, NumberOfBlurPass, 1, 0);//Already blur once on vertical, pass 1 as initial index. #endregion #region Draw back with stencil test BindTarget(depthStencilBuffer, renderTargetFull, deviceContext, buffer.TargetWidth, buffer.TargetHeight); screenQuadPass.PixelShader.BindTexture(deviceContext, textureSlot, blurCore.CurrentSRV); screenQuadPass.BindShader(deviceContext); screenQuadPass.BindStates(deviceContext, StateType.BlendState | StateType.RasterState | StateType.DepthStencilState); deviceContext.Draw(4, 0); #endregion #region Draw outline onto original target BindTarget(null, buffer.FullResPPBuffer.CurrentRTV, deviceContext, buffer.TargetWidth, buffer.TargetHeight, false); screenOutlinePass.PixelShader.BindTexture(deviceContext, textureSlot, buffer.FullResPPBuffer.NextSRV); screenOutlinePass.BindShader(deviceContext); screenOutlinePass.BindStates(deviceContext, StateType.BlendState | StateType.RasterState | StateType.DepthStencilState); deviceContext.Draw(4, 0); screenOutlinePass.PixelShader.BindTexture(deviceContext, textureSlot, null); #endregion }
protected override void OnDetach() { MipMapLevels = 0; textureSampler = null; cubeTextureRes = null; base.OnDetach(); }
private void UpdateTexture(TextureModel texture) { var newTexture = texture == null ? null : EffectTechnique.EffectsManager.MaterialTextureManager.Register(texture); RemoveAndDispose(ref textureProxy); textureProxy = newTexture; }
/// <summary> /// Creates the 2D texture view from color array. /// </summary> /// <param name="device"></param> /// <param name="array">The array.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="createSRV"></param> /// <param name="generateMipMaps"></param> public static ShaderResourceViewProxy CreateViewFromColorArray(Device device, Color4[] array, int width, int height, bool createSRV = true, bool generateMipMaps = true) { var proxy = new ShaderResourceViewProxy(device); proxy.CreateViewFromColorArray(array, width, height, createSRV, generateMipMaps); return(proxy); }
/// <summary> /// Creates the 2D texture view from raw pixel byte array /// </summary> /// <param name="device">The device.</param> /// <param name="dataPtr">The data PTR.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="format">The format.</param> /// <param name="createSRV">if set to <c>true</c> [create SRV].</param> /// <param name="generateMipMaps"></param> /// <returns></returns> public unsafe static ShaderResourceViewProxy CreateView(Device device, IntPtr dataPtr, int width, int height, global::SharpDX.DXGI.Format format, bool createSRV = true, bool generateMipMaps = true) { var proxy = new ShaderResourceViewProxy(device); proxy.CreateView(dataPtr, width, height, format, createSRV, generateMipMaps); return(proxy); }
/// <summary> /// Called when [detach]. /// </summary> protected override void OnDetach() { DisposeBuffers(); textureSampler = null; blendState = null; textureView = null; base.OnDetach(); }
private void UpdateTexture(Stream texture) { RemoveAndDispose(ref textureProxy); if (texture != null) { textureProxy = Collect(EffectTechnique.EffectsManager.MaterialTextureManager.Register(texture)); } }
/// <summary> /// Create a texture2D based UAV /// </summary> /// <param name="device"></param> /// <param name="texture2DDesc"></param> /// <param name="uavDesc"></param> /// <param name="srvDesc"></param> public UAVBufferViewProxy(Device device, ref Texture2DDescription texture2DDesc, ref UnorderedAccessViewDescription uavDesc, ref ShaderResourceViewDescription srvDesc) { resource = new SDX11.Texture2D(device, texture2DDesc); srv = new ShaderResourceViewProxy(device, resource); srv.CreateTextureView(ref srvDesc); uav = new UnorderedAccessView(device, resource, uavDesc); }
/// <summary> /// Creates the 2D texture view from data array /// </summary> /// <typeparam name="T"></typeparam> /// <param name="device">The device.</param> /// <param name="array">The array.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="format">The format.</param> /// <param name="createSRV">if set to <c>true</c> [create SRV].</param> /// <param name="generateMipMaps"></param> /// <returns></returns> public static ShaderResourceViewProxy CreateView <T>(Device device, T[] array, int width, int height, global::SharpDX.DXGI.Format format, bool createSRV = true, bool generateMipMaps = true) where T : struct { var proxy = new ShaderResourceViewProxy(device); proxy.CreateView(array, width, height, format, createSRV, generateMipMaps); return(proxy); }
/// <summary> /// Runs the blur procedure /// </summary> /// <param name="context">The context.</param> /// <param name="deviceContext">The device context.</param> /// <param name="source">The source.</param> /// <param name="depth">The depth.</param> /// <param name="sourceViewport"></param> /// <param name="modelStruct"></param> public virtual void Run(RenderContext context, DeviceContextProxy deviceContext, ShaderResourceViewProxy source, ref ViewportF sourceViewport, BlurDepth depth, ref BorderEffectStruct modelStruct) { deviceContext.SetSampler(PixelShader.Type, samplerSlot, sampler); if ((depth & BlurDepth.One) != 0) { using (var target1 = context.GetOffScreenRT(OffScreenTextureSize.Half, global::SharpDX.DXGI.Format.R8G8B8A8_UNorm, out var width, out var height)) { modelStruct.ViewportScale = (int)OffScreenTextureSize.Half; modelCB.Upload(deviceContext, ref modelStruct); //Full -> Half Vertical deviceContext.SetRenderTarget(target1); deviceContext.SetViewport(0, 0, width, height); deviceContext.SetScissorRectangle(0, 0, width, height); screenBlurPassVertical.BindShader(deviceContext); screenBlurPassVertical.BindStates(deviceContext, StateType.All); screenBlurPassVertical.PixelShader.BindTexture(deviceContext, textureSlot, source); deviceContext.Draw(4, 0); if ((depth & BlurDepth.Two) != 0) { using (var target2 = context.GetOffScreenRT(OffScreenTextureSize.Quarter, global::SharpDX.DXGI.Format.R8G8B8A8_UNorm, out var width2, out var height2)) { // Half to Quater Vertical modelStruct.ViewportScale = (int)OffScreenTextureSize.Quarter; modelCB.Upload(deviceContext, ref modelStruct); deviceContext.SetRenderTarget(target2); deviceContext.SetViewport(0, 0, width2, height2); deviceContext.SetScissorRectangle(0, 0, width2, height2); screenBlurPassVertical.BindShader(deviceContext); screenBlurPassVertical.PixelShader.BindTexture(deviceContext, textureSlot, target1); deviceContext.Draw(4, 0); // Quater to Half Horizontal modelStruct.ViewportScale = (int)OffScreenTextureSize.Half; modelCB.Upload(deviceContext, ref modelStruct); deviceContext.SetRenderTarget(target1); deviceContext.SetViewport(0, 0, width, height); deviceContext.SetScissorRectangle(0, 0, width, height); screenBlurPassHorizontal.BindShader(deviceContext); screenBlurPassHorizontal.PixelShader.BindTexture(deviceContext, textureSlot, target2); deviceContext.Draw(4, 0); } } // Half to Full Horizontal modelStruct.ViewportScale = (int)OffScreenTextureSize.Full; modelCB.Upload(deviceContext, ref modelStruct); deviceContext.SetRenderTarget(source); deviceContext.SetViewport(ref sourceViewport); deviceContext.SetScissorRectangle(ref sourceViewport); screenBlurPassHorizontal.BindShader(deviceContext); screenBlurPassHorizontal.PixelShader.BindTexture(deviceContext, textureSlot, target1); deviceContext.Draw(4, 0); } } }
protected override void OnDetach() { width = height = 0; colorTarget = null; alphaTarget = null; colorTargetNoMSAA = null; alphaTargetNoMSAA = null; base.OnDetach(); }
/// <summary> /// Creates the view from pixel data. /// </summary> /// <param name="device">The device.</param> /// <param name="pixels">The pixels.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="depth">The depth.</param> /// <param name="format">The format.</param> /// <param name="createSRV">if set to <c>true</c> [create SRV].</param> /// <param name="generateMipMaps">if set to <c>true</c> [generate mip maps].</param> /// <returns></returns> public static ShaderResourceViewProxy CreateViewFromPixelData(Device device, Half4[] pixels, int width, int height, int depth, global::SharpDX.DXGI.Format format, bool createSRV = true, bool generateMipMaps = true) { var proxy = new ShaderResourceViewProxy(device); proxy.CreateView(pixels, width, height, depth, format, createSRV, generateMipMaps); return(proxy); }
public void UpdateGradientMap() { RemoveAndDispose(ref transferMap); if (material.TransferMap != null) { transferMap = Collect(ShaderResourceViewProxy.CreateViewFromColorArray(EffectsManager.Device, material.TransferMap)); } WriteValue(VolumeParamsStruct.HasGradientMapX, material.TransferMap != null); }
private void UpdateTexture(VolumeTextureMaterialCoreBase <T> material) { RemoveAndDispose(ref texture); texture = Collect(OnCreateTexture(material, EffectsManager)); if (texture != null) { UpdateStepSize(); } }
/// <summary> /// Called when [detach]. /// </summary> protected override void OnDetach() { DisposeBuffers(); isInitialParticleChanged = true; textureSampler = null; blendState = null; textureView = null; base.OnDetach(); }