public void OnInitialize(DeviceContextHolder holder) { _effect = holder.GetEffect<EffectPpSmaa>(); throw new NotSupportedException(); // _areasTexMap = ShaderResourceView.FromMemory(holder.Device, Resources.AreaTexDX10); // _searchTexMap = ShaderResourceView.FromMemory(holder.Device, Resources.SearchTex); }
public override void Initialize(DeviceContextHolder contextHolder) { _material = new EffectSimpleMaterial.AlphaMaterial { Alpha = Kn5Material.GetPropertyValueAByName("alpha") }; base.Initialize(contextHolder); }
public void Draw(DeviceContextHolder holder, ShaderResourceView view, RenderTargetView target, TargetResourceTexture temporaryEdges, TargetResourceTexture temporaryBlending) { holder.PrepareQuad(_effect.LayoutPT); holder.DeviceContext.OutputMerger.BlendState = null; // edges holder.DeviceContext.OutputMerger.SetTargets(temporaryEdges.TargetView); holder.DeviceContext.ClearRenderTargetView(temporaryEdges.TargetView, new Color4(0f, 0f, 0f, 0f)); _effect.FxScreenSizeSpec.Set(new Vector4(1f / holder.Width, 1f / holder.Height, holder.Width, holder.Height)); _effect.FxInputMap.SetResource(view); _effect.TechSmaa.DrawAllPasses(holder.DeviceContext, 6); // blending holder.DeviceContext.OutputMerger.SetTargets(temporaryBlending.TargetView); holder.DeviceContext.ClearRenderTargetView(temporaryBlending.TargetView, new Color4(0f, 0f, 0f, 0f)); _effect.FxEdgesMap.SetResource(temporaryEdges.View); _effect.FxAreaTexMap.SetResource(_areasTexMap); _effect.FxSearchTexMap.SetResource(_searchTexMap); _effect.TechSmaaB.DrawAllPasses(holder.DeviceContext, 6); // final part holder.DeviceContext.OutputMerger.SetTargets(target); _effect.FxBlendMap.SetResource(temporaryBlending.View); _effect.TechSmaaN.DrawAllPasses(holder.DeviceContext, 6); }
public override void Initialize(DeviceContextHolder contextHolder) { _txNormal = Kn5Material.ShaderName.Contains("damage") ? null : GetTexture("txNormal", contextHolder); _txMaps = GetTexture("txMaps", contextHolder); _txDetails = GetTexture("txDetail", contextHolder); _txDetailsNormal = GetTexture("txNormalDetail", contextHolder); if (_txNormal != null) { Flags |= EffectSimpleMaterial.HasNormalMap; } if (Equals(Kn5Material.GetPropertyValueAByName("isAdditive"), 2.0f)) { Flags |= EffectSimpleMaterial.IsCarpaint; } if (Kn5Material.GetPropertyValueAByName("useDetail") > 0) { Flags |= EffectSimpleMaterial.HasDetailsMap; } if (Kn5Material.ShaderName.Contains("_AT")) { Flags |= EffectSimpleMaterial.UseNormalAlphaAsAlpha; } _material = new EffectSimpleMaterial.MapsMaterial { DetailsUvMultipler = Kn5Material.GetPropertyValueAByName("detailUVMultiplier"), DetailsNormalBlend = _txDetailsNormal == null ? 0f : Kn5Material.GetPropertyValueAByName("detailNormalBlend") }; base.Initialize(contextHolder); }
public override void Resize(DeviceContextHolder holder, int width, int height) { if (width == Width && height == Height) return; base.Resize(holder, width, height); TargetView = new RenderTargetView(holder.Device, Texture); View = new ShaderResourceView(holder.Device, Texture); }
public void Initialize(DeviceContextHolder contextHolder) { _effect = contextHolder.GetEffect<EffectDeferredGObject>(); if (_kn5Material == null) return; _txDiffuse = GetTexture("txDiffuse", contextHolder); _txNormal = _kn5Material.ShaderName.Contains("damage") ? null : GetTexture("txNormal", contextHolder); _txMaps = GetTexture("txMaps", contextHolder); _txDetails = GetTexture("txDetail", contextHolder); _txDetailsNormal = GetTexture("txNormalDetail", contextHolder); uint flags = 0; if (_txNormal != null) { flags |= EffectDeferredGObject.HasNormalMap; } if (_txMaps != null) { flags |= EffectDeferredGObject.HasMaps; } if (_kn5Material.GetPropertyValueAByName("useDetail") > 0) { flags |= EffectDeferredGObject.HasDetailsMap; } if (_txDetailsNormal != null) { flags |= EffectDeferredGObject.HasDetailsNormalMap; } if (_kn5Material.ShaderName == "ksTyres" || _kn5Material.ShaderName == "ksBrakeDisc") { flags |= EffectDeferredGObject.UseDiffuseAlphaAsMap; } if (IsBlending) { flags |= EffectDeferredGObject.AlphaBlend; } if (Equals(_kn5Material.GetPropertyValueAByName("isAdditive"), 1.0f)) { flags |= EffectDeferredGObject.IsAdditive; } var specularExp = _kn5Material.GetPropertyValueAByName("ksSpecularEXP"); if (Equals(_kn5Material.GetPropertyValueAByName("isAdditive"), 2.0f)) { specularExp = 250f; } _material = new EffectDeferredGObject.Material { Ambient = _kn5Material.GetPropertyValueAByName("ksAmbient"), Diffuse = _kn5Material.GetPropertyValueAByName("ksDiffuse"), Specular = _kn5Material.GetPropertyValueAByName("ksSpecular"), SpecularExp = specularExp, Emissive = _kn5Material.GetPropertyValueCByName("ksEmissive"), FresnelC = _kn5Material.GetPropertyValueAByName("fresnelC"), FresnelExp = _kn5Material.GetPropertyValueAByName("fresnelEXP"), FresnelMaxLevel = _kn5Material.GetPropertyValueAByName("fresnelMaxLevel"), DetailsUvMultipler = _kn5Material.GetPropertyValueAByName("detailUVMultiplier"), DetailsNormalBlend = _kn5Material.GetPropertyValueAByName("detailNormalBlend"), Flags = flags }; }
public bool Prepare(DeviceContextHolder contextHolder, SpecialRenderMode mode) { if (mode != SpecialRenderMode.Deferred && mode != SpecialRenderMode.Reflection) return false; _effect.FxSkyDown.Set(SkyColorLower); _effect.FxSkyRange.Set(SkyColorUpper - SkyColorLower); return true; }
private void UpdateAdaptation(DeviceContextHolder holder) { var adaptation = GetAdaptationTexture(true); holder.DeviceContext.OutputMerger.SetTargets(GetAdaptationTexture().TargetView); _effect.FxInputMap.SetResource(adaptation.View); _effect.FxBrightnessMap.SetResource(_newAverageColor.View); _effect.TechAdaptation.DrawAllPasses(holder.DeviceContext, 6); }
public override void Initialize(DeviceContextHolder contextHolder) { _material = new EffectSimpleMaterial.NmUvMultMaterial { DiffuseMultipler = Kn5Material.GetPropertyValueAByName("diffuseMult"), NormalMultipler = Kn5Material.GetPropertyValueAByName("normalMult") }; base.Initialize(contextHolder); }
public void Draw(DeviceContextHolder holder, ShaderResourceView view, RenderTargetView target) { holder.DeviceContext.OutputMerger.SetTargets(target); holder.QuadBuffers.Prepare(holder.DeviceContext, _effect.LayoutPT); _effect.FxScreenSize.Set(new Vector4(holder.Width, holder.Height, 1f / holder.Width, 1f / holder.Height)); _effect.FxInputMap.SetResource(view); _effect.TechFxaa.DrawAllPasses(holder.DeviceContext, 6); }
public void Draw(DeviceContextHolder holder, ICamera camera, SpecialLightMode mode) { if (!_initialized) { OnInitialize(holder); _initialized = true; } DrawInner(holder, camera, mode); }
public void OnResize(DeviceContextHolder holder) { var width = holder.Width; var height = holder.Height; var bloomBlur = 8f; CalculateGaussian(1f / width, 0, bloomBlur, out _hosw, out _hoso); CalculateGaussian(0, 1f / height, bloomBlur, out _vosw, out _voso); }
public Kn5RenderableList(Kn5Node node, DeviceContextHolder holder) : base(node.Name, Kn5RenderableObject.FlipByX ? node.Transform.ToMatrixFixX() : node.Transform.ToMatrix(), node.Children.Select(x => Kn5Converter.Convert(x, holder))) { OriginalNode = node; if (IsEnabled && (!OriginalNode.Active || OriginalNode.Name == "COCKPIT_LR" || OriginalNode.Name == "STEER_LR" || OriginalNode.Name == "CINTURE_ON" || OriginalNode.Name.StartsWith("DAMAGE_GLASS"))) { IsEnabled = false; } }
public bool Prepare(DeviceContextHolder contextHolder, SpecialRenderMode mode) { if (mode != SpecialRenderMode.Deferred) return false; _effect.FxDiffuseMap.SetResource(_txDiffuse); contextHolder.DeviceContext.InputAssembler.InputLayout = _effect.LayoutPT; contextHolder.DeviceContext.OutputMerger.BlendState = contextHolder.TransparentBlendState; contextHolder.DeviceContext.OutputMerger.DepthStencilState = contextHolder.LessEqualReadOnlyDepthState; return true; }
public override bool Prepare(DeviceContextHolder contextHolder, SpecialRenderMode mode) { if (mode != SpecialRenderMode.SimpleTransparent && mode != SpecialRenderMode.Simple && mode != SpecialRenderMode.Outline) return false; Effect.FxMaterial.Set(_material); Effect.FxDiffuseMap.SetResource(_txDiffuse); PrepareStates(contextHolder, mode); return true; }
public void Initialize(DeviceContextHolder holder) { throw new NotImplementedException(); //using (var cubeTex = new Texture2D(holder.Device, new Texture2DDescription { // ArraySize = 6, // BindFlags = BindFlags.ShaderResource | BindFlags.DepthStencil, // CpuAccessFlags = CpuAccessFlags.None, // Depth = 1, // Dimension = TextureDimension.TextureCube, // Format = Format.R32_Typeless, // Height = _cubeMapSize, // MipLevels = 1, // OptionFlags = ResourceOptionFlags.TextureCube, // SampleDescription = new SampleDescription(1, 0), // Usage = ResourceUsage.Default, // Width = _cubeMapSize //})) { // _targetView = Enumerable.Range(0, 6).Select(x => new RenderTargetView(holder.Device, cubeTex, // new RenderTargetViewDescription { // Format = format, // Dimension = // RenderTargetViewDimension // .Texture2DArray, // ArraySize = 1, // FirstArraySlice = x, // MipSlice = 0 // })).ToArray(); // _view = new ShaderResourceView(holder.Device, cubeTex, new ShaderResourceViewDescription { // Format = format, // Dimension = ShaderResourceViewDimension.TextureCube, // MostDetailedMip = 0, // MipLevels = -1 // }); //} //const Format depthFormat = Format.D32_Float; //using (var depthTex = new Texture2D(holder.Device, new Texture2DDescription { // Width = _cubeMapSize, // Height = _cubeMapSize, // MipLevels = 1, // ArraySize = 1, // SampleDescription = new SampleDescription(1, 0), // Format = depthFormat, // Usage = ResourceUsage.Default, // BindFlags = BindFlags.DepthStencil, // CpuAccessFlags = CpuAccessFlags.None, // OptionFlags = ResourceOptionFlags.None //})) { // _depthTargetView = new DepthStencilView(holder.Device, depthTex, new DepthStencilViewDescription { // Format = depthFormat, // Flags = DepthStencilViewFlags.None, // Dimension = DepthStencilViewDimension.Texture2D, // MipSlice = 0, // }); //} }
public override bool Prepare(DeviceContextHolder contextHolder, SpecialRenderMode mode) { if (!base.Prepare(contextHolder, mode)) return false; Effect.FxMapsMaterial.Set(_material); Effect.FxNormalMap.SetResource(_txNormal); Effect.FxDetailsMap.SetResource(_txDetails); Effect.FxDetailsNormalMap.SetResource(_txDetailsNormal); Effect.FxMapsMap.SetResource(_txMaps); return true; }
public void Draw(DeviceContextHolder contextHolder, ICamera camera, SpecialRenderMode mode) { if (!IsEnabled || mode == SpecialRenderMode.Reflection && !IsReflectable) return; if (!_initialized) { Initialize(contextHolder); _initialized = true; } DrawInner(contextHolder, camera, mode); }
public void Initialize(DeviceContextHolder contextHolder) { _effect = contextHolder.GetEffect<EffectDeferredGSky>(); _rasterizerState = RasterizerState.FromDescription(contextHolder.Device, new RasterizerStateDescription { FillMode = FillMode.Solid, CullMode = CullMode.Front, IsAntialiasedLineEnabled = false, IsFrontCounterclockwise = false, IsDepthClipEnabled = true }); }
public void Initialize(DeviceContextHolder holder) { const Format format = Format.R16G16B16A16_Float; using (var cubeTex = new Texture2D(holder.Device, new Texture2DDescription { Width = _cubeMapSize, Height = _cubeMapSize, MipLevels = 2, ArraySize = 6, SampleDescription = new SampleDescription(1, 0), Format = format, Usage = ResourceUsage.Default, BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.GenerateMipMaps | ResourceOptionFlags.TextureCube })) { _targetView = Enumerable.Range(0, 6).Select(x => new RenderTargetView(holder.Device, cubeTex, new RenderTargetViewDescription { Format = format, Dimension = RenderTargetViewDimension .Texture2DArray, ArraySize = 1, FirstArraySlice = x, MipSlice = 0 })).ToArray(); _view = new ShaderResourceView(holder.Device, cubeTex, new ShaderResourceViewDescription { Format = format, Dimension = ShaderResourceViewDimension.TextureCube, MostDetailedMip = 0, MipLevels = -1 }); } const Format depthFormat = Format.D32_Float; using (var depthTex = new Texture2D(holder.Device, new Texture2DDescription { Width = _cubeMapSize, Height = _cubeMapSize, MipLevels = 1, ArraySize = 1, SampleDescription = new SampleDescription(1, 0), Format = depthFormat, Usage = ResourceUsage.Default, BindFlags = BindFlags.DepthStencil, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None })) { _depthTargetView = new DepthStencilView(holder.Device, depthTex, new DepthStencilViewDescription { Format = depthFormat, Flags = DepthStencilViewFlags.None, Dimension = DepthStencilViewDimension.Texture2D, MipSlice = 0, }); } }
public void Draw(DeviceContextHolder contextHolder, int indices, SpecialRenderMode mode) { contextHolder.DeviceContext.Rasterizer.State = _rasterizerState; if (mode == SpecialRenderMode.Deferred) { _effect.TechSkyDeferred.DrawAllPasses(contextHolder.DeviceContext, indices); } else if (mode == SpecialRenderMode.Reflection) { _effect.TechSkyForward.DrawAllPasses(contextHolder.DeviceContext, indices); } contextHolder.DeviceContext.Rasterizer.State = null; }
public override void DrawInner(DeviceContextHolder holder, ICamera camera, SpecialLightMode mode) { _effect.FxDirectionalLightDirection.Set(Direction); _effect.FxLightColor.Set(Color); // using this instead of .Prepare() to keep DepthState — it might be special for filtering holder.QuadBuffers.PrepareInputAssembler(holder.DeviceContext, _effect.LayoutPT); (mode == SpecialLightMode.Default ? _effect.TechDirectionalLight : mode == SpecialLightMode.Shadows ? _effect.TechDirectionalLight_Shadows : mode == SpecialLightMode.ShadowsWithoutFilter ? _effect.TechDirectionalLight_Shadows_NoFilter : _effect.TechDirectionalLight_Split).DrawAllPasses(holder.DeviceContext, 6); }
public bool Prepare(DeviceContextHolder contextHolder, SpecialRenderMode mode) { switch (mode) { case SpecialRenderMode.Deferred: case SpecialRenderMode.Reflection: case SpecialRenderMode.Shadow: contextHolder.DeviceContext.InputAssembler.InputLayout = _effect.LayoutPNTG; return true; default: return false; } }
public void OnResize(DeviceContextHolder holder) { var width = holder.Width; var height = holder.Height; var i = 4 * 3; foreach (var texture in _textures) { texture.Resize(holder, Math.Max(width / i, 1), Math.Max(height / i, 1)); i *= 4; } _bloomTexture.Resize(holder, width, height); _tempTexture.Resize(holder, width, height); }
public override void Initialize(DeviceContextHolder contextHolder) { if (Equals(Kn5Material.GetPropertyValueAByName("isAdditive"), 1.0f)) { Flags |= EffectSimpleMaterial.IsAdditive; } _material = new EffectSimpleMaterial.ReflectiveMaterial { FresnelC = Kn5Material.GetPropertyValueAByName("fresnelC"), FresnelExp = Kn5Material.GetPropertyValueAByName("fresnelEXP"), FresnelMaxLevel = Kn5Material.GetPropertyValueAByName("fresnelMaxLevel") }; base.Initialize(contextHolder); }
private void UpdateNewAverateColor(DeviceContextHolder holder, ShaderResourceView view) { for (var i = 0; i <= DownsamplerAdaptationCycles; i++) { var currentRt = i == DownsamplerAdaptationCycles ? _newAverageColor : _textures[i]; holder.DeviceContext.Rasterizer.SetViewports(new Viewport(0, 0, currentRt.Width, currentRt.Height, 0.0f, 1.0f)); holder.DeviceContext.OutputMerger.SetTargets(currentRt.TargetView); _effect.FxPixel.Set(new Vector2(1f / currentRt.Width, 1f / currentRt.Height)); _effect.FxInputMap.SetResource(i == 0 ? view : _textures[i - 1].View); _effect.FxCropImage.Set(new Vector2(i == 0 ? 0.5f : 1f)); _effect.TechDownsampling.DrawAllPasses(holder.DeviceContext, 6); } }
public static IRenderableObject Convert(Kn5Node node, DeviceContextHolder holder) { switch (node.NodeClass) { case Kn5NodeClass.Base: return new Kn5RenderableList(node, holder); case Kn5NodeClass.Mesh: case Kn5NodeClass.SkinnedMesh: return new Kn5RenderableObject(node, holder); default: throw new ArgumentOutOfRangeException(); } }
public void Draw(DeviceContextHolder contextHolder, int indices, SpecialRenderMode mode) { switch (mode) { case SpecialRenderMode.Deferred: _effect.TechSpecialGlDeferred.DrawAllPasses(contextHolder.DeviceContext, indices); break; case SpecialRenderMode.Reflection: _effect.TechSpecialGlForward.DrawAllPasses(contextHolder.DeviceContext, indices); break; case SpecialRenderMode.Shadow: _effect.TechSpecialGlMask.DrawAllPasses(contextHolder.DeviceContext, indices); break; } }
public override void Initialize(DeviceContextHolder contextHolder) { base.Initialize(contextHolder); if (Kn5Material.AlphaTested) { Flags |= EffectSimpleMaterial.AlphaTest; } _txDiffuse = GetTexture("txDiffuse", contextHolder); _material = new EffectSimpleMaterial.StandartMaterial { Ambient = Kn5Material.GetPropertyValueAByName("ksAmbient"), Diffuse = Kn5Material.GetPropertyValueAByName("ksDiffuse"), Specular = Kn5Material.GetPropertyValueAByName("ksSpecular"), SpecularExp = Kn5Material.GetPropertyValueAByName("ksSpecularEXP"), Emissive = Kn5Material.GetPropertyValueCByName("ksEmissive"), Flags = Flags }; }
public override void Resize(DeviceContextHolder holder, int width, int height) { base.Resize(holder, width, height); DepthView = new DepthStencilView(holder.Device, Texture, new DepthStencilViewDescription { Flags = DepthStencilViewFlags.None, Format = Format.D24_UNorm_S8_UInt, Dimension = DepthStencilViewDimension.Texture2D, MipSlice = 0 }); View = new ShaderResourceView(holder.Device, Texture, new ShaderResourceViewDescription { Format = Format.R24_UNorm_X8_Typeless, Dimension = ShaderResourceViewDimension.Texture2D, MipLevels = 1, MostDetailedMip = 0 }); }
public override void DrawSceneForShadows(DeviceContextHolder holder, ICamera camera) { ShowroomNode?.Draw(holder, camera, SpecialRenderMode.Shadow); CarNode?.Draw(holder, camera, SpecialRenderMode.Shadow); }
private void Draw(float multipler, int size, int padding, float fadeRadius, [CanBeNull] IProgress <double> progress, CancellationToken cancellation) { DeviceContext.ClearRenderTargetView(_summBuffer.TargetView, Color.Transparent); var t = Iterations; // draw var iter = 0f; var progressReport = 0; for (var k = 0; k < t; k++) { if (++progressReport > 10) { progressReport = 0; progress?.Report((double)k / t); if (cancellation.IsCancellationRequested) { return; } } /* random distribution */ Vector3 v3; while (true) { var x = MathF.Random(-1f, 1f); var y = MathF.Random(0.1f, 1f); var z = MathF.Random(-1f, 1f); if (x.Abs() < 0.005 && z.Abs() < 0.005) { continue; } v3 = new Vector3(x, y, z); if (v3.LengthSquared() > 1f) { continue; } v3.Normalize(); if (v3.Y < 0.9f - DiffusionLevel * 0.9) { continue; } break; } DrawShadow(v3); AddShadow(-v3, ref iter); // to make it symmetrical if (v3.X.Abs() > 0.05f && k + 1 < t) { v3.X *= -1f; DrawShadow(v3); AddShadow(-v3, ref iter); k++; } } DeviceContextHolder.PrepareQuad(_effect.LayoutPT); DeviceContext.Rasterizer.State = null; DeviceContext.OutputMerger.BlendState = null; DeviceContext.Rasterizer.SetViewports(Viewport); _effect.FxSize.Set(new Vector4(Width, Height, 1f / Width, 1f / Height)); // blurring for (var i = BlurResult ? 2 : 1; i > 0; i--) { _effect.FxMultipler.Set(i > 1 ? 2f : 1f); DeviceContext.ClearRenderTargetView(_tempBuffer.TargetView, Color.Transparent); DeviceContext.OutputMerger.SetTargets(_tempBuffer.TargetView); _effect.FxInputMap.SetResource(_summBuffer.View); _effect.TechHorizontalShadowBlur.DrawAllPasses(DeviceContext, 6); DeviceContext.ClearRenderTargetView(_summBuffer.TargetView, Color.Transparent); DeviceContext.OutputMerger.SetTargets(_summBuffer.TargetView); _effect.FxInputMap.SetResource(_tempBuffer.View); _effect.TechVerticalShadowBlur.DrawAllPasses(DeviceContext, 6); } // result DeviceContext.ClearRenderTargetView(RenderTargetView, Color.Transparent); DeviceContext.OutputMerger.SetTargets(RenderTargetView); _effect.FxInputMap.SetResource(_summBuffer.View); _effect.FxCount.Set(iter / SkyBrightnessLevel); _effect.FxMultipler.Set(multipler); _effect.FxFade.Set(fadeRadius != 0f ? 10f / fadeRadius : 100f); _effect.FxPadding.Set(padding / (size + padding * 2f)); _effect.FxShadowSize.Set(new Vector2(_shadowSize.X, _shadowSize.Z)); _effect.TechResult.DrawAllPasses(DeviceContext, 6); }
public void OnResize(DeviceContextHolder holder) { _effect.FxScreenSize.Set(new Vector4(holder.Width, holder.Height, 1f / holder.Width, 1f / holder.Height)); }
public void DrawSqrt(DeviceContextHolder holder, ShaderResourceView view, RenderTargetView target) { holder.DeviceContext.OutputMerger.SetTargets(target); holder.PrepareQuad(_effect.LayoutPT); _effect.FxInputMap.SetResource(view); _effect.TechCopySqrt.DrawAllPasses(holder.DeviceContext, 6); }
public void OnInitialize(DeviceContextHolder holder) { _effect = holder.GetEffect<EffectPpBasic>(); }
protected override void InitializeInner() { _effect = DeviceContextHolder.GetEffect <EffectSpecialPiecesBlender>(); }
public void OnResize(DeviceContextHolder holder) { }
public void OnResize(DeviceContextHolder holder) { _cache.Clear(); }
public virtual void OnInitialize(DeviceContextHolder holder) { _blurEffect = holder.GetEffect <EffectPpAoBlur>(); }
public virtual void Draw(DeviceContextHolder holder, ShaderResourceView depth, ShaderResourceView normals, ICamera camera, RenderTargetView target, float aoPower) { _blurEffect.FxDepthMap.SetResource(depth); _blurEffect.FxNormalMap.SetResource(normals); }
public void Draw(DeviceContextHolder holder, ShaderResourceView view) { throw new NotSupportedException(); }
protected override void DrawSceneToBuffer() { if (!UseSslr && !UseAo) { base.DrawSceneToBuffer(); return; } DrawPrepare(); if (_sslrHelper == null) { _sslrHelper = DeviceContextHolder.GetHelper <DarkSslrHelper>(); } if (_blurHelper == null) { _blurHelper = DeviceContextHolder.GetHelper <BlurHelper>(); } // Draw scene to G-buffer to get normals, depth and base reflection DeviceContext.Rasterizer.SetViewports(Viewport); DeviceContext.OutputMerger.SetTargets(DepthStencilView, _sslrBufferBaseReflection?.TargetView, _gBufferNormals.TargetView, _gBufferDepth.TargetView); DeviceContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); DeviceContext.ClearRenderTargetView(_gBufferNormals.TargetView, (Color4) new Vector4(0.5f)); if (_sslrBufferBaseReflection != null) { DeviceContext.ClearRenderTargetView(_sslrBufferBaseReflection.TargetView, (Color4) new Vector4(0)); } DeviceContext.ClearRenderTargetView(_gBufferDepth.TargetView, (Color4) new Vector4(1f)); DeviceContext.OutputMerger.DepthStencilState = null; DeviceContext.OutputMerger.BlendState = null; DeviceContext.Rasterizer.State = null; if (ShowroomNode != null) { ShowroomNode.Draw(DeviceContextHolder, ActualCamera, SpecialRenderMode.GBuffer); } else { if (_mirror != null) { if (FlatMirror && !FlatMirrorBlurred) { _mirror.DrawReflection(DeviceContextHolder, ActualCamera, SpecialRenderMode.GBuffer); } else { _mirror.Draw(DeviceContextHolder, ActualCamera, SpecialRenderMode.GBuffer); } } } CarNode?.Draw(DeviceContextHolder, ActualCamera, SpecialRenderMode.GBuffer); // AO? if (UseAo) { var aoHelper = _aoHelper; if (aoHelper == null) { aoHelper = _aoHelper = GetAoHelper(); } if (AoType == AoType.Hbao) { UseSslr = true; SetInnerBuffer(_sslrBufferScene); DrawPreparedSceneToBuffer(); (aoHelper as HbaoHelper)?.Prepare(DeviceContextHolder, _sslrBufferScene.View); SetInnerBuffer(null); } aoHelper.Draw(DeviceContextHolder, _gBufferDepth.View, _gBufferNormals.View, ActualCamera, _aoBuffer.TargetView); aoHelper.Blur(DeviceContextHolder, _aoBuffer, InnerBuffer, Camera); var effect = Effect; effect.FxAoMap.SetResource(_aoBuffer.View); Effect.FxAoPower.Set(AoOpacity); effect.FxScreenSize.Set(new Vector4(Width, Height, 1f / Width, 1f / Height)); if (AoDebug) { DeviceContextHolder.GetHelper <CopyHelper>().Draw(DeviceContextHolder, _aoBuffer.View, InnerBuffer.TargetView); return; } } if (UseSslr && _sslrBufferBaseReflection != null) { // Draw actual scene to _sslrBufferScene SetInnerBuffer(_sslrBufferScene); DrawPreparedSceneToBuffer(); SetInnerBuffer(null); // Prepare SSLR and combine buffers #if SSLR_PARAMETRIZED if (_sslrParamsChanged) { _sslrParamsChanged = false; var effect = DeviceContextHolder.GetEffect <EffectPpDarkSslr>(); effect.FxStartFrom.Set(_sslrStartFrom); effect.FxFixMultiplier.Set(_sslrFixMultiplier); effect.FxOffset.Set(_sslrOffset); effect.FxGlowFix.Set(_sslrGrowFix); effect.FxDistanceThreshold.Set(_sslrDistanceThreshold); } #endif _sslrHelper.Draw(DeviceContextHolder, _gBufferDepth.View, _sslrBufferBaseReflection.View, _gBufferNormals.View, ActualCamera, _sslrBufferResult.TargetView); _blurHelper.BlurDarkSslr(DeviceContextHolder, _sslrBufferResult, InnerBuffer, (float)(2f * ResolutionMultiplier)); _sslrHelper.FinalStep(DeviceContextHolder, _sslrBufferScene.View, _sslrBufferResult.View, _sslrBufferBaseReflection.View, _gBufferNormals.View, ActualCamera, InnerBuffer.TargetView); } else { DrawPreparedSceneToBuffer(); } }
protected override void DrawScene() { // TODO: support more than one car? var effect = Effect; DeviceContext.OutputMerger.DepthStencilState = null; DeviceContext.OutputMerger.BlendState = null; DeviceContext.Rasterizer.State = GetRasterizerState(); var carNode = CarNode; // draw reflection if needed if (ShowroomNode == null && FlatMirror && _mirror != null) { effect.FxLightDir.Set(new Vector3(_light.X, -_light.Y, _light.Z)); if (FlatMirrorBlurred) { DeviceContext.ClearDepthStencilView(_mirrorDepthBuffer.DepthView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); DeviceContext.ClearRenderTargetView(_mirrorBuffer.TargetView, (Color4)BackgroundColor * BackgroundBrightness); DeviceContext.OutputMerger.SetTargets(_mirrorDepthBuffer.DepthView, _mirrorBuffer.TargetView); DrawMirror(); DeviceContext.Rasterizer.SetViewports(OutputViewport); if (UseFxaa) { DeviceContextHolder.GetHelper <FxaaHelper>().Draw(DeviceContextHolder, _mirrorBuffer.View, _mirrorBlurBuffer.TargetView); DeviceContextHolder.GetHelper <BlurHelper>() .BlurFlatMirror(DeviceContextHolder, _mirrorBlurBuffer, _temporaryBuffer, ActualCamera.ViewProjInvert, _mirrorDepthBuffer.View, 60f); } else { DeviceContextHolder.GetHelper <BlurHelper>() .BlurFlatMirror(DeviceContextHolder, _mirrorBuffer, _temporaryBuffer, ActualCamera.ViewProjInvert, _mirrorDepthBuffer.View, 60f, target: _mirrorBlurBuffer); } DeviceContextHolder.GetHelper <BlurHelper>() .BlurFlatMirror(DeviceContextHolder, _mirrorBlurBuffer, _temporaryBuffer, ActualCamera.ViewProjInvert, _mirrorDepthBuffer.View, 12f); DeviceContext.Rasterizer.SetViewports(Viewport); DeviceContext.OutputMerger.SetTargets(DepthStencilView, InnerBuffer.TargetView); } else { DrawMirror(); } effect.FxLightDir.Set(_light); } // draw a scene, apart from car if (ShowroomNode != null) { if (CubemapAmbient != 0f) { effect.FxCubemapAmbient.Set(0f); } DeviceContext.OutputMerger.DepthStencilState = DeviceContextHolder.States.LessEqualDepthState; ShowroomNode.Draw(DeviceContextHolder, ActualCamera, SpecialRenderMode.Simple); DeviceContext.OutputMerger.DepthStencilState = DeviceContextHolder.States.ReadOnlyDepthState; ShowroomNode.Draw(DeviceContextHolder, ActualCamera, SpecialRenderMode.SimpleTransparent); if (CubemapAmbient != 0f) { effect.FxCubemapAmbient.Set(FxCubemapAmbientValue); } } else { // draw a mirror if (_mirror != null) { if (!FlatMirror) { _mirror.SetMode(DeviceContextHolder, FlatMirrorMode.BackgroundGround); _mirror.Draw(DeviceContextHolder, ActualCamera, SpecialRenderMode.Simple); } else if (FlatMirrorBlurred && _mirrorBuffer != null) { effect.FxScreenSize.Set(new Vector4(Width, Height, 1f / Width, 1f / Height)); // _effect.FxWorldViewProjInv.SetMatrix(ActualCamera.ViewProjInvert); _mirror.SetMode(DeviceContextHolder, FlatMirrorMode.TextureMirror); _mirror.Draw(DeviceContextHolder, ActualCamera, _mirrorBlurBuffer.View, null, null); } else { _mirror.SetMode(DeviceContextHolder, FlatMirrorMode.TransparentMirror); _mirror.Draw(DeviceContextHolder, ActualCamera, SpecialRenderMode.SimpleTransparent); } } } // draw car if (carNode == null) { return; } // shadows carNode.DrawAmbientShadows(DeviceContextHolder, ActualCamera); // car itself DeviceContext.OutputMerger.DepthStencilState = DeviceContextHolder.States.LessEqualDepthState; carNode.Draw(DeviceContextHolder, ActualCamera, SpecialRenderMode.Simple); DeviceContext.OutputMerger.DepthStencilState = DeviceContextHolder.States.ReadOnlyDepthState; carNode.Draw(DeviceContextHolder, ActualCamera, SpecialRenderMode.SimpleTransparent); // debug stuff if (SuspensionDebug) { carNode.DrawSuspensionDebugStuff(DeviceContextHolder, ActualCamera); } if (carNode.IsColliderVisible) { carNode.DrawCollidersDebugStuff(DeviceContextHolder, ActualCamera); } }
public void OnInitialize(DeviceContextHolder holder) { _effect = holder.GetEffect <EffectPpDarkSslr>(); _effect.FxNoiseMap.SetResource(holder.GetRandomTexture(16, 16)); _blurHelper = holder.GetHelper <BlurHelper>(); }
protected override void InitializeInner() { DeviceContextHolder.Set <IMaterialsFactory>(new UvMaterialsFactory()); _carNode = new Kn5RenderableFile(_kn5, Matrix.Identity); }
public void Draw(DeviceContextHolder holder, ShaderResourceView view) { BlurHorizontally(holder, view); }
public override void Draw(DeviceContextHolder holder, ShaderResourceView depth, ShaderResourceView normals, ICamera camera, RenderTargetView target, float aoPower) { base.Draw(holder, depth, normals, camera, target, aoPower); // TODO: ao power! holder.PrepareQuad(_effect.LayoutPT); holder.DeviceContext.ClearRenderTargetView(_depths[0].TargetView, default(Color4)); holder.DeviceContext.ClearRenderTargetView(_depths[1].TargetView, default(Color4)); holder.DeviceContext.ClearRenderTargetView(_depths[2].TargetView, default(Color4)); holder.DeviceContext.ClearRenderTargetView(_depths[3].TargetView, default(Color4)); holder.DeviceContext.ClearRenderTargetView(_pingPong[0].TargetView, default(Color4)); holder.DeviceContext.ClearRenderTargetView(_pingPong[1].TargetView, default(Color4)); holder.DeviceContext.ClearRenderTargetView(_finalResults.TargetViews[0], default(Color4)); holder.DeviceContext.ClearRenderTargetView(_finalResults.TargetViews[1], default(Color4)); holder.DeviceContext.ClearRenderTargetView(_finalResults.TargetViews[2], default(Color4)); holder.DeviceContext.ClearRenderTargetView(_finalResults.TargetViews[3], default(Color4)); // prepare depths _effect.Fx_DepthSource.SetResource(depth); holder.DeviceContext.Rasterizer.SetViewports(new Viewport(0, 0, holder.Width / 2f, holder.Height / 2f)); holder.DeviceContext.OutputMerger.SetTargets(_depths.Select(x => x.TargetView).ToArray()); _effect.TechPrepareDepth.DrawAllPasses(holder.DeviceContext, 6); // draw stuff holder.DeviceContext.OutputMerger.SetTargets(target); /*_effect.FxDepthMap.SetResource(depth); * _effect.FxNormalMap.SetResource(normals); * * _effect.FxWorldViewProj.SetMatrix(camera.ViewProj); * _effect.FxWorldViewProjInv.SetMatrix(camera.ViewProjInvert);*/ _effect.Fx_ViewspaceDepthSource.SetResource(_depths[0].View); _effect.Fx_ViewspaceDepthSource1.SetResource(_depths[1].View); _effect.Fx_ViewspaceDepthSource2.SetResource(_depths[2].View); _effect.Fx_ViewspaceDepthSource3.SetResource(_depths[3].View); _effect.Fx_NormalmapSource.SetResource(normals); // assao var c = camera as CameraBase; if (c == null) { return; } var proj = Matrix.PerspectiveFovLH(c.FovY, c.Aspect, c.NearZValue, c.FarZValue); var view = Matrix.LookAtLH(c.Position.FlipX(), (c.Position + c.Look).FlipX(), c.Up.FlipX()); //var view = Matrix.LookAtRH(c.Position, c.Position + c.Look, c.Up); //var view = Matrix.LookAtLH(c.Position, c.Position + c.Look, c.Up); //_effect.FxProjectionMatrix.Set(proj); _effect.FxProj.SetMatrix(proj); float depthLinearizeMul = -proj.M43; // float depthLinearizeMul = ( clipFar * clipNear ) / ( clipFar - clipNear ); float depthLinearizeAdd = proj.M22; // float depthLinearizeAdd = clipFar / ( clipFar - clipNear ); // correct the handedness issue. need to make sure this below is correct, but I think it is. if (depthLinearizeMul * depthLinearizeAdd < 0) { depthLinearizeAdd = -depthLinearizeAdd; } float tanHalfFOVY = 1.0f / proj.M22; // = tanf( drawContext.Camera.GetYFOV( ) * 0.5f ); float tanHalfFOVX = 1.0F / proj.M11; // = tanHalfFOVY * drawContext.Camera.GetAspect( ); var settings = new { FadeOutFrom = 50f, FadeOutTo = 300f, HorizonAngleThreshold = 0.06f, Radius = 1.2f, QualityLevel = 2, AdaptiveQualityLimit = 0.45f, Sharpness = 0.98f, TemporalSupersamplingAngleOffset = 0f, TemporalSupersamplingRadiusOffset = 1f, DetailShadowStrength = 0.5f, }; var halfSize = 0.5f; var consts = new EffectPpAssao.ASSAOConstants { ViewportPixelSize = new Vector2(1f / holder.Width, 1f / holder.Height), HalfViewportPixelSize = new Vector2(halfSize / (holder.Width + 1), halfSize / (holder.Height + 1)), Viewport2xPixelSize = new Vector2(2f / holder.Width, 2f / holder.Height), Viewport2xPixelSize_x_025 = new Vector2(0.5f / holder.Width, 0.5f / holder.Height), DepthUnpackConsts = new Vector2(depthLinearizeMul, depthLinearizeAdd), CameraTanHalfFOV = new Vector2(tanHalfFOVX, tanHalfFOVY), NDCToViewMul = new Vector2(tanHalfFOVX * 2.0f, tanHalfFOVY * -2.0f), NDCToViewAdd = new Vector2(tanHalfFOVX * -1.0f, tanHalfFOVY * 1.0f), EffectRadius = 1.2f, EffectShadowStrength = 1f * 4.3f, EffectShadowPow = 1.5f, EffectShadowClamp = 0.98f, EffectFadeOutMul = -1.0f / (settings.FadeOutTo - settings.FadeOutFrom), EffectFadeOutAdd = settings.FadeOutFrom / (settings.FadeOutTo - settings.FadeOutFrom) + 1.0f, EffectHorizonAngleThreshold = settings.HorizonAngleThreshold.Saturate(), DepthPrecisionOffsetMod = 0.9992f }; float effectSamplingRadiusNearLimit = (settings.Radius * 1.2f); if (settings.QualityLevel == 0) { //consts.EffectShadowStrength *= 0.9f; effectSamplingRadiusNearLimit *= 1.50f; } effectSamplingRadiusNearLimit /= tanHalfFOVY; // to keep the effect same regardless of FOV consts.EffectSamplingRadiusNearLimitRec = 1.0f / effectSamplingRadiusNearLimit; consts.AdaptiveSampleCountLimit = settings.AdaptiveQualityLimit; consts.NegRecEffectRadius = -1.0f / consts.EffectRadius; var pass = 0; consts.PerPassFullResCoordOffset = new Vector2(pass % 2, pass / 2); consts.PerPassFullResUVOffset = new Vector2(((pass % 2) - 0.0f) / holder.Width, ((pass / 2) - 0.0f) / holder.Height); consts.InvSharpness = (1.0f - settings.Sharpness).Clamp(0.0f, 1.0f); consts.PassIndex = pass; consts.QuarterResPixelSize = new Vector2(0.25f / (float)holder.Width, 0.25f / (float)holder.Height); float additionalAngleOffset = settings.TemporalSupersamplingAngleOffset; // if using temporal supersampling approach (like "Progressive Rendering Using Multi-frame Sampling" from GPU Pro 7, etc.) float additionalRadiusScale = settings.TemporalSupersamplingRadiusOffset; // if using temporal supersampling approach (like "Progressive Rendering Using Multi-frame Sampling" from GPU Pro 7, etc.) const int subPassCount = 5; consts.PatternRotScaleMatrices = new Vector4[5]; for (int subPass = 0; subPass < subPassCount; subPass++) { int a = pass; int b = subPass; var spmap = new int[] { 0, 1, 4, 3, 2 }; b = spmap[subPass]; float ca, sa; float angle0 = ((float)a + (float)b / (float)subPassCount) * (3.1415926535897932384626433832795f) * 0.5f; angle0 += additionalAngleOffset; ca = angle0.Cos(); sa = angle0.Sin(); float scale = 1.0f + (a - 1.5f + (b - (subPassCount - 1.0f) * 0.5f) / (float)subPassCount) * 0.07f; scale *= additionalRadiusScale; consts.PatternRotScaleMatrices[subPass] = new Vector4(scale * ca, scale * -sa, -scale * sa, -scale * ca); } consts.NormalsUnpackMul = 1.0f; consts.NormalsUnpackAdd = 0.0f; consts.DetailAOStrength = settings.DetailShadowStrength; consts.Dummy0 = 0.0f; //consts.NormalsWorldToViewspaceMatrix = Matrix.Transpose(view); consts.NormalsWorldToViewspaceMatrix = view; _effect.Fx_ASSAOConsts.Set(consts); _effect.FxProjInv.SetMatrix(Matrix.Invert(proj)); //_effect.FxDitherScale.Set(holder.Width / 4); //_effect.FxRenderTargetResolution.Set(new Vector2(holder.Width, holder.Height)); var corners = new [] { new Vector4(-1f, -1f, 0f, 1f), new Vector4(1f, -1f, 0f, 1f), new Vector4(1f, 1f, 0f, 1f), new Vector4(-1f, 1f, 0f, 1f) }; var inverseProjection = Matrix.Invert(proj); for (var i = 0; i < 4; ++i) { corners[i] = Vector4.Transform(corners[i], inverseProjection); corners[i] /= corners[i].W; corners[i] /= corners[i].Z; } _effect.FxViewFrustumVectors.Set(corners); //_effect.FxNormalsToViewSpace.SetMatrix(Matrix.Invert(Matrix.Transpose(camera.ViewProj))); //_effect.FxNormalsToViewSpace.SetMatrix(Matrix.Invert(Matrix.Transpose(camera.Proj))); _effect.FxNormalsToViewSpace.SetMatrix(camera.View); // _effect.Fx _effect.TechAssao.DrawAllPasses(holder.DeviceContext, 6); }
protected override void ClearBuffers(DeviceContextHolder holder) { holder.DeviceContext.ClearDepthStencilView(_buffer.DepthView, DepthStencilClearFlags.Depth, 1.0f, 0); }
protected override void DrawOverride() { DeviceContext.OutputMerger.SetTargets(RenderTargetView); DeviceContextHolder.PrepareQuad(_effect.LayoutPT); _effect.TechBlend.DrawAllPasses(DeviceContextHolder.DeviceContext, 6); }
public void OnInitialize(DeviceContextHolder holder) { Effect = holder.GetEffect <EffectDeferredPpSslr>(); }
public void OnInitialize(DeviceContextHolder holder) { _effect = holder.GetEffect <EffectSpecialTrackMap>(); }