Пример #1
0
        protected override void DrawPrepare()
        {
            base.DrawPrepare();

            var effect = DeviceContextHolder.GetEffect <EffectDarkMaterial>();

            var center = ReflectionCubemapPosition;

            if (EffectDarkMaterial.EnableShadows && _previousShadowsTarget != center)
            {
                _previousShadowsTarget = center;
                _shadows.Update(-_light, center);
                _shadows.DrawScene(DeviceContextHolder, this);

                effect.FxShadowMaps.SetResourceArray(_shadows.Splits.Take(EffectDarkMaterial.NumSplits).Select(x => x.View).ToArray());
                effect.FxShadowViewProj.SetMatrixArray(
                    _shadows.Splits.Take(EffectDarkMaterial.NumSplits).Select(x => x.ShadowTransform).ToArray());
            }

            if (CubemapReflection && _reflectionCubemap.Update(center))
            {
                _reflectionCubemap.DrawScene(DeviceContextHolder, this);
                effect.FxReflectionCubemap.SetResource(_reflectionCubemap.View);
            }

            effect.FxEyePosW.Set(ActualCamera.Position);
            effect.FxLightDir.Set(_light);
        }
        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 DrawTransparent()
        {
            var effect = DeviceContextHolder.GetEffect <EffectDeferredGObject>();

            effect.FxReflectionCubemap.SetResource(_reflectionCubemap.View);
            effect.FxEyePosW.Set(Camera.Position);

            DeviceContext.OutputMerger.SetTargets(_gDepthBuffer.DepthView, _temporaryBuffer1.TargetView);
            DeviceContext.OutputMerger.BlendState = DeviceContextHolder.States.TransparentBlendState;
            Scene.Draw(DeviceContextHolder, Camera, SpecialRenderMode.DeferredTransparentDepth);

            DeviceContext.OutputMerger.DepthStencilState = DeviceContextHolder.States.ReadOnlyDepthState;
            Scene.Draw(DeviceContextHolder, Camera, SpecialRenderMode.DeferredTransparentForw);
            DeviceContext.OutputMerger.DepthStencilState = null;
            DeviceContext.OutputMerger.BlendState        = null;

            DeviceContext.OutputMerger.SetTargets(_gDepthBuffer.DepthView, _gBufferBase.TargetView, _gBufferNormal.TargetView, _gBufferMaps.TargetView);
            DeviceContext.OutputMerger.DepthStencilState = DeviceContextHolder.States.LessEqualDepthState;
            Scene.Draw(DeviceContextHolder, Camera, SpecialRenderMode.DeferredTransparentDef);

            DrawLights(_temporaryBuffer0);
            if (UseLocalReflections)
            {
                DrawReflections(_temporaryBuffer3, BlurLocalReflections ? _temporaryBuffer2 : null, _temporaryBuffer0);
            }

            CombineResult(_temporaryBuffer2, _temporaryBuffer0, UseLocalReflections ? _temporaryBuffer3 : null, _temporaryBuffer1);
        }
Пример #4
0
        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
            };
        }
Пример #5
0
        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);
        }
Пример #6
0
        protected override void DrawPrepare()
        {
            base.DrawPrepare();

            var highlighted = AmbientShadowHighlight ? (IRenderableObject)CarNode?.AmbientShadowNode : SelectedObject;

            if (highlighted == null || _outlineBuffer == null)
            {
                return;
            }

            DeviceContext.ClearDepthStencilView(_outlineDepthBuffer.DepthView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1f, 0);
            DeviceContext.OutputMerger.SetTargets(_outlineDepthBuffer.DepthView);
            DeviceContext.Rasterizer.State = DeviceContextHolder.States.DoubleSidedState;

            highlighted.Draw(DeviceContextHolder, ActualCamera, SpecialRenderMode.Outline);

            DeviceContext.ClearRenderTargetView(_outlineBuffer.TargetView, Color.Transparent);
            DeviceContext.OutputMerger.SetTargets(_outlineBuffer.TargetView);

            var effect = DeviceContextHolder.GetEffect <EffectPpOutline>();

            effect.FxDepthMap.SetResource(_outlineDepthBuffer.View);
            effect.FxScreenSize.Set(new Vector4(ActualWidth, ActualHeight, 1f / ActualWidth, 1f / ActualHeight));
            DeviceContextHolder.PrepareQuad(effect.LayoutPT);
            effect.TechOutline.DrawAllPasses(DeviceContext, 6);
        }
Пример #7
0
        /// <summary>
        /// Initializes the sprite renderer so it is set up for use.
        /// </summary>
        protected void Initialize(DeviceContextHolder device)
        {
            _shader = device.GetEffect <EffectSpriteShader>();

            CreateVertexBuffer(VerticeSpriteSpecific.StrideValue, _bufferSize);
            CreateDepthStencilAndBlendState();
            RefreshViewport();
        }
Пример #8
0
 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
     });
 }
Пример #9
0
        private void InitializeBuffers()
        {
            _shadowBuffer = TargetResourceDepthTexture.Create();
            _bufferFSumm  = TargetResourceTexture.Create(Format.R32G32B32A32_Float);
            _bufferF1     = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);
            _bufferF2     = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);
            _bufferA      = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);

            _summBlendState = Device.CreateBlendState(new RenderTargetBlendDescription {
                BlendEnable           = true,
                SourceBlend           = BlendOption.One,
                DestinationBlend      = BlendOption.One,
                BlendOperation        = BlendOperation.Add,
                SourceBlendAlpha      = BlendOption.One,
                DestinationBlendAlpha = BlendOption.One,
                BlendOperationAlpha   = BlendOperation.Add,
                RenderTargetWriteMask = ColorWriteMaskFlags.All,
            });

            _bakedBlendState = Device.CreateBlendState(new RenderTargetBlendDescription {
                BlendEnable           = true,
                SourceBlend           = BlendOption.One,
                DestinationBlend      = BlendOption.One,
                BlendOperation        = BlendOperation.Maximum,
                SourceBlendAlpha      = BlendOption.One,
                DestinationBlendAlpha = BlendOption.One,
                BlendOperationAlpha   = BlendOperation.Maximum,
                RenderTargetWriteMask = ColorWriteMaskFlags.All,
            });

            _effect = DeviceContextHolder.GetEffect <EffectSpecialShadow>();

            _rasterizerStateFrontCull = RasterizerState.FromDescription(Device, new RasterizerStateDescription {
                CullMode = CullMode.Front,
                FillMode = FillMode.Solid,
                IsAntialiasedLineEnabled = false,
                IsDepthClipEnabled       = true,
                DepthBias            = (int)(100 * ShadowBiasCullFront),
                DepthBiasClamp       = 0.0f,
                SlopeScaledDepthBias = ShadowBiasCullFront
            });

            _rasterizerStateBackCull = RasterizerState.FromDescription(Device, new RasterizerStateDescription {
                CullMode = CullMode.Back,
                FillMode = FillMode.Solid,
                IsAntialiasedLineEnabled = false,
                IsDepthClipEnabled       = true,
                DepthBias            = (int)(100 * ShadowBiasCullBack),
                DepthBiasClamp       = 0.0f,
                SlopeScaledDepthBias = ShadowBiasCullBack
            });
        }
Пример #10
0
        private void RenderUv()
        {
            var effect = DeviceContextHolder.GetEffect <EffectSpecialUv>();

            for (var x = -1f; x <= 1f; x++)
            {
                for (var y = -1f; y <= 1f; y++)
                {
                    effect.FxOffset.Set(new Vector2(x, y));
                    _carNode.Draw(DeviceContextHolder, null, SpecialRenderMode.Simple);
                }
            }
        }
Пример #11
0
        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);
        }
Пример #12
0
        protected override void InitializeInner()
        {
            _effect = DeviceContextHolder.GetEffect <EffectSpecialTrackOutline>();

            _maps = _mapFilenames.Select((x, i) => {
                var data = new MapViewData(DeviceContextHolder, x, UseAiLanes);
                if (i == 0)
                {
                    Scale *= (data.MapSize.X / data.MapSize.Y).Clamp(1f, 2f);
                }

                return(data);
            }).ToArray();

            if (LoadPreview)
            {
                if (File.Exists(_previewFilename))
                {
                    using (var preview = Texture2D.FromFile(Device, _previewFilename)) {
                        _previewSize = new Vector2(preview.Description.Width, preview.Description.Height);
                        _previewView = new ShaderResourceView(Device, preview);
                    }
                }
                else
                {
                    AcToolsLogging.Write("Not found: " + _previewFilename);
                }
            }

            _f0Buffer     = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);
            _f1Buffer     = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);
            _fBlendBuffer = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);
            _fSummBuffer  = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);
            _a0Buffer     = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);
            _a1Buffer     = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);
            _aSummBuffer  = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);

            _combineBlendState = Device.CreateBlendState(new RenderTargetBlendDescription {
                BlendEnable           = true,
                SourceBlend           = BlendOption.SourceAlpha,
                DestinationBlend      = BlendOption.InverseSourceAlpha,
                BlendOperation        = BlendOperation.Add,
                SourceBlendAlpha      = BlendOption.One,
                DestinationBlendAlpha = BlendOption.One,
                BlendOperationAlpha   = BlendOperation.Maximum,
                RenderTargetWriteMask = ColorWriteMaskFlags.All
            });
        }
Пример #13
0
 public override void OnInitialize(DeviceContextHolder holder)
 {
     _effect     = holder.GetEffect <EffectDeferredLight>();
     _sphere     = SphereObject.Create(Radius);
     _rasterizer = RasterizerState.FromDescription(holder.Device, new RasterizerStateDescription {
         CullMode                 = CullMode.Front,
         FillMode                 = FillMode.Solid,
         IsDepthClipEnabled       = true,
         IsAntialiasedLineEnabled = false
     });
     _depth = DepthStencilState.FromDescription(holder.Device, new DepthStencilStateDescription {
         DepthComparison  = Comparison.Greater,
         IsDepthEnabled   = true,
         IsStencilEnabled = false,
         DepthWriteMask   = DepthWriteMask.Zero
     });
 }
Пример #14
0
        protected override void DrawAfter()
        {
            base.DrawAfter();
            if (!AmbientShadowHighlight && SelectedObject == null || _outlineBuffer == null)
            {
                return;
            }

            var effect = DeviceContextHolder.GetEffect <EffectPpBasic>();

            DeviceContext.OutputMerger.BlendState = DeviceContextHolder.States.TransparentBlendState;
            DeviceContextHolder.PrepareQuad(effect.LayoutPT);
            effect.FxInputMap.SetResource(_outlineBuffer.View);

            DeviceContext.Rasterizer.State = null;
            DeviceContext.OutputMerger.DepthStencilState = DeviceContextHolder.States.DisabledDepthState;
            effect.TechCopy.DrawAllPasses(DeviceContext, 6);
        }
Пример #15
0
        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);
        }
Пример #16
0
        private void InitializeBuffers()
        {
            _shadowBuffer = TargetResourceDepthTexture.Create();
            _summBuffer   = TargetResourceTexture.Create(Format.R32_Float);
            _tempBuffer   = TargetResourceTexture.Create(Format.R32_Float);

            _blendState = Device.CreateBlendState(new RenderTargetBlendDescription {
                BlendEnable           = true,
                SourceBlend           = BlendOption.One,
                DestinationBlend      = BlendOption.One,
                BlendOperation        = BlendOperation.Add,
                SourceBlendAlpha      = BlendOption.SourceAlpha,
                DestinationBlendAlpha = BlendOption.InverseSourceAlpha,
                BlendOperationAlpha   = BlendOperation.Add,
                RenderTargetWriteMask = ColorWriteMaskFlags.All,
            });

            _effect = DeviceContextHolder.GetEffect <EffectSpecialShadow>();
        }
Пример #17
0
        public void OnInitialize(DeviceContextHolder holder) {
            _effect = holder.GetEffect<EffectPpHdr>();
            _blurHelper = holder.GetHelper<BlurHelper>();

            _textures = Enumerable.Range(0, DownsamplerAdaptationCycles)
                          .Select(x => TargetResourceTexture.Create(Format.R16G16B16A16_Float))
                          .ToArray();

            _averateColor = Enumerable.Range(0, 2).Select(x => {
                var t = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
                t.Resize(holder, 1, 1);
                return t;
            }).ToArray();

            _newAverageColor = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
            _newAverageColor.Resize(holder, 1, 1);

            _bloomTexture = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
            _tempTexture = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
        }
Пример #18
0
        private void RenderUv()
        {
            var effect = DeviceContextHolder.GetEffect <EffectSpecialUv>();
            var a      = new List <ToDrawAt>(1);

            for (var i = _filteredNodes.Length - 1; i >= 0; i--)
            {
                var v = _filteredNodes[i].OriginalNode.Vertices;
                var w = new List <ToDrawAt>(1);
                for (var j = v.Length - 1; j >= 0; j--)
                {
                    var t = new ToDrawAt(v[j].TexC);
                    if (!w.Contains(t))
                    {
                        w.Add(t);
                    }

                    if (w.Count >= 16)
                    {
                        break;
                    }
                }

                a.AddRange(w.ApartFrom(a).ToList());
            }

            AcToolsLogging.Write($"Affected sectors: {a.Select(x => $"[X: {x.X}, Y: {x.Y}]").JoinToString("; ")}");

            var s = Stopwatch.StartNew();

            foreach (var w in a)
            {
                effect.FxOffset.Set(new Vector2(-w.X, -w.Y - 1f));
                for (var i = _filteredNodes.Length - 1; i >= 0; i--)
                {
                    _filteredNodes[i].Draw(DeviceContextHolder, null, SpecialRenderMode.Simple);
                }
            }

            AcToolsLogging.Write($"Performance: {s.Elapsed.TotalMilliseconds / a.Count:F1} ms per sector; {a.Count} sectors; {_filteredNodes.Length} node(s)");
        }
Пример #19
0
        public void OnInitialize(DeviceContextHolder holder)
        {
            _effect     = holder.GetEffect <EffectPpHdr>();
            _blurHelper = holder.GetHelper <BlurHelper>();

            _textures = Enumerable.Range(0, DownsamplerAdaptationCycles)
                        .Select(x => TargetResourceTexture.Create(Format.R16G16B16A16_Float))
                        .ToArray();

            _averateColor = Enumerable.Range(0, 2).Select(x => {
                var t = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
                t.Resize(holder, 1, 1, null);
                return(t);
            }).ToArray();

            _newAverageColor = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
            _newAverageColor.Resize(holder, 1, 1, null);

            _bloomTexture = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
            _tempTexture  = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
        }
Пример #20
0
        protected override void InitializeInner()
        {
            base.InitializeInner();
            DeviceContextHolder.Set <IMaterialsFactory>(new MaterialsProviderDeferred());

            Scene.Add(SkyObject.Create(500f));

            foreach (var showroom in _kn5.Skip(1))
            {
                Scene.Add(new Kn5RenderableFile(showroom, Matrix.Identity));
            }

            if (_kn5.Length > 1)
            {
                _car = new DeferredRenderableCar(CarDescription.FromKn5(_kn5[0]), Matrix.Identity, shadowsHeight: 0.001f, lights: Lights)
                {
                    IsReflectable = false
                };
                Scene.Add(_car);
            }

            Scene.UpdateBoundingBox();

            Camera = new CameraOrbit(32)
            {
                Alpha  = 0.9f,
                Beta   = 0.1f,
                Radius = _car?.BoundingBox?.GetSize().Length() * 1.2f ?? 4.8f,
                Target = (_car?.BoundingBox?.GetCenter() ?? Vector3.Zero) - new Vector3(0f, 0.05f, 0f)
            };

            _resetCamera = (CameraOrbit)Camera.Clone();

            Sun = new DirectionalLight {
                Color     = FixLight(new Vector3(1.2f, 1.0f, 0.9f)) * 5f,
                Direction = Vector3.Normalize(new Vector3(-1.2f, -3.4f, -2.2f))
            };

            _effect = DeviceContextHolder.GetEffect <EffectDeferredGObject>();
        }
Пример #21
0
        public void Process(DeviceContextHolder holder, ShaderResourceView depthView, ShaderResourceView normalsView, ICamera camera, float blurMultipler,
                            TargetResourceTexture blurTemporary, RenderTargetView target)
        {
            // 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

            Draw(holder, depthView, normalsView, camera);
            _blurHelper.BlurDarkSslr(holder, BufferResult, blurTemporary, 4f * blurMultipler);
            FinalStep(holder, BufferScene.View, BufferResult.View, BufferBaseReflection.View,
                      normalsView, camera, target);
        }
Пример #22
0
        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);
        }
Пример #23
0
        public override void OnInitialize(DeviceContextHolder holder)
        {
            base.OnInitialize(holder);

            _effect = holder.GetEffect <EffectPpSsao>();

            var samplesKernel = new Vector4[EffectPpSsao.SampleCount];
            var random        = new Random(0);

            for (var i = 0; i < samplesKernel.Length; i++)
            {
                samplesKernel[i].X = (float)(random.NextDouble() * 2d - 1d);
                samplesKernel[i].Z = (float)(random.NextDouble() * 2d - 1d);
                samplesKernel[i].Y = (float)random.NextDouble();
                samplesKernel[i].Normalize();

                var scale = (float)i / samplesKernel.Length;
                scale             = (scale * scale).Lerp(0.1f, 1f);
                samplesKernel[i] *= scale;
            }

            _effect.FxSamplesKernel.Set(samplesKernel);
        }
        protected override void InitializeInner()
        {
            _deferredLighting = DeviceContextHolder.GetEffect <EffectDeferredLight>();
            _deferredResult   = DeviceContextHolder.GetEffect <EffectDeferredResult>();
            _ppBasic          = DeviceContextHolder.GetEffect <EffectPpBasic>();

            _gDepthBuffer  = TargetResourceDepthTexture.Create();
            _gBufferBase   = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
            _gBufferNormal = TargetResourceTexture.Create(Format.R32G32B32A32_Float);
            _gBufferMaps   = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);

            _temporaryDepthBuffer = TargetResourceDepthTexture.Create();
            _temporaryBuffer0     = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
            _temporaryBuffer1     = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
            _temporaryBuffer2     = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
            _temporaryBuffer3     = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
            _outputBuffer         = TargetResourceTexture.Create(Format.R8G8B8A8_UNorm);

            _reflectionCubemap = new ReflectionCubemap(1024);
            _reflectionCubemap.Initialize(DeviceContextHolder);

            _sunShadows = new ShadowsDirectional(2048);
            _sunShadows.Initialize(DeviceContextHolder);
        }
Пример #25
0
        private bool ColorGradingPass(ShaderResourceView input, RenderTargetView output, Viewport viewport)
        {
            if (ColorGradingData == null)
            {
                return(false);
            }

            if (!_colorGradingSet)
            {
                _colorGradingSet = true;

                try {
                    LoadColorGradingData();
                } catch (Exception e) {
                    AcToolsLogging.Write(e);
                }
            }

            if (_colorGradingView == null)
            {
                return(false);
            }

            if (_hdr == null)
            {
                _hdr = DeviceContextHolder.GetEffect <EffectPpHdr>();
            }

            DeviceContext.Rasterizer.SetViewports(viewport);
            DeviceContext.OutputMerger.SetTargets(output);

            _hdr.FxInputMap.SetResource(input);
            _hdr.FxColorGradingMap.SetResource(_colorGradingView);
            _hdr.TechColorGrading.DrawAllPasses(DeviceContext, 6);
            return(true);
        }
Пример #26
0
        public void Initialize(DeviceContextHolder contextHolder) {
            _effect = contextHolder.GetEffect<EffectSimpleMaterial>();

            var texturesProvider = contextHolder.Get<TexturesProvider>();
            _txDiffuse = texturesProvider.GetTexture(_filename, contextHolder);
        }
Пример #27
0
 public void OnInitialize(DeviceContextHolder holder)
 {
     _effect = holder.GetEffect <EffectPpBasic>();
 }
Пример #28
0
 public void OnInitialize(DeviceContextHolder holder) {
     _effect = holder.GetEffect<EffectPpBlur>();
 }
Пример #29
0
 public void OnInitialize(DeviceContextHolder holder)
 {
     _effect = holder.GetEffect <EffectPpDarkSslr>();
     _effect.FxNoiseMap.SetResource(holder.GetRandomTexture(16, 16));
 }
Пример #30
0
 public virtual void OnInitialize(DeviceContextHolder holder)
 {
     _blurEffect = holder.GetEffect <EffectPpAoBlur>();
 }
Пример #31
0
 public override void OnInitialize(DeviceContextHolder holder) {
     _effect = holder.GetEffect<EffectDeferredLight>();
 }
Пример #32
0
 public void Initialize(DeviceContextHolder contextHolder) {
     _effect = contextHolder.GetEffect<EffectDeferredGObjectSpecial>();
 }
Пример #33
0
 public void OnInitialize(DeviceContextHolder holder)
 {
     _effect = holder.GetEffect <EffectSpecialTrackMap>();
 }
Пример #34
0
 public void OnInitialize(DeviceContextHolder holder)
 {
     _effect        = holder.GetEffect <EffectPpDof>();
     _copyHelper    = holder.GetHelper <CopyHelper>();
     _bokehBaseView = ShaderResourceView.FromMemory(holder.Device, Resources.Bokeh);
 }
Пример #35
0
 public void Initialize(DeviceContextHolder contextHolder) {
     _effect = contextHolder.GetEffect<EffectSimpleMaterial>();
 }
Пример #36
0
 protected virtual void DrawPrepareEffect(Vector3 eyesPosition, Vector3 light, [CanBeNull] ShadowsDirectional shadows,
                                          [CanBeNull] ReflectionCubemap reflection)
 {
     DeviceContextHolder.GetEffect <EffectSimpleMaterial>().FxEyePosW.Set(ActualCamera.Position);
 }
Пример #37
0
        protected bool HdrPass(ShaderResourceView input, RenderTargetView output, Viewport viewport)
        {
            if (UseLensFlares)
            {
                // prepare effects
                if (_lensFlares == null)
                {
                    _lensFlares = DeviceContextHolder.GetEffect <EffectPpLensFlares>();
                }

                if (_hdr == null)
                {
                    _hdr = DeviceContextHolder.GetEffect <EffectPpHdr>();
                }

                if (_blur == null)
                {
                    _blur = DeviceContextHolder.GetHelper <BlurHelper>();
                }

                // filter bright areas by high threshold to downscaled buffer #1
                DeviceContext.Rasterizer.SetViewports(_bufferH1.Viewport);
                DeviceContext.OutputMerger.SetTargets(_bufferH1.TargetView);
                DeviceContext.ClearRenderTargetView(_bufferH1.TargetView, ColorTransparent);

                DeviceContextHolder.PrepareQuad(_hdr.LayoutPT);
                _hdr.FxInputMap.SetResource(input);
                _hdr.TechBloomHighThreshold.DrawAllPasses(DeviceContext, 6);

                DeviceContext.Rasterizer.SetViewports(_bufferH2.Viewport);
                DeviceContext.OutputMerger.SetTargets(_bufferH2.TargetView);
                DeviceContext.ClearRenderTargetView(_bufferH2.TargetView, ColorTransparent);

                DeviceContextHolder.PrepareQuad(_lensFlares.LayoutPT);
                _lensFlares.FxInputMap.SetResource(_bufferH1.View);
                _lensFlares.TechGhosts.DrawAllPasses(DeviceContext, 6);

                // blur bright areas from buffer #1 to itself using downscaled buffer #3 as a temporary one
                _blur.Blur(DeviceContextHolder, _bufferH2, _bufferH1, 2f, 2);

                // combine original buffer and buffer #1 with blurred bright areas to buffer #2
                DeviceContext.Rasterizer.SetViewports(viewport);
                DeviceContext.OutputMerger.SetTargets(output);

                _hdr.FxInputMap.SetResource(input);
                _hdr.FxBloomMap.SetResource(_bufferH2.View);
                GetHdrTechnique().DrawAllPasses(DeviceContext, 6);

                return(true);
            }

            if (UseBloom)
            {
                // prepare effects
                if (_hdr == null)
                {
                    _hdr = DeviceContextHolder.GetEffect <EffectPpHdr>();
                }

                if (_blur == null)
                {
                    _blur = DeviceContextHolder.GetHelper <BlurHelper>();
                }

                // filter bright areas by high threshold to downscaled buffer #1
                DeviceContext.Rasterizer.SetViewports(_bufferH1.Viewport);
                DeviceContext.OutputMerger.SetTargets(_bufferH1.TargetView);
                DeviceContext.ClearRenderTargetView(_bufferH1.TargetView, ColorTransparent);

                DeviceContextHolder.PrepareQuad(_hdr.LayoutPT);
                _hdr.FxInputMap.SetResource(input);
                _hdr.TechBloomHighThreshold.DrawAllPasses(DeviceContext, 6);

                // blur bright areas from buffer #1 to itself using downscaled buffer #3 as a temporary one
                _blur.Blur(DeviceContextHolder, _bufferH1, _bufferH2, 0.5f * BloomRadiusMultiplier, 2);

                // combine original buffer and buffer #1 with blurred bright areas to buffer #2
                DeviceContext.Rasterizer.SetViewports(viewport);
                DeviceContext.OutputMerger.SetTargets(output);

                _hdr.FxInputMap.SetResource(input);
                _hdr.FxBloomMap.SetResource(_bufferH1.View);
                GetHdrTechnique().DrawAllPasses(DeviceContext, 6);

                return(true);
            }

            if (ToneMapping != ToneMappingFn.None)
            {
                if (_hdr == null)
                {
                    _hdr = DeviceContextHolder.GetEffect <EffectPpHdr>();
                }

                DeviceContext.Rasterizer.SetViewports(viewport);
                DeviceContext.OutputMerger.SetTargets(output);
                DeviceContextHolder.PrepareQuad(_hdr.LayoutPT);

                _hdr.FxInputMap.SetResource(input);
                _hdr.FxBloomMap.SetResource(null);
                GetHdrTechnique().DrawAllPasses(DeviceContext, 6);
                return(true);
            }

            return(false);
        }
Пример #38
0
 public void OnInitialize(DeviceContextHolder holder)
 {
     _effect = holder.GetEffect <EffectPpDownsample>();
 }
Пример #39
0
 public void OnInitialize(DeviceContextHolder holder) {
     Effect = holder.GetEffect<EffectDeferredPpSslr>();
 }
        public void Initialize(DeviceContextHolder contextHolder) {
            _effect = contextHolder.GetEffect<EffectDeferredGObject>();

            var texturesProvider = contextHolder.Get<TexturesProvider>();
            _txDiffuse = texturesProvider.GetTexture(_filename, contextHolder);
        }
Пример #41
0
 public override void OnInitialize(DeviceContextHolder holder)
 {
     base.OnInitialize(holder);
     _effect = holder.GetEffect <EffectPpHbao>();
 }
Пример #42
0
 public void Initialize(DeviceContextHolder contextHolder) {
     _effect = contextHolder.GetEffect<EffectSpecialTrackMap>();
 }