Exemple #1
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.CreateTextureView(4, 4, (x, y) => {
                var angle = (float)(2f * Math.PI * MathUtils.Random());
                var r     = angle.Cos();
                var g     = -angle.Sin();
                var b     = (float)MathUtils.Random() * 0.01f;
                return(new Color4(r, g, b));
            });

            _effect.FxDitherMap.SetResource(_dither);
        }
Exemple #2
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.CreateTextureView(16, 16, (x, y) => {
                var angle = (float)(2f * Math.PI * MathUtils.Random());
                var r     = angle.Cos();
                var g     = -angle.Sin();
                //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);
        }