private void UseEffect(Action <EffectSpecialPaintShop> fn, TargetResourceTexture tex) { if (_paintShopEffect == null) { _paintShopEffect = DeviceContextHolder.GetEffect <EffectSpecialPaintShop>(); var s = Stopwatch.StartNew(); _paintShopEffect.FxNoiseMap.SetResource(DeviceContextHolder.GetRandomTexture(OptionPaintShopRandomSize, OptionPaintShopRandomSize)); AcToolsLogging.Write($"Random texture: {s.Elapsed.TotalMilliseconds:F1} ms"); } using (DeviceContextHolder.SaveRenderTargetAndViewport()) { DeviceContextHolder.PrepareQuad(_paintShopEffect.LayoutPT); DeviceContext.Rasterizer.SetViewports(tex.Viewport); DeviceContext.OutputMerger.SetTargets(tex.TargetView); DeviceContext.ClearRenderTargetView(tex.TargetView, new Color4(0f, 0f, 0f, 0f)); DeviceContext.OutputMerger.BlendState = null; DeviceContext.OutputMerger.DepthStencilState = null; DeviceContext.Rasterizer.State = null; _paintShopEffect.FxNoiseMultipler.Set((float)Math.Max(tex.Width, tex.Height) / OptionPaintShopRandomSize); _paintShopEffect.FxSize.Set(new Vector4(tex.Width, tex.Height, 1f / tex.Width, 1f / tex.Height)); fn?.Invoke(_paintShopEffect); } }
private void PreparePcss(ShadowsDirectional shadows) { if (_pcssParamsSet) { return; } _pcssParamsSet = true; var splits = new Vector4[shadows.Splits.Length]; var sceneScale = (ShowroomNode == null ? 1f : 2f) * PcssSceneScale; var lightScale = PcssLightScale; for (var i = 0; i < shadows.Splits.Length; i++) { splits[i] = new Vector4(sceneScale / shadows.Splits[i].Size, lightScale / shadows.Splits[i].Size, 0, 0); } var effect = Effect; effect.FxPcssScale.Set(splits); if (!_pcssNoiseMapSet) { _pcssNoiseMapSet = true; effect.FxNoiseMap.SetResource(DeviceContextHolder.GetRandomTexture(16, 16)); } }
public override void OnInitialize(DeviceContextHolder holder) { base.OnInitialize(holder); // textures _depths = new[] { TargetResourceTexture.Create(Format.R16_Float), TargetResourceTexture.Create(Format.R16_Float), TargetResourceTexture.Create(Format.R16_Float), TargetResourceTexture.Create(Format.R16_Float), }; _pingPong = new[] { TargetResourceTexture.Create(Format.R8G8_UNorm), TargetResourceTexture.Create(Format.R8G8_UNorm), }; _finalResults = TargetResourceTextureArray.Create(Format.R8G8_UNorm, 4); // effect _effect = holder.GetEffect <EffectPpAssao>(); _effect.FxNoiseMap.SetResource(holder.GetRandomTexture(4, 4)); var samplesKernel = new Vector4[EffectPpSsao.SampleCount]; for (var i = 0; i < samplesKernel.Length; i++) { samplesKernel[i].X = MathUtils.Random(-1f, 1f); samplesKernel[i].Y = MathUtils.Random(-1f, 1f); //samplesKernel[i].Y = MathUtils.Random(0f, 1f); samplesKernel[i].Normalize(); //samplesKernel[i] *= 0.01f; //var scale = (float)i / samplesKernel.Length; //scale = MathUtils.Lerp(0.1f, 1f, scale * scale); //samplesKernel[i] *= scale; } // _effect.FxSampleDirections.Set(samplesKernel); _dither = holder.CreateTexture(4, 4, (x, y) => { var angle = (float)(2f * Math.PI * MathUtils.Random()); var r = MathF.Cos(angle); var g = -MathF.Sin(angle); var b = (float)MathUtils.Random() * 0.01f; return(new Color4(r, g, b)); }); _effect.FxDitherMap.SetResource(_dither); }
public override void OnInitialize(DeviceContextHolder holder) { base.OnInitialize(holder); _effect = holder.GetEffect <EffectPpHbao>(); _effect.FxNoiseMap.SetResource(holder.GetRandomTexture(4, 4)); var samplesKernel = new Vector4[EffectPpSsao.SampleCount]; for (var i = 0; i < samplesKernel.Length; i++) { samplesKernel[i].X = MathUtils.Random(-1f, 1f); samplesKernel[i].Y = MathUtils.Random(-1f, 1f); //samplesKernel[i].Y = MathUtils.Random(0f, 1f); samplesKernel[i].Normalize(); //samplesKernel[i] *= 0.01f; //var scale = (float)i / samplesKernel.Length; //scale = MathUtils.Lerp(0.1f, 1f, scale * scale); //samplesKernel[i] *= scale; } _effect.FxSampleDirections.Set(samplesKernel); _dither = holder.CreateTexture(16, 16, (x, y) => { var angle = (float)(2f * Math.PI * MathUtils.Random()); var r = MathF.Cos(angle); var g = -MathF.Sin(angle); //var b = (float)MathUtils.Random() * 1f; var b = 0.2f; return(new Color4(r, g, b)); }); /*_dither = holder.CreateTexture(16, 16, (x, y) => { * var angle = (float)(2f * Math.PI * MathUtils.Random()); * var r = MathUtils.Random(-1f, 1f); * var g = MathUtils.Random(-1f, 1f); * //var b = (float)MathUtils.Random() * 1f; * var b = 0.2f; * return new Color4(r, g, MathUtils.Random(-1f, 1f), b); * });*/ _effect.FxDitherMap.SetResource(_dither); }
protected void SetRandomValues(DeviceContextHolder holder, EffectOnlyResourceVariable texture, EffectOnlyVector4Variable size, bool accumulationMode, Vector2 targetSize) { if (_accumulationMode != accumulationMode) { _accumulationMode = accumulationMode; var randomSize = accumulationMode ? 16 : 4; texture.SetResource(holder.GetRandomTexture(randomSize, randomSize)); _randomSize = randomSize; if (!accumulationMode) { size.Set(new Vector4(targetSize.X / _randomSize, targetSize.Y / _randomSize, 0f, 0f)); } } else if (accumulationMode) { size.Set(new Vector4(targetSize.X / _randomSize, targetSize.Y / _randomSize, MathUtils.Random(0f, 1f), MathUtils.Random(0f, 1f))); } }
public override void OnInitialize(DeviceContextHolder holder) { base.OnInitialize(holder); _effect = holder.GetEffect <EffectPpSsaoAlt>(); _effect.FxNoiseMap.SetResource(holder.GetRandomTexture(4, 4)); var samplesKernel = new Vector4[EffectPpSsao.SampleCount]; for (var i = 0; i < samplesKernel.Length; i++) { samplesKernel[i].X = MathUtils.Random(-1f, 1f); samplesKernel[i].Z = MathUtils.Random(-1f, 1f); samplesKernel[i].Y = MathUtils.Random(0f, 1f); samplesKernel[i].Normalize(); var scale = (float)i / samplesKernel.Length; scale = MathUtils.Lerp(0.1f, 1f, scale * scale); samplesKernel[i] *= scale; } _effect.FxSamplesKernel.Set(samplesKernel); }
public void OnInitialize(DeviceContextHolder holder) { _effect = holder.GetEffect <EffectPpDarkSslr>(); _effect.FxNoiseMap.SetResource(holder.GetRandomTexture(16, 16)); }