private byte[] GetBytes([CanBeNull] PaintShopSource source)
        {
            if (source == null)
            {
                return(null);
            }

            if (!source.UseInput)
            {
                if (source.Data != null)
                {
                    return(source.Data);
                }

                if (source.Name != null && MainSlot.Kn5?.TexturesData.ContainsKey(source.Name) == true)
                {
                    return(MainSlot.Kn5.TexturesData[source.Name]);
                }

                if (source.Color != null)
                {
                    using (var texture = DeviceContextHolder.CreateTexture(1, 1, (x, y) => source.Color.Value))
                        using (var stream = new MemoryStream()) {
                            Texture2D.ToStream(DeviceContext, texture, ImageFileFormat.Dds, stream);
                            return(stream.ToArray());
                        }
                }
            }

            AcToolsLogging.Write("Can’t get bytes: " + source);
            return(null);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }