public void Evaluate(int SpreadMax) { if (this.FInPreset.IsChanged || this.FInState.IsChanged) { this.FOutState.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { DX11RenderState rs; if (this.FInState.PluginIO.IsConnected) { rs = this.FInState[i]; } else { rs = new DX11RenderState(); } this.AssignPreset(this.FInPreset[i].Name, rs); this.FOutState[i] = rs; } } }
public void Evaluate(int SpreadMax) { if (this.enabled.IsChanged || this.FInState.IsChanged) { this.FOutState.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { DX11RenderState rs; if (this.FInState.IsConnected) { rs = this.FInState[i].Clone(); } else { rs = new DX11RenderState(); } BlendStateDescription bs = rs.Blend; bs.AlphaToCoverageEnable = this.enabled[i]; rs.Blend = bs; this.FOutState[i] = rs; } } }
public void Evaluate(int SpreadMax) { if (this.enabled.IsChanged || this.FInState.IsChanged) { this.FOutState.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { DX11RenderState rs; if (this.FInState.IsConnected) { rs = this.FInState[i].Clone(); } else { rs = new DX11RenderState(); } RasterizerStateDescription bs = rs.Rasterizer; bs.IsDepthClipEnabled = this.enabled[i]; rs.Rasterizer = bs; this.FOutState[i] = rs; } } }
public void Render(DX11RenderContext context) { if (this.lasthandle != this.Handle) { if (this.swapchain != null) { if (this.swapchain.Contains(context)) { this.swapchain.Dispose(context); } } this.lasthandle = this.Handle; } if (!this.swapchain.Contains(context)) { this.swapchain[context] = new DX11SwapChain(context, this.Handle, SlimDX.DXGI.Format.R8G8B8A8_UNorm, new SampleDescription(1, 0), 60, 1); } if (this.resized) { this.swapchain[context].Resize(); } if (this.FEnabled[0]) { context.CurrentDeviceContext.ClearRenderTargetView(this.swapchain[context].RTV, new SlimDX.Color4(0, 0, 0, 0)); } if (this.FIn.PluginIO.IsConnected && this.FEnabled[0]) { int id = this.FIndex[0]; if (this.FIn[id].Contains(context)) { context.RenderTargetStack.Push(this.swapchain[context]); var rs = new DX11RenderState(); if (FAlpha[0]) { rs.Blend = DX11BlendStates.Instance.GetState("Blend"); context.CurrentDeviceContext.ClearRenderTargetView(this.swapchain[context].RTV, FInBgColor[0].Color); } context.RenderStateStack.Push(rs); context.CleanShaderStages(); context.Primitives.FullTriVS.GetVariableBySemantic("TEXTURE").AsResource().SetResource(this.FIn[id][context].SRV); context.Primitives.FullScreenTriangle.Bind(null); context.Primitives.ApplyFullTri(); context.Primitives.FullScreenTriangle.Draw(); context.RenderStateStack.Pop(); context.RenderTargetStack.Pop(); context.CleanUpPS(); } } }
public void Begin(SlimDX.Matrix vp, DX11RenderState shapes, DX11RenderState aabb) { this.shapesRenderState = shapes != null ? shapes : this.defaultRenderState; this.aabbRenderState = aabb != null ? aabb : this.shapesRenderState; this.solidColorShader.ApplyCamera(vp); context.RenderStateStack.Push(shapesRenderState); context.CleanShaderStages(); }
public void Evaluate(int SpreadMax) { if (this.red.IsChanged || this.green.IsChanged || this.blue.IsChanged || this.alpha.IsChanged || this.FInState.IsChanged) { this.FOutState.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { DX11RenderState rs; if (this.FInState.IsConnected) { rs = this.FInState[i].Clone(); } else { rs = new DX11RenderState(); } ColorWriteMaskFlags flag = ColorWriteMaskFlags.None; if (red[i]) { flag |= ColorWriteMaskFlags.Red; } if (green[i]) { flag |= ColorWriteMaskFlags.Green; } if (blue[i]) { flag |= ColorWriteMaskFlags.Blue; } if (alpha[i]) { flag |= ColorWriteMaskFlags.Alpha; } BlendStateDescription bs = rs.Blend; bs.RenderTargets[0].RenderTargetWriteMask = flag; rs.Blend = bs; this.FOutState[i] = rs; } } }
public void Evaluate(int SpreadMax) { if (this.FInFillMode.IsChanged || this.FInCullMode.IsChanged || this.FInDepthBias.IsChanged || this.FInDepthBiasClamp.IsChanged || this.FInDepthClipEnable.IsChanged || this.FInFrontCCW.IsChanged || this.FInLineAAEnable.IsChanged || this.FInEnableMS.IsChanged || this.FInEnableScissor.IsChanged || this.FInSlopeScaleDB.IsChanged || this.FInState.IsChanged) { this.FOutState.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { DX11RenderState rs; if (this.FInState.IsConnected) { rs = this.FInState[i].Clone(); } else { rs = new DX11RenderState(); } RasterizerStateDescription rsd = rs.Rasterizer; rsd.FillMode = this.FInFillMode[i]; rsd.CullMode = this.FInCullMode[i]; rsd.DepthBias = this.FInDepthBias[i]; rsd.DepthBiasClamp = this.FInDepthBiasClamp[i]; rsd.IsDepthClipEnabled = this.FInDepthClipEnable[i]; rsd.IsAntialiasedLineEnabled = this.FInLineAAEnable[i]; rsd.IsFrontCounterclockwise = this.FInFrontCCW[i]; rsd.IsMultisampleEnabled = this.FInEnableMS[i]; rsd.IsScissorEnabled = this.FInEnableScissor[i]; rsd.SlopeScaledDepthBias = this.FInSlopeScaleDB[i]; rs.Rasterizer = rsd; this.FOutState[i] = rs; } } }
public void Evaluate(int SpreadMax) { if (this.FInAlphaCover.IsChanged || this.FInEnable.IsChanged || this.FInBlendOp.IsChanged || this.FInBlendOpAlpha.IsChanged || this.FInWriteMask.IsChanged || this.FInSrc.IsChanged || this.FInSrcAlpha.IsChanged || this.FInDest.IsChanged || this.FInDestAlpha.IsChanged) { this.FOutState.SliceCount = SpreadMax; DX11RenderState rs; if (this.FInState.PluginIO.IsConnected) { rs = this.FInState[0].Clone(); } else { rs = new DX11RenderState(); } BlendStateDescription bs = rs.Blend; for (int i = 0; i < 8; i++) { bs.IndependentBlendEnable = true; bs.AlphaToCoverageEnable = this.FInAlphaCover[0]; bs.RenderTargets[i].BlendEnable = this.FInEnable[i]; bs.RenderTargets[i].BlendOperation = this.FInBlendOp[i]; bs.RenderTargets[i].BlendOperationAlpha = this.FInBlendOpAlpha[i]; bs.RenderTargets[i].RenderTargetWriteMask = this.FInWriteMask[i]; bs.RenderTargets[i].SourceBlend = this.FInSrc[i]; bs.RenderTargets[i].SourceBlendAlpha = this.FInSrcAlpha[i]; bs.RenderTargets[i].DestinationBlend = this.FInDest[i]; bs.RenderTargets[i].DestinationBlendAlpha = this.FInDestAlpha[i]; } rs.Blend = bs; this.FOutState[0] = rs; } }
public void Evaluate(int SpreadMax) { if (this.enabled.IsChanged || this.FInState.IsChanged) { this.FOutState.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { DX11RenderState rs; if (this.FInState.IsConnected) { rs = this.FInState[i].Clone(); } else { rs = new DX11RenderState(); } rs.Rasterizer.IsScissorEnabled = this.enabled[i]; this.FOutState[i] = rs; } } }
public void Evaluate(int SpreadMax) { if (this.FInState.IsChanged || this.FInReference.IsChanged) { this.FOutState.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { DX11RenderState rs; if (this.FInState.IsConnected) { rs = this.FInState[i].Clone(); } else { rs = new DX11RenderState(); } rs.DepthStencilReference = this.FInReference[i]; this.FOutState[i] = rs; } } }
public void Evaluate(int SpreadMax) { if (this.FMode.IsChanged || this.FInState.IsChanged) { this.FOutState.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { DX11RenderState rs; if (this.FInState.IsConnected) { rs = this.FInState[i].Clone(); } else { rs = new DX11RenderState(); } rs.Rasterizer = DX11RasterizerStates.GetState(this.FMode[i]); this.FOutState[i] = rs; } } }
public void Evaluate(int SpreadMax) { if (this.FInFactor.IsChanged || this.FInState.IsChanged) { this.FOutState.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { DX11RenderState rs; if (this.FInState.PluginIO.IsConnected) { rs = this.FInState[i].Clone(); } else { rs = new DX11RenderState(); } rs.BlendFactor = this.FInFactor[i]; this.FOutState[i] = rs; } } }
protected override DX11RenderState AssignPreset(string key, DX11RenderState statein) { statein.DepthStencil = DX11DepthStencilStates.Instance.GetState(key); return(statein); }
public void Evaluate(int SpreadMax) { if (this.mode.IsChanged || this.FInState.IsChanged) { this.FOutState.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { DX11RenderState rs; if (this.FInState.IsConnected) { rs = this.FInState[i].Clone(); } else { rs = new DX11RenderState(); } BlendStateDescription bs = rs.Blend; RenderTargetBlendDescription target = bs.RenderTargets[0]; //Note: to optimize a little, we do the following : //In any case, if blend is disabled, we enable it as otherwise modes with do nothing //Only exception is replace, if blend is disabled we leave as it is switch (mode[i]) { case AlphaOperationMode.Keep: target.BlendEnable = true; target.BlendOperation = BlendOperation.Add; target.DestinationBlendAlpha = BlendOption.One; target.SourceBlendAlpha = BlendOption.Zero; break; case AlphaOperationMode.Replace: if (target.BlendEnable) { target.BlendOperation = BlendOperation.Add; target.DestinationBlendAlpha = BlendOption.Zero; target.SourceBlendAlpha = BlendOption.One; } break; case AlphaOperationMode.Multiply: target.BlendEnable = true; target.BlendOperation = BlendOperation.Add; target.DestinationBlendAlpha = BlendOption.SourceAlpha; target.SourceBlendAlpha = BlendOption.Zero; break; case AlphaOperationMode.Interpolate: target.BlendEnable = true; target.BlendOperation = BlendOperation.Add; target.DestinationBlendAlpha = BlendOption.InverseSourceAlpha; target.SourceBlendAlpha = BlendOption.SourceAlpha; break; } bs.RenderTargets[0] = target; rs.Blend = bs; this.FOutState[i] = rs; } } }
public void Render(DX11RenderContext context) { if (this.lasthandle != this.Handle) { if (this.swapchain != null) { if (this.swapchain.Contains(context)) { this.swapchain.Dispose(context); } } this.lasthandle = this.Handle; } if (!this.swapchain.Contains(context)) { this.swapchain[context] = new DX11SwapChain(context, this.Handle, SlimDX.DXGI.Format.R8G8B8A8_UNorm, new SampleDescription(1, 0), 60, 1); } if (this.resized) { this.swapchain[context].Resize(); } if (this.FEnabled[0]) { context.CurrentDeviceContext.ClearRenderTargetView(this.swapchain[context].RTV, new SlimDX.Color4(0, 0, 0, 0)); } if (this.FIn.IsConnected && this.spreadMax > 0 && this.FEnabled[0]) { int id = this.FIndex[0]; if (this.FIn[id].Contains(context) && this.FIn[id][context] != null) { context.RenderTargetStack.Push(this.swapchain[context]); var rs = new DX11RenderState(); if (FAlpha[0]) { rs.Blend = DX11BlendStates.Instance.GetState("Blend"); context.CurrentDeviceContext.ClearRenderTargetView(this.swapchain[context].RTV, FInBgColor[0].Color); } context.RenderStateStack.Push(rs); context.CleanShaderStages(); context.Primitives.FullTriVS.GetVariableBySemantic("TEXTURE").AsResource().SetResource(this.FIn[id][context].SRV); EffectSamplerVariable samplervariable = context.Primitives.FullTriVS.GetVariableByName("linSamp").AsSampler(); SamplerState state = null; if (this.FInSamplerState.IsConnected) { state = SamplerState.FromDescription(context.Device, this.FInSamplerState[0]); samplervariable.SetSamplerState(0, state); } else { samplervariable.UndoSetSamplerState(0); } context.Primitives.FullScreenTriangle.Bind(null); context.Primitives.ApplyFullTri(); context.Primitives.FullScreenTriangle.Draw(); context.RenderStateStack.Pop(); context.RenderTargetStack.Pop(); context.CleanUpPS(); samplervariable.UndoSetSamplerState(0); //undo as can be used in other places if (state != null) { state.Dispose(); } } } }
public void Evaluate(int SpreadMax) { if (this.FInComparison.IsChanged || this.FInDepthWriteMask.IsChanged || this.FInEnableDepth.IsChanged || this.FInEnableStencil.IsChanged || this.FInState.IsChanged || this.FInBFComp.IsChanged || this.FInBFDFOp.IsChanged || this.FInBFFOp.IsChanged || this.FInBFPOp.IsChanged || this.FInFFComp.IsChanged || this.FInFFDFOp.IsChanged || this.FInFFFOp.IsChanged || this.FInFFPOp.IsChanged || this.FInStencilReadMask.IsChanged || this.FInStencilWriteMask.IsChanged) { this.FOutState.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { DX11RenderState rs; if (this.FInState.PluginIO.IsConnected) { rs = this.FInState[i]; } else { rs = new DX11RenderState(); } DepthStencilStateDescription ds = rs.DepthStencil; ds.DepthComparison = this.FInComparison[i]; ds.DepthWriteMask = this.FInDepthWriteMask[i]; ds.IsDepthEnabled = this.FInEnableDepth[i]; ds.IsStencilEnabled = this.FInEnableStencil[i]; int srm = Math.Min(255, Math.Max(this.FInStencilReadMask[i], 0)); int swm = Math.Min(255, Math.Max(this.FInStencilWriteMask[i], 0)); ds.StencilReadMask = Convert.ToByte(srm); ds.StencilWriteMask = Convert.ToByte(swm); DepthStencilOperationDescription dbf = new DepthStencilOperationDescription(); dbf.Comparison = this.FInBFComp[i]; dbf.DepthFailOperation = this.FInBFDFOp[i]; dbf.FailOperation = this.FInBFFOp[i]; dbf.PassOperation = this.FInBFPOp[i]; ds.BackFace = dbf; DepthStencilOperationDescription dff = new DepthStencilOperationDescription(); dff.Comparison = this.FInFFComp[i]; dff.DepthFailOperation = this.FInFFDFOp[i]; dff.FailOperation = this.FInFFFOp[i]; dff.PassOperation = this.FInFFPOp[i]; ds.FrontFace = dff; rs.DepthStencil = ds; this.FOutState[i] = rs; } } }
public void Update(DX11RenderContext context) { Device device = context.Device; DeviceContext ctx = context.CurrentDeviceContext; if (!this.deviceshaderdata.Contains(context)) { this.deviceshaderdata[context] = new DX11ShaderData(context, this.FShader); } if (!this.shaderVariableCache.Contains(context)) { this.shaderVariableCache[context] = new DX11ShaderVariableCache(context, this.deviceshaderdata[context].ShaderInstance, this.varmanager); } if (!this.imageShaderInfo.Contains(context)) { this.imageShaderInfo[context] = new ImageShaderInfo(this.deviceshaderdata[context].ShaderInstance); } DX11ShaderData shaderdata = this.deviceshaderdata[context]; ImageShaderInfo shaderInfo = this.imageShaderInfo[context]; context.RenderStateStack.Push(new DX11RenderState()); this.OnBeginQuery(context); //Clear shader stages shaderdata.ResetShaderStages(ctx); context.Primitives.ApplyFullTriVS(); for (int i = 0; i < this.previousFrameResults.SliceCount; i++) { if (this.FInEnabled[i] || this.FInPreserveOnDisable[i] == false) { this.previousFrameResults[i]?.UnLock(); this.previousFrameResults[i] = null; } } int wi, he; DX11ResourcePoolEntry <DX11RenderTarget2D> preservedtarget = null; renderSettings.CustomSemantics.Clear(); renderSettings.ResourceSemantics.Clear(); if (this.FInSemantics.IsConnected) { renderSettings.CustomSemantics.AddRange(this.FInSemantics.ToArray()); } if (this.FInResSemantics.IsConnected) { renderSettings.ResourceSemantics.AddRange(this.FInResSemantics.ToArray()); } for (int textureIndex = 0; textureIndex < this.spmax; textureIndex++) { int passcounter = 0; if (this.FInEnabled[textureIndex]) { List <DX11ResourcePoolEntry <DX11RenderTarget2D> > locktargets = new List <DX11ResourcePoolEntry <DX11RenderTarget2D> >(); #region Manage size DX11Texture2D initial; if (this.FIn.IsConnected) { if (this.FInUseDefaultSize[0]) { if (this.FIn[textureIndex].Contains(context) && this.FIn[textureIndex][context] != null) { initial = this.FIn[textureIndex][context]; } else { initial = context.DefaultTextures.WhiteTexture; } wi = (int)this.FInSize[0].X; he = (int)this.FInSize[0].Y; } else { initial = this.FIn[textureIndex].Contains(context) ? this.FIn[textureIndex][context] : null; if (initial != null) { wi = initial.Width; he = initial.Height; } else { initial = context.DefaultTextures.WhiteTexture; wi = (int)this.FInSize[textureIndex].X; he = (int)this.FInSize[textureIndex].Y; } } } else { initial = context.DefaultTextures.WhiteTexture; wi = (int)this.FInSize[textureIndex].X; he = (int)this.FInSize[textureIndex].Y; } #endregion renderSettings.RenderWidth = wi; renderSettings.RenderHeight = he; this.varmanager.SetGlobalSettings(shaderdata.ShaderInstance, renderSettings); var variableCache = this.shaderVariableCache[context]; variableCache.ApplyGlobals(renderSettings); DX11ResourcePoolEntry <DX11RenderTarget2D> lasttmp = null; List <DX11Texture2D> rtlist = new List <DX11Texture2D>(); //Go trough all passes int tid = this.FInTechnique[textureIndex].Index; ImageShaderTechniqueInfo techniqueInfo = shaderInfo.GetTechniqueInfo(tid); //Now we need to add optional extra pass in case we want mip chain (only in case it's not needed, if texture has mips we just ignore) if (techniqueInfo.WantMips) { //Single level and bigger than 1 should get a mip generation pass if (initial.Width > 1 && initial.Height > 1 && initial.Resource.Description.MipLevels == 1) { //Texture might now be an allowed render target format, so we at least need to check that, and default to rgba8 unorm //also check for auto mip map gen var mipTargetFmt = initial.Format; if (!context.IsSupported(FormatSupport.RenderTarget, mipTargetFmt) || !context.IsSupported(FormatSupport.MipMapAutoGeneration, mipTargetFmt) || !context.IsSupported(FormatSupport.UnorderedAccessView, mipTargetFmt)) { mipTargetFmt = Format.R8G8B8A8_UNorm; } DX11ResourcePoolEntry <DX11RenderTarget2D> mipTarget = context.ResourcePool.LockRenderTarget(initial.Width, initial.Height, mipTargetFmt, new SampleDescription(1, 0), true, 0); locktargets.Add(mipTarget); context.RenderTargetStack.Push(mipTarget.Element); context.BasicEffects.PointSamplerPixelPass.Apply(initial.SRV); context.CurrentDeviceContext.Draw(3, 0); context.RenderTargetStack.Pop(); context.CurrentDeviceContext.GenerateMips(mipTarget.Element.SRV); //Replace initial by our new texture initial = mipTarget.Element; } } //Bind Initial (once only is ok) and mark for previous usage too DX11Texture2D lastrt = initial; shaderInfo.ApplyInitial(initial.SRV); for (int passIndex = 0; passIndex < techniqueInfo.PassCount; passIndex++) { ImageShaderPassInfo passInfo = techniqueInfo.GetPassInfo(passIndex); bool isLastPass = passIndex == techniqueInfo.PassCount - 1; Format fmt = initial.Format; if (passInfo.CustomFormat) { fmt = passInfo.Format; } bool mips = passInfo.Mips || (isLastPass && FInMipLastPass[textureIndex]); int w, h; if (passIndex == 0) { h = he; w = wi; } else { h = passInfo.Reference == ImageShaderPassInfo.eImageScaleReference.Initial ? he : lastrt.Height; w = passInfo.Reference == ImageShaderPassInfo.eImageScaleReference.Initial ? wi : lastrt.Width; } if (passInfo.DoScale) { if (passInfo.Absolute) { w = Convert.ToInt32(passInfo.ScaleVector.X); h = Convert.ToInt32(passInfo.ScaleVector.Y); } else { w = Convert.ToInt32((float)w * passInfo.ScaleVector.X); h = Convert.ToInt32((float)h * passInfo.ScaleVector.Y); } w = Math.Max(w, 1); h = Math.Max(h, 1); } //Check format support for render target, and default to rgb8 if not if (!context.IsSupported(FormatSupport.RenderTarget, fmt)) { fmt = Format.R8G8B8A8_UNorm; } //To avoid uav issue if (fmt == Format.B8G8R8A8_UNorm) { fmt = Format.R8G8B8A8_UNorm; } DX11ResourcePoolEntry <DX11RenderTarget2D> elem; if (preservedtarget != null) { elem = preservedtarget; } else { elem = context.ResourcePool.LockRenderTarget(w, h, fmt, new SampleDescription(1, 0), mips, 0); locktargets.Add(elem); } DX11RenderTarget2D rt = elem.Element; if (this.FDepthIn.IsConnected && passInfo.UseDepth) { context.RenderTargetStack.Push(this.FDepthIn[0][context], true, elem.Element); } else { context.RenderTargetStack.Push(elem.Element); } if (passInfo.Clear) { elem.Element.Clear(new Color4(0, 0, 0, 0)); } #region Check for depth/blend preset bool validdepth = false; bool validblend = false; DepthStencilStateDescription ds = new DepthStencilStateDescription(); BlendStateDescription bs = new BlendStateDescription(); if (passInfo.DepthPreset != "") { try { ds = DX11DepthStencilStates.GetState(passInfo.DepthPreset); validdepth = true; } catch { } } if (passInfo.BlendPreset != "") { try { bs = DX11BlendStates.GetState(passInfo.BlendPreset); validblend = true; } catch { } } #endregion if (validdepth || validblend) { DX11RenderState state = new DX11RenderState(); if (validdepth) { state.DepthStencil = ds; } if (validblend) { state.Blend = bs; } context.RenderStateStack.Push(state); } renderSettings.RenderWidth = w; renderSettings.RenderHeight = h; renderSettings.BackBuffer = elem.Element; //Apply settings (we do both here, as texture size semantic might ahve variableCache.ApplyGlobals(renderSettings); variableCache.ApplySlice(objectSettings, textureIndex); //Bind last render target shaderInfo.ApplyPrevious(lastrt.SRV); this.BindPassIndexSemantic(shaderdata.ShaderInstance.Effect, passIndex); if (this.FDepthIn.IsConnected) { if (this.FDepthIn[0].Contains(context)) { shaderInfo.ApplyDepth(this.FDepthIn[0][context].SRV); } } for (int list = 0; list < this.FinPrePostActions.SliceCount; list++) { if (this.FinPrePostActions[list] != null) { this.FinPrePostActions[list].OnBeginPass(context, passIndex); } } //Apply pass and draw quad passInfo.Apply(ctx); if (passInfo.ComputeData.Enabled) { passInfo.ComputeData.Dispatch(context, w, h); context.CleanUpCS(); } else { ctx.ComputeShader.Set(null); context.Primitives.FullScreenTriangle.Draw(); ctx.OutputMerger.SetTargets(this.nullrtvs); } //Generate mips if applicable if (mips) { ctx.GenerateMips(rt.SRV); } if (!passInfo.KeepTarget) { rtlist.Add(rt); lastrt = rt; lasttmp = elem; preservedtarget = null; passcounter++; } else { preservedtarget = elem; } context.RenderTargetStack.Pop(); //Apply pass result semantic if applicable (after pop) shaderInfo.ApplyPassResult(lasttmp.Element.SRV, passIndex); if (validblend || validdepth) { context.RenderStateStack.Pop(); } if (passInfo.HasState) { context.RenderStateStack.Apply(); } for (int list = 0; list < this.FinPrePostActions.SliceCount; list++) { if (this.FinPrePostActions[list] != null) { this.FinPrePostActions[list].OnEndPass(context, passIndex); } } } //Set last render target this.FOut[textureIndex][context] = lastrt; //Unlock all resources foreach (DX11ResourcePoolEntry <DX11RenderTarget2D> lt in locktargets) { lt.UnLock(); } //Keep lock on last rt, since don't want it overidden lasttmp.Lock(); this.previousFrameResults[textureIndex] = lasttmp; } else { if (this.FInPreserveOnDisable[textureIndex]) { //We kept it locked on top this.FOut[textureIndex][context] = this.previousFrameResults[textureIndex] != null ? this.previousFrameResults[textureIndex].Element : null; } else { this.FOut[textureIndex][context] = this.FIn[textureIndex][context]; } } } context.RenderStateStack.Pop(); this.OnEndQuery(context); }
protected override DX11RenderState AssignPreset(string key, DX11RenderState statein) { statein.Blend = DX11BlendStates.Instance.GetState(key); return(statein); }
public void Update(IPluginIO pin, DX11RenderContext context) { Device device = context.Device; DeviceContext ctx = context.CurrentDeviceContext; if (!this.deviceshaderdata.ContainsKey(context)) { this.deviceshaderdata.Add(context, new DX11ShaderData(context)); this.deviceshaderdata[context].SetEffect(this.FShader); } DX11ShaderData shaderdata = this.deviceshaderdata[context]; if (this.shaderupdated) { shaderdata.SetEffect(this.FShader); this.shaderupdated = false; } context.RenderStateStack.Push(new DX11RenderState()); this.OnBeginQuery(context); //Clear shader stages shaderdata.ResetShaderStages(ctx); context.Primitives.ApplyFullTriVS(); foreach (DX11ResourcePoolEntry <DX11RenderTarget2D> rt in this.lastframetargets) { rt.UnLock(); } this.lastframetargets.Clear(); DX11ObjectRenderSettings or = new DX11ObjectRenderSettings(); int wi, he; bool preserve = false; DX11ResourcePoolEntry <DX11RenderTarget2D> preservedtarget = null; for (int i = 0; i < this.spmax; i++) { int passcounter = 0; if (this.FInEnabled[i]) { List <DX11ResourcePoolEntry <DX11RenderTarget2D> > locktargets = new List <DX11ResourcePoolEntry <DX11RenderTarget2D> >(); #region Manage size DX11Texture2D initial; if (this.FIn.PluginIO.IsConnected) { if (this.FInUseDefaultSize[0]) { initial = context.DefaultTextures.WhiteTexture; wi = (int)this.FInSize[0].X; he = (int)this.FInSize[0].Y; } else { initial = this.FIn[i][context]; if (initial != null) { wi = initial.Width; he = initial.Height; } else { initial = context.DefaultTextures.WhiteTexture; wi = (int)this.FInSize[0].X; he = (int)this.FInSize[0].Y; } } } else { initial = context.DefaultTextures.WhiteTexture; wi = (int)this.FInSize[0].X; he = (int)this.FInSize[0].Y; } #endregion DX11RenderSettings r = new DX11RenderSettings(); r.RenderWidth = wi; r.RenderHeight = he; if (this.FInSemantics.PluginIO.IsConnected) { r.CustomSemantics.AddRange(this.FInSemantics.ToArray()); } if (this.FInResSemantics.PluginIO.IsConnected) { r.ResourceSemantics.AddRange(this.FInResSemantics.ToArray()); } this.varmanager.SetGlobalSettings(shaderdata.ShaderInstance, r); this.varmanager.ApplyGlobal(shaderdata.ShaderInstance); DX11Texture2D lastrt = initial; DX11ResourcePoolEntry <DX11RenderTarget2D> lasttmp = null; List <DX11Texture2D> rtlist = new List <DX11Texture2D>(); //Bind Initial (once only is ok) this.BindTextureSemantic(shaderdata.ShaderInstance.Effect, "INITIAL", initial); //Go trough all passes EffectTechnique tech = shaderdata.ShaderInstance.Effect.GetTechniqueByIndex(tid); for (int j = 0; j < tech.Description.PassCount; j++) { ImageShaderPass pi = this.varmanager.passes[j]; EffectPass pass = tech.GetPassByIndex(j); for (int kiter = 0; kiter < pi.IterationCount; kiter++) { if (passcounter > 0) { for (int pid = 0; pid < passcounter; pid++) { string pname = "PASSRESULT" + pid; this.BindTextureSemantic(shaderdata.ShaderInstance.Effect, pname, rtlist[pid]); } } Format fmt = initial.Format; if (pi.CustomFormat) { fmt = pi.Format; } bool mips = pi.Mips; int w, h; if (j == 0) { h = he; w = wi; } else { h = pi.Reference == ImageShaderPass.eImageScaleReference.Initial ? he : lastrt.Height; w = pi.Reference == ImageShaderPass.eImageScaleReference.Initial ? wi : lastrt.Width; } if (pi.DoScale) { if (pi.Absolute) { w = Convert.ToInt32(pi.ScaleVector.X); h = Convert.ToInt32(pi.ScaleVector.Y); } else { w = Convert.ToInt32((float)w * pi.ScaleVector.X); h = Convert.ToInt32((float)h * pi.ScaleVector.Y); } w = Math.Max(w, 1); h = Math.Max(h, 1); } //Check format support for render target, and default to rgb8 if not if (!context.IsSupported(FormatSupport.RenderTarget, fmt)) { fmt = Format.R8G8B8A8_UNorm; } //Since device is not capable of telling us BGR not supported if (fmt == Format.B8G8R8A8_UNorm) { fmt = Format.R8G8B8A8_UNorm; } DX11ResourcePoolEntry <DX11RenderTarget2D> elem; if (preservedtarget != null) { elem = preservedtarget; } else { elem = context.ResourcePool.LockRenderTarget(w, h, fmt, new SampleDescription(1, 0), mips, 0); locktargets.Add(elem); } DX11RenderTarget2D rt = elem.Element; if (this.FDepthIn.PluginIO.IsConnected && pi.UseDepth) { context.RenderTargetStack.Push(this.FDepthIn[0][context], true, elem.Element); } else { context.RenderTargetStack.Push(elem.Element); } if (pi.Clear) { elem.Element.Clear(new Color4(0, 0, 0, 0)); } #region Check for depth/blend preset bool validdepth = false; bool validblend = false; DepthStencilStateDescription ds = new DepthStencilStateDescription(); BlendStateDescription bs = new BlendStateDescription(); if (pi.DepthPreset != "") { try { ds = DX11DepthStencilStates.Instance.GetState(pi.DepthPreset); validdepth = true; } catch { } } if (pi.BlendPreset != "") { try { bs = DX11BlendStates.Instance.GetState(pi.BlendPreset); validblend = true; } catch { } } #endregion if (validdepth || validblend) { DX11RenderState state = new DX11RenderState(); if (validdepth) { state.DepthStencil = ds; } if (validblend) { state.Blend = bs; } context.RenderStateStack.Push(state); } r.RenderWidth = w; r.RenderHeight = h; r.BackBuffer = elem.Element; this.varmanager.ApplyGlobal(shaderdata.ShaderInstance); //Apply settings (note that textures swap is handled later) this.varmanager.ApplyPerObject(context, shaderdata.ShaderInstance, or, i); //Bind last render target this.BindTextureSemantic(shaderdata.ShaderInstance.Effect, "PREVIOUS", lastrt); this.BindPassIndexSemantic(shaderdata.ShaderInstance.Effect, j); this.BindPassIterIndexSemantic(shaderdata.ShaderInstance.Effect, kiter); if (this.FDepthIn.PluginIO.IsConnected) { if (this.FDepthIn[0].Contains(context)) { this.BindTextureSemantic(shaderdata.ShaderInstance.Effect, "DEPTHTEXTURE", this.FDepthIn[0][context]); } } //Apply pass and draw quad pass.Apply(ctx); if (pi.ComputeData.Enabled) { pi.ComputeData.Dispatch(context, w, h); context.CleanUpCS(); } else { ctx.ComputeShader.Set(null); context.Primitives.FullScreenTriangle.Draw(); ctx.OutputMerger.SetTargets(this.nullrtvs); } //Generate mips if applicable if (pi.Mips) { ctx.GenerateMips(rt.SRV); } if (!pi.KeepTarget) { preserve = false; rtlist.Add(rt); lastrt = rt; lasttmp = elem; preservedtarget = null; passcounter++; } else { preserve = true; preservedtarget = elem; } context.RenderTargetStack.Pop(); if (validblend || validdepth) { context.RenderStateStack.Pop(); } if (pi.HasState) { context.RenderStateStack.Apply(); } } } //Set last render target this.FOut[i][context] = lastrt; //Unlock all resources foreach (DX11ResourcePoolEntry <DX11RenderTarget2D> lt in locktargets) { lt.UnLock(); } //Keep lock on last rt, since don't want it overidden lasttmp.Lock(); this.lastframetargets.Add(lasttmp); } else { this.FOut[i][context] = this.FIn[i][context]; } } context.RenderStateStack.Pop(); this.OnEndQuery(context); //UnLock previous frame in applicable //if (previoustarget != null) { context.ResourcePool.Unlock(previoustarget); } }
protected abstract DX11RenderState AssignPreset(string key, DX11RenderState statein);