public void Render(DX11RenderContext context) { Device device = context.Device; DeviceContext ctx = context.CurrentDeviceContext; //Just in case if (!this.updateddevices.Contains(context)) { this.Update(context); } if (!this.FInLayer.PluginIO.IsConnected) { return; } if (this.rendereddevices.Contains(context)) { return; } if (this.FInEnabled[0]) { if (this.BeginQuery != null) { this.BeginQuery(context); } context.CurrentDeviceContext.OutputMerger.SetTargets(new RenderTargetView[0]); settings.ViewportIndex = 0; settings.ViewportCount = 1; settings.BackBuffer = FOutBuffers[0][context]; settings.CustomSemantics = rsemantics; for (int i = 0; i < FSemantic.SliceCount; i++) { settings.RenderWidth = sizes[i]; settings.RenderHeight = sizes[i]; settings.RenderDepth = sizes[i]; if (FInResetCounter[i]) { settings.ResetCounter = true; int[] resetval = { FInResetCounterValue[i] }; var uavarray = new UnorderedAccessView[1] { FOutBuffers[i][context].UAV }; context.CurrentDeviceContext.ComputeShader.SetUnorderedAccessViews(uavarray, 0, 1, resetval); } else { settings.ResetCounter = false; } } FInLayer[0][context].Render(context, settings); EndQuery?.Invoke(context); } }
public void Update(DX11RenderContext context) { if (!init) { PluginEntry.InitHBAO(context.Device.ComPointer); PluginEntry.SetDepthParameters(FDepthIn[0][context].SRV.ComPointer, Array.ConvertAll(FProjIn[0].Values, x => (float)x), FSceneScaleIn[0]); PluginEntry.SetAoParameters(FRadiusIn[0], FBiasIn[0], FPowerExpIn[0], FSmallScaleAoIn[0], FLargeScaleAoIn[0], FStepCountIn[0], FForegroundAoIn[0], FForegroundViewDepthIn[0], FBackgroundAoIn[0], FBackgroundViewDepthIn[0], FDepthStorageIn[0], FDepthClampModeIn[0], FDepthThresholdIn[0], FDepthThresholdMaxViewDepthIn[0], FDepthThresholdSharpnessIn[0], FBlurIn[0], FBlurRadiusIn[0], FBlurSharpnessIn[0], FBlurSharpnessProfileIn[0], FBlurSharpnessProfileForegroundScaleIn[0], FBlurSharpnessProfileForegroundViewDepthIn[0], FBlurSharpnessProfileBackgroundViewDepthIn[0]); init = true; } w = FDepthIn[0][context].Width; h = FDepthIn[0][context].Height; aa = FDepthIn[0][context].Description.SampleDescription.Count; if (w != lastW || h != lastH || aa != lastAa || reset) { lastW = w; lastH = h; lastAa = aa; rt?.Dispose(); rt = new DX11RenderTarget2D(context, w, h, new SampleDescription(1, 0), Format.R8G8B8A8_UNorm); FOut[0][context] = rt; // make sure it doesn't try to run on the old depth buffer PluginEntry.SetDepthParameters(FDepthIn[0][context].SRV.ComPointer, Array.ConvertAll(FProjIn[0].Values, x => (float)x), FSceneScaleIn[0]); reset = false; } if (FProjIn.IsChanged || FSceneScaleIn.IsChanged) { PluginEntry.SetDepthParameters(FDepthIn[0][context].SRV.ComPointer, Array.ConvertAll(FProjIn[0].Values, x => (float)x), FSceneScaleIn[0]); } // uff if (FRadiusIn.IsChanged || FBiasIn.IsChanged || FPowerExpIn.IsChanged || FSmallScaleAoIn.IsChanged || FLargeScaleAoIn.IsChanged || FStepCountIn.IsChanged || FForegroundAoIn.IsChanged || FForegroundViewDepthIn.IsChanged || FBackgroundAoIn.IsChanged || FBackgroundViewDepthIn.IsChanged || FDepthStorageIn.IsChanged || FDepthClampModeIn.IsChanged || FDepthThresholdIn.IsChanged || FDepthThresholdMaxViewDepthIn.IsChanged || FDepthThresholdSharpnessIn.IsChanged || FBlurIn.IsChanged || FBlurRadiusIn.IsChanged || FBlurSharpnessIn.IsChanged || FBlurSharpnessProfileIn.IsChanged || FBlurSharpnessProfileForegroundScaleIn.IsChanged || FBlurSharpnessProfileForegroundViewDepthIn.IsChanged || FBlurSharpnessProfileBackgroundViewDepthIn.IsChanged) { PluginEntry.SetAoParameters(FRadiusIn[0], FBiasIn[0], FPowerExpIn[0], FSmallScaleAoIn[0], FLargeScaleAoIn[0], FStepCountIn[0], FForegroundAoIn[0], FForegroundViewDepthIn[0], FBackgroundAoIn[0], FBackgroundViewDepthIn[0], FDepthStorageIn[0], FDepthClampModeIn[0], FDepthThresholdIn[0], FDepthThresholdMaxViewDepthIn[0], FDepthThresholdSharpnessIn[0], FBlurIn[0], FBlurRadiusIn[0], FBlurSharpnessIn[0], FBlurSharpnessProfileIn[0], FBlurSharpnessProfileForegroundScaleIn[0], FBlurSharpnessProfileForegroundViewDepthIn[0], FBlurSharpnessProfileBackgroundViewDepthIn[0]); } BeginQuery?.Invoke(context); RenderHBAO(context.CurrentDeviceContext.ComPointer, rt.RTV.ComPointer); EndQuery?.Invoke(context); }
protected void OnEndQuery(DX11RenderContext context) { EndQuery?.Invoke(context); }
public void Update(DX11RenderContext context) { if (!FEnabled[0]) { return; } BeginQuery?.Invoke(context); if (HbaoInstances.Count != FDepthIn.SliceCount) { // TODO: dispose stuff here too? there must be a better way HbaoInstances.Clear(); for (int i = 0; i < FDepthIn.SliceCount; i++) { HbaoInstances.Add(new Dictionary <DX11RenderContext, RenderTargetHbaoContextPair>()); } } for (int i = 0; i < FDepthIn.SliceCount; i++) { RenderTargetHbaoContextPair rthcp; GfsdkHbaoContext hbao; bool isNew = false; int w = FDepthIn[0][context].Width; int h = FDepthIn[0][context].Height; int aa = FDepthIn[0][context].Description.SampleDescription.Count; if (HbaoInstances.Count < i + 1) { HbaoInstances.Add(new Dictionary <DX11RenderContext, RenderTargetHbaoContextPair>()); } if (!HbaoInstances[i].ContainsKey(context)) { rthcp = new RenderTargetHbaoContextPair { // TODO: is the 8 bpc format a limitation of the HBAO+ SDK? // TODO: changing format of the input texture seems to kill hbao+ RenderTarget = new DX11RenderTarget2D(context, w, h, new SampleDescription(1, 0), Format.R8G8B8A8_UNorm), Hbao = new GfsdkHbaoContext(context.Device), Width = w, Height = h, SampleCount = aa }; rthcp.Hbao.DepthSrv = FDepthIn[i][context].SRV; rthcp.Hbao.RenderTarget = rthcp.RenderTarget.RTV; rthcp.Hbao.SetDepthSrv(); FOut[i][context] = rthcp.RenderTarget; HbaoInstances[i].Add(context, rthcp); isNew = true; } else { rthcp = HbaoInstances[i][context]; } hbao = rthcp.Hbao; hbao.DeviceContext = context.CurrentDeviceContext; bool resChanged = w != rthcp.Width || h != rthcp.Height || aa != rthcp.SampleCount; // TODO: do we need reset here? // res change if (resChanged) { rthcp.Width = w; rthcp.Height = h; rthcp.SampleCount = aa; rthcp.RenderTarget.Dispose(); rthcp.RenderTarget = new DX11RenderTarget2D(context, w, h, new SampleDescription(1, 0), Format.R8G8B8A8_UNorm); FOut[i][context] = rthcp.RenderTarget; hbao.RenderTarget = rthcp.RenderTarget.RTV; // make sure it doesn't try to run on the old depth buffer rthcp.Hbao.DepthSrv = FDepthIn[i][context].SRV; hbao.SetDepthSrv(); if (FNormalIn[i] != null) { hbao.NormalSrv = FNormalIn[i][context].SRV; hbao.SetNormalSrv(); } } // depth parameters if (FProjIn.IsChanged || FSceneScaleIn.IsChanged || resChanged || isNew) { hbao.Projection = Array.ConvertAll(FProjIn[i].Values, x => (float)x); hbao.SceneScale = FSceneScaleIn[i]; hbao.SetDepthParameters(); } // ao parameters if (FRadiusIn.IsChanged || FBiasIn.IsChanged || FPowerExpIn.IsChanged || FSmallScaleAoIn.IsChanged || FLargeScaleAoIn.IsChanged || FStepCountIn.IsChanged || FForegroundAoIn.IsChanged || FForegroundViewDepthIn.IsChanged || FBackgroundAoIn.IsChanged || FBackgroundViewDepthIn.IsChanged || FDepthStorageIn.IsChanged || FDepthClampModeIn.IsChanged || FDepthThresholdIn.IsChanged || FDepthThresholdMaxViewDepthIn.IsChanged || FDepthThresholdSharpnessIn.IsChanged || FBlurIn.IsChanged || FBlurRadiusIn.IsChanged || FBlurSharpnessIn.IsChanged || FBlurSharpnessProfileIn.IsChanged || FBlurSharpnessProfileForegroundScaleIn.IsChanged || FBlurSharpnessProfileForegroundViewDepthIn.IsChanged || FBlurSharpnessProfileBackgroundViewDepthIn.IsChanged || resChanged || isNew) { hbao.Radius = FRadiusIn[i]; hbao.Bias = FBiasIn[i]; hbao.PowerExp = FPowerExpIn[i]; hbao.SmallScaleAo = FSmallScaleAoIn[i]; hbao.LargeScaleAo = FLargeScaleAoIn[i]; hbao.StepCount = FStepCountIn[i]; hbao.ForegroundAo = FForegroundAoIn[i]; hbao.ForegroundViewDepth = FForegroundViewDepthIn[i]; hbao.BackgroundAo = FBackgroundAoIn[i]; hbao.BackgroundViewDepth = FBackgroundViewDepthIn[i]; hbao.DepthStorage = FDepthStorageIn[i]; hbao.DepthClampMode = FDepthClampModeIn[i]; hbao.DepthThreshold = FDepthThresholdIn[i]; hbao.DepthThresholdMaxViewDepth = FDepthThresholdMaxViewDepthIn[i]; hbao.DepthThresholdSharpness = FDepthThresholdSharpnessIn[i]; hbao.Blur = FBlurIn[i]; hbao.BlurRadius = FBlurRadiusIn[i]; hbao.BlurSharpness = FBlurSharpnessIn[i]; hbao.BlurSharpnessProfile = FBlurSharpnessProfileIn[i]; hbao.BlurSharpnessProfileForegroundScale = FBlurSharpnessProfileForegroundScaleIn[i]; hbao.BlurSharpnessProfileForegroundViewDepth = FBlurSharpnessProfileForegroundViewDepthIn[i]; hbao.BlurSharpnessProfileBackgroundViewDepth = FBlurSharpnessProfileBackgroundViewDepthIn[i]; hbao.SetAoParameters(); } // normal srv if (FNormalIn[i] != null) { hbao.NormalSrv = FNormalIn[i][context].SRV; hbao.SetNormalSrv(); } // normal parameters if (FNormal.IsChanged || FNormalDecodeBiasIn.IsChanged || FNormalDecodeScaleIn.IsChanged || isNew) { hbao.Normal = FNormal[i]; hbao.View = Array.ConvertAll(FView[i].Values, x => (float)x); hbao.DecodeBias = FNormalDecodeBiasIn[i]; hbao.DecodeScale = FNormalDecodeScaleIn[i]; hbao.SetNormalParameters(); } // rendermask if (FRendermaskIn.IsChanged || isNew) { hbao.SetRenderMask(FRendermaskIn[0]); } hbao.Render(); } EndQuery?.Invoke(context); }
public void Evaluate(int SpreadMax) { this.FError.SliceCount = SpreadMax; FOutput.SliceCount = SpreadMax; ImgCache.SliceCount = SpreadMax; FOutput.Stream.IsChanged = false; if (this.FTextureIn.PluginIO.IsConnected) { if (this.RenderRequest != null) { this.RenderRequest(this, this.FHost); } if (this.AssignedContext == null) { this.FError.SliceCount = 0; return; } //Do NOT cache this, assignment done by the host FQuery[0] = this; BeginQuery?.Invoke(AssignedContext); for (int i = 0; i < SpreadMax; i++) { if (this.FTextureIn[i].Contains(this.AssignedContext) && this.FEnabled[i]) { try { if (FOutput[i] == null) { FOutput[i] = new FaceTrackerContext(); } FOutput[i].Scale = (float)FScale[i]; FOutput[i].MinNeighbors = FMinNeighbours[i]; FOutput[i].MinObjectWidth = FMinObjWidth[i]; FOutput[i].MaxObjectWidth = FMaxObjWidth[i]; FOutput[i].DoLandmarks = FDoLandmarks[i]; if (this.FTextureIn[i][this.AssignedContext].Format != Format.R8_UNorm) { FError[i] = "Texture is not R8_UNorm"; continue; } int w = this.FTextureIn[i][this.AssignedContext].Width; int h = this.FTextureIn[i][this.AssignedContext].Height; if (ImgCache[i] == null) { ImgCache[i] = new byte[w * h]; } if (ImgCache[i].Length != w * h) { ImgCache[i] = new byte[w * h]; } var texture = this.FTextureIn[0][AssignedContext]; var staging = new DX11StagingTexture2D(AssignedContext, texture.Width, texture.Height, texture.Format); staging.CopyFrom(texture); var db = staging.LockForRead(); db.Data.Read(ImgCache[i], 0, w * h); staging.UnLock(); staging.Dispose(); switch (FEngine[i]) { case FaceTrackerMode.Frontal: FOutput[i].DetectFrontal(ImgCache[i], w, h); break; case FaceTrackerMode.FrontalSurveillance: FOutput[i].DetectFrontalSurveillance(ImgCache[i], w, h); break; case FaceTrackerMode.MultiView: FOutput[i].DetectMultiView(ImgCache[i], w, h); break; case FaceTrackerMode.MultiViewReinforce: FOutput[i].DetectMultiViewReinforce(ImgCache[i], w, h); break; } this.FError[i] = ""; } catch (Exception ex) { FLogger.Log(ex); this.FError[i] = ex.Message + Environment.NewLine + ex.StackTrace; } } else { this.FError[i] = "!"; } } EndQuery?.Invoke(AssignedContext); FOutput.Stream.IsChanged = true; } else { this.FError.SliceCount = 0; } }