Beispiel #1
0
 public EffectColorFunction(EffectFunction function, ColorSpectrum colorspectrum, int size = 1)
 {
     this.function      = function;
     this.colorspectrum = colorspectrum;
     this.size          = size;
     this.origin        = function.GetOrigin();
 }
Beispiel #2
0
    public Transform GetEffectPoint(EffectPoint point)
    {
        switch (point)
        {
        case EffectPoint.Body:
            return(Body);

        case EffectPoint.Foot:
            return(Foot);

        case EffectPoint.Head:
            return(Head);

        case EffectPoint.LeftHand:
            return(LeftHand);

        case EffectPoint.LeftWeapon:
            return(LeftWeapon);

        case EffectPoint.RightHand:
            return(RightHand);

        case EffectPoint.RightWeapon:
            return(RightWeapon);

        default:
            return(mTrans);
        }
    }
        private void RenderEffectPoint(EffectPoint effectPoint)
        {
            List <EffectBaseSettingWrap> list = null;

            if (m_activeEffectsDic.TryGetValue(effectPoint, out list) && list.Count > 0)
            {
                SetContextCommandBuffer(effectPoint);
                m_context.m_command.BeginSample(string.Format("PostProcess_{0}", effectPoint));
                var cameraTarget = new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget);
                int tmpSRT       = -1;
                tmpSRT             = RunTimeHelper.GetTemporaryRTID();
                m_context.m_source = tmpSRT;
                m_context.GetFullscreenTemporaryRT(tmpSRT, RenderTextureFormat.Default, FilterMode.Bilinear);
                //拷贝屏幕到source
                m_context.m_command.PostBlit(cameraTarget, tmpSRT);

                int tmpTRT = -1;
                if (list.Count > 1)
                {
                    tmpTRT             = RunTimeHelper.GetTemporaryRTID();
                    m_context.m_target = tmpTRT;
                    m_context.GetFullscreenTemporaryRT(tmpTRT, RenderTextureFormat.ARGB32, FilterMode.Bilinear);
                }
                else
                {
                    m_context.m_target = cameraTarget;
                }

                for (int i = 0; i < list.Count; ++i)
                {
                    var setting = list[i];
                    if (m_activeRendererDic.ContainsKey(setting.m_rendererType))
                    {
                        m_activeRendererDic[setting.m_rendererType].BaseRender(m_context, setting.m_setting);
                    }

                    //switch
                    if (i < list.Count - 1)
                    {
                        var tmp = m_context.m_target;
                        m_context.m_target = m_context.m_source;
                        m_context.m_source = tmp;
                    }
                }

                if (tmpSRT > -1)
                {
                    m_context.m_command.ReleaseTemporaryRT(tmpSRT);
                }

                if (tmpTRT > -1)
                {
                    m_context.m_command.ReleaseTemporaryRT(tmpTRT);
                }

                m_context.m_command.EndSample(string.Format("PostProcess_{0}", effectPoint));
            }
        }
        private void Awake()
        {
            m_context = new RenderContext();
            m_camera  = this.GetComponent <Camera>();
            if (m_camera.actualRenderingPath == RenderingPath.Forward && !m_camera.allowHDR)
            {
                //BuiltinRenderTextureType.CameraTarget 在Forward渲染模式下,默认渲染到backBuffer,
                //为了在CommandBuffer中获得相机内容,需要开启HDR或者设置摄像机camera.forceIntoRenderTexture 为true,
                m_camera.forceIntoRenderTexture = true;
            }

            m_opaqueCommandBuffer = new CommandBuffer()
            {
                name = "opaque cmd"
            };
            m_imageEffectCommandBuffer = new CommandBuffer()
            {
                name = "imageEffect cmd"
            };

            m_camera.AddCommandBuffer(CameraEvent.BeforeImageEffectsOpaque, m_opaqueCommandBuffer);
            m_camera.AddCommandBuffer(CameraEvent.BeforeImageEffects, m_imageEffectCommandBuffer);

            m_activeEffectsDic  = new Dictionary <EffectPoint, List <EffectBaseSettingWrap> >();
            m_activeRendererDic = new Dictionary <Type, EffectRendererBase>();
            if (m_profile != null)
            {
                foreach (var setting in m_profile.m_wraps)
                {
                    List <EffectBaseSettingWrap> list = null;
                    EffectPoint key = setting.m_effectPoint;
                    if (!m_activeEffectsDic.TryGetValue(key, out list))
                    {
                        list = new List <EffectBaseSettingWrap>();
                        m_activeEffectsDic.Add(key, list);
                    }

                    list.Add(setting);
                    EffectRendererBase renderer = null;
                    if (!m_activeRendererDic.TryGetValue(setting.m_rendererType, out renderer))
                    {
                        m_activeRendererDic.Add(setting.m_rendererType, Activator.CreateInstance(setting.m_rendererType) as EffectRendererBase);
                    }
                }
            }

            foreach (var effects in m_activeEffectsDic)
            {
                effects.Value.Sort((ea, eb) => {
                    return(ea.m_order - ea.m_order);
                });
            }

            PostProcessEffectMgr.Instance.RegisterLayer(this);
        }
Beispiel #5
0
 private void UpdateSingleEffectPoint(EffectPoint singleEffectPoint)
 {
     if (singleEffectPoint is ScaleEffectPoint)
     {
         ScaleEffectPoint effectPoint = singleEffectPoint as ScaleEffectPoint;
         TargetContainer.ScaleTo(effectPoint.NewScale, effectPoint.ProcessTime, effectPoint.EasingTypes);
     }
     else if (singleEffectPoint is ColorEffectPoint)
     {
         ColorEffectPoint effectPoint = singleEffectPoint as ColorEffectPoint;
         TargetContainer.FadeColour(effectPoint.Color, effectPoint.ProcessTime, effectPoint.EasingTypes);
     }
 }
        private void SetContextCommandBuffer(EffectPoint effectPoint)
        {
            switch (effectPoint)
            {
            case EffectPoint.BeforeTransparent:
                m_context.m_command = m_opaqueCommandBuffer;
                m_opaqueCommandBuffer.Clear();
                break;

            case EffectPoint.BeforeFinal:
                m_context.m_command = m_imageEffectCommandBuffer;
                m_imageEffectCommandBuffer.Clear();
                break;
            }
        }
Beispiel #7
0
        private void GlobalHookMouseClick(object sender, MouseEventArgs e)
        {
            if (!(Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effects_mouse_clicking)
            {
                return;
            }

            Devices.DeviceKeys device_key = Devices.DeviceKeys.Peripheral;

            if (device_key != Devices.DeviceKeys.NONE && (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effects_enabled)
            {
                EffectPoint pt = Effects.GetBitmappingFromDeviceKey(device_key).GetCenter();
                if (pt != new EffectPoint(0, 0))
                {
                    input_list.Add(CreateInputItem(device_key, pt));
                }
            }
        }
Beispiel #8
0
        private void GlobalHookKeyDown(object sender, KeyEventArgs e)
        {
            if (Utils.Time.GetMillisecondsSinceEpoch() - previoustime > 1000L)
            {
                return; //This event wasn't used for at least 1 second
            }
            if (previous_key == e.KeyCode)
            {
                return;
            }

            Devices.DeviceKeys device_key = Utils.KeyUtils.GetDeviceKey(e.KeyCode);

            if (device_key != Devices.DeviceKeys.NONE && (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effects_enabled)
            {
                EffectPoint pt = Effects.GetBitmappingFromDeviceKey(device_key).GetCenter();
                if (pt != new EffectPoint(0, 0))
                {
                    input_list.Add(CreateInputItem(device_key, pt));
                    previous_key = e.KeyCode;
                }
            }
        }
Beispiel #9
0
        private input_item CreateInputItem(Devices.DeviceKeys key, EffectPoint origin)
        {
            Color primary_c   = (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_primary_color;
            Color secondary_c = (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_secondary_color;

            if ((Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effects_random_primary_color)
            {
                primary_c = Utils.ColorUtils.GenerateRandomColor(primary_c);
            }

            if ((Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effects_random_secondary_color)
            {
                secondary_c = Utils.ColorUtils.GenerateRandomColor(secondary_c);
            }

            AnimationMix anim_mix = new AnimationMix();

            if ((Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_type == InteractiveEffects.Wave)
            {
                AnimationTrack wave = new AnimationTrack("Wave effect", 1.0f);
                wave.SetFrame(0.0f,
                              new AnimationCircle(origin.ToPointF(), 0, primary_c, (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_width)
                              );
                wave.SetFrame(0.80f,
                              new AnimationCircle(origin.ToPointF(), Effects.canvas_width * 0.80f, secondary_c, (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_width)
                              );
                wave.SetFrame(1.00f,
                              new AnimationCircle(origin.ToPointF(), Effects.canvas_width, Color.FromArgb(0, secondary_c), (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_width)
                              );
                anim_mix.AddTrack(wave);
            }
            else if ((Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_type == InteractiveEffects.Wave_Filled)
            {
                AnimationTrack wave = new AnimationTrack("Filled Wave effect", 1.0f);
                wave.SetFrame(0.0f,
                              new AnimationFilledCircle(origin.ToPointF(), 0, primary_c, (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_width)
                              );
                wave.SetFrame(0.80f,
                              new AnimationFilledCircle(origin.ToPointF(), Effects.canvas_width * 0.80f, secondary_c, (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_width)
                              );
                wave.SetFrame(1.00f,
                              new AnimationFilledCircle(origin.ToPointF(), Effects.canvas_width, Color.FromArgb(0, secondary_c), (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_width)
                              );
                anim_mix.AddTrack(wave);
            }
            else if ((Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_type == InteractiveEffects.KeyPress)
            {
                ColorSpectrum spec = new ColorSpectrum(primary_c, secondary_c);
                if ((Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_type == InteractiveEffects.KeyPress)
                {
                    spec = new ColorSpectrum(primary_c, Color.FromArgb(0, secondary_c));
                    spec.SetColorAt(0.80f, secondary_c);
                }

                return(new input_item(key, 0.0f, spec));
            }
            else if ((Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_type == InteractiveEffects.ArrowFlow)
            {
                PointF starting_pt = origin.ToPointF();

                AnimationTrack arrow = new AnimationTrack("Arrow Flow effect", 1.0f);
                arrow.SetFrame(0.0f,
                               new AnimationLines(
                                   new AnimationLine[] {
                    new AnimationLine(starting_pt, starting_pt, primary_c, (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_width),
                    new AnimationLine(starting_pt, starting_pt, primary_c, (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_width)
                }
                                   )
                               );
                arrow.SetFrame(0.33f,
                               new AnimationLines(
                                   new AnimationLine[] {
                    new AnimationLine(starting_pt, new PointF(starting_pt.X + Effects.canvas_width * 0.33f, starting_pt.Y), Utils.ColorUtils.BlendColors(primary_c, secondary_c, 0.33D), (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_width),
                    new AnimationLine(starting_pt, new PointF(starting_pt.X - Effects.canvas_width * 0.33f, starting_pt.Y), Utils.ColorUtils.BlendColors(primary_c, secondary_c, 0.33D), (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_width)
                }
                                   )
                               );
                arrow.SetFrame(0.66f,
                               new AnimationLines(
                                   new AnimationLine[] {
                    new AnimationLine(new PointF(starting_pt.X + Effects.canvas_width * 0.33f, starting_pt.Y), new PointF(starting_pt.X + Effects.canvas_width * 0.66f, starting_pt.Y), secondary_c, (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_width),
                    new AnimationLine(new PointF(starting_pt.X - Effects.canvas_width * 0.33f, starting_pt.Y), new PointF(starting_pt.X - Effects.canvas_width * 0.66f, starting_pt.Y), secondary_c, (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_width)
                }
                                   )
                               );
                arrow.SetFrame(1.0f,
                               new AnimationLines(
                                   new AnimationLine[] {
                    new AnimationLine(new PointF(starting_pt.X + Effects.canvas_width * 0.66f, starting_pt.Y), new PointF(starting_pt.X + Effects.canvas_width, starting_pt.Y), Color.FromArgb(0, secondary_c), (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_width),
                    new AnimationLine(new PointF(starting_pt.X - Effects.canvas_width * 0.66f, starting_pt.Y), new PointF(starting_pt.X - Effects.canvas_width, starting_pt.Y), Color.FromArgb(0, secondary_c), (Global.Configuration.desktop_profile.Settings as DesktopSettings).interactive_effect_width)
                }
                                   )
                               );
                anim_mix.AddTrack(arrow);
            }

            return(new input_item(key, 0.0f, anim_mix));
        }
Beispiel #10
0
 public EffectSettingAttribute(Type renderTye, EffectPoint effectPoint)
 {
     m_renderType  = renderTye;
     m_effectPoint = effectPoint;
 }
Beispiel #11
0
        public Tuple <EffectPoint, Color>[] getPointMap()
        {
            //List<Tuple<EffectPoint, EffectColor>> points = new List<Tuple<EffectPoint, EffectColor>>();

            List <EffectPoint[]> points = new List <EffectPoint[]>();

            if (function is EffectCircle)
            {
                for (float t = 0.0f; t < Math.PI * 2.0f; t += 0.025f)
                {
                    EffectPoint point = function.GetPoint(t);

                    HashSet <EffectPoint> newpts = new HashSet <EffectPoint>();

                    if (!point.IsOutOfRange())
                    {
                        newpts.Add(new EffectPoint(point.X, point.Y));

                        for (int offset = 0; offset < size; offset++)
                        {
                            newpts.Add(new EffectPoint(point.X + offset, point.Y));
                            newpts.Add(new EffectPoint(point.X, point.Y + offset));
                            newpts.Add(new EffectPoint(point.X - offset, point.Y));
                            newpts.Add(new EffectPoint(point.X, point.Y - offset));
                            newpts.Add(new EffectPoint(point.X + offset, point.Y + offset));
                            newpts.Add(new EffectPoint(point.X + offset, point.Y - offset));
                            newpts.Add(new EffectPoint(point.X - offset, point.Y + offset));
                            newpts.Add(new EffectPoint(point.X - offset, point.Y - offset));
                        }
                    }

                    if (newpts.Count != 0)
                    {
                        points.Add(newpts.ToArray());
                    }
                }
            }
            else
            {
                for (float x = 0.0f; x < Effects.canvas_width; x += 1.0f)
                {
                    EffectPoint point = function.GetPoint(x);

                    List <EffectPoint> newpts = new List <EffectPoint>();

                    if (!point.IsOutOfRange())
                    {
                        newpts.Add(point);

                        for (int offset = 0; offset < size; offset++)
                        {
                            newpts.Add(new EffectPoint(point.X + offset, point.Y));
                            newpts.Add(new EffectPoint(point.X, point.Y + offset));
                            newpts.Add(new EffectPoint(point.X - offset, point.Y));
                            newpts.Add(new EffectPoint(point.X, point.Y - offset));
                            newpts.Add(new EffectPoint(point.X + offset, point.Y + offset));
                            newpts.Add(new EffectPoint(point.X + offset, point.Y - offset));
                            newpts.Add(new EffectPoint(point.X - offset, point.Y + offset));
                            newpts.Add(new EffectPoint(point.X - offset, point.Y - offset));
                        }
                    }

                    if (newpts.Count != 0)
                    {
                        points.Add(newpts.ToArray());
                    }
                }
            }

            List <Tuple <EffectPoint, Color> > points_ret = new List <Tuple <EffectPoint, Color> >();

            for (int pt_id = 0; pt_id < points.Count; pt_id++)
            {
                Color color = colorspectrum.GetColorAt((float)pt_id / points.Count);

                foreach (EffectPoint pt in points[pt_id])
                {
                    points_ret.Add(new Tuple <EffectPoint, Color>(pt, color));
                }
            }

            return(points_ret.ToArray());
        }
Beispiel #12
0
        public override void UpdateLights(EffectFrame frame)
        {
            previoustime = currenttime;
            currenttime  = Utils.Time.GetMillisecondsSinceEpoch();

            Queue <EffectLayer> layers = new Queue <EffectLayer>();
            EffectLayer         layer;

            effect_cfg.speed = Global.Configuration.idle_speed;

            switch (Global.Configuration.idle_type)
            {
            case IdleEffects.Dim:
                layer = new EffectLayer("Idle - Dim");

                Color dim_color = Color.FromArgb(125, 0, 0, 0);
                layer.Fill(dim_color);

                layers.Enqueue(layer);
                break;

            case IdleEffects.ColorBreathing:
                layer = new EffectLayer("Idle - Color Breathing");

                Color breathe_bg_color = Global.Configuration.idle_effect_secondary_color;
                layer.Fill(breathe_bg_color);

                float sine = (float)Math.Pow(Math.Sin((double)((currenttime % 10000L) / 10000.0f) * 2 * Math.PI * Global.Configuration.idle_speed), 2);

                layer.Fill(Color.FromArgb((byte)(sine * 255), Global.Configuration.idle_effect_primary_color));

                layers.Enqueue(layer);
                break;

            case IdleEffects.RainbowShift_Horizontal:
                layer = new EffectLayer("Idle - Rainbow Shift (Horizontal)", LayerEffects.RainbowShift_Horizontal, effect_cfg);

                layers.Enqueue(layer);
                break;

            case IdleEffects.RainbowShift_Vertical:
                layer = new EffectLayer("Idle - Rainbow Shift (Vertical)", LayerEffects.RainbowShift_Vertical, effect_cfg);

                layers.Enqueue(layer);
                break;

            case IdleEffects.StarFall:
                layer = new EffectLayer("Idle - Starfall");

                if (nextstarset < currenttime)
                {
                    for (int x = 0; x < Global.Configuration.idle_amount; x++)
                    {
                        Devices.DeviceKeys star = allKeys[randomizer.Next(allKeys.Length)];
                        if (stars.ContainsKey(star))
                        {
                            stars[star] = 1.0f;
                        }
                        else
                        {
                            stars.Add(star, 1.0f);
                        }
                    }

                    nextstarset = currenttime + (long)(1000L * Global.Configuration.idle_frequency);
                }

                layer.Fill(Global.Configuration.idle_effect_secondary_color);

                Devices.DeviceKeys[] stars_keys = stars.Keys.ToArray();

                foreach (Devices.DeviceKeys star in stars_keys)
                {
                    layer.Set(star, Utils.ColorUtils.MultiplyColorByScalar(Global.Configuration.idle_effect_primary_color, stars[star]));
                    stars[star] -= getDeltaTime() * 0.05f * Global.Configuration.idle_speed;
                }

                layers.Enqueue(layer);
                break;

            case IdleEffects.RainFall:
                layer = new EffectLayer("Idle - Rainfall");

                if (nextstarset < currenttime)
                {
                    for (int x = 0; x < Global.Configuration.idle_amount; x++)
                    {
                        Devices.DeviceKeys star = allKeys[randomizer.Next(allKeys.Length)];
                        if (raindrops.ContainsKey(star))
                        {
                            raindrops[star] = 1.0f;
                        }
                        else
                        {
                            raindrops.Add(star, 1.0f);
                        }
                    }

                    nextstarset = currenttime + (long)(1000L * Global.Configuration.idle_frequency);
                }

                layer.Fill(Global.Configuration.idle_effect_secondary_color);

                Devices.DeviceKeys[] raindrops_keys = raindrops.Keys.ToArray();

                ColorSpectrum drop_spec = new ColorSpectrum(Global.Configuration.idle_effect_primary_color, Color.FromArgb(0, Global.Configuration.idle_effect_primary_color));

                foreach (Devices.DeviceKeys raindrop in raindrops_keys)
                {
                    EffectPoint pt = Effects.GetBitmappingFromDeviceKey(raindrop).GetCenter();

                    float transition_value = 1.0f - raindrops[raindrop];
                    float radius           = transition_value * Effects.canvas_biggest;

                    layer.GetGraphics().DrawEllipse(new Pen(drop_spec.GetColorAt(transition_value), 2),
                                                    pt.X - radius,
                                                    pt.Y - radius,
                                                    2 * radius,
                                                    2 * radius);

                    raindrops[raindrop] -= getDeltaTime() * 0.05f * Global.Configuration.idle_speed;
                }

                layers.Enqueue(layer);
                break;

            default:
                break;
            }

            frame.AddOverlayLayers(layers.ToArray());
        }