예제 #1
0
        public void Initialise()
        {
            if (isInit)
            {
                return;
            }

            isInit = true;

            GameObjectManager.AddGameObject(Camera.Orthographic("mainCamera", new Vector3(0, 0, 1f), Vector3.Zero));

            materials = new Material[1];

            RenderTargetSettings settings_target = new RenderTargetSettings()
            {
                blend   = BlendState.AlphaBlend,
                depth   = DepthStencilState.DepthRead,
                effect  = null,
                mode    = SpriteSortMode.Deferred,
                sampler = SamplerState.LinearClamp
            };

            Resources.LoadRenderTarget2D("UI_dithered", this, GraphicsHelper.screen.Width, GraphicsHelper.screen.Height, false, SurfaceFormat.Color, DepthFormat.Depth16, 0, RenderTargetUsage.DiscardContents, settings_target);
            RenderTargetRenderer dithered = RenderTargetRenderer.MakeRenderTargetRenderer("UI_dithered", new RenderTargetSettings(), 1);

            materials[0]             = Resources.LoadAsset(new Material().GetType(), "shader_noise", this) as Material;
            dithered.settings.effect = materials[0];
            dithered.settings.effect.CurrentTechnique = dithered.settings.effect.Techniques["RCDCLSB"];
            dithered.settings.effect.Parameters["S"].SetValue(Random.Range());
            dithered.settings.effect.Parameters["N"].SetValue(0.001f);

            settings_target = new RenderTargetSettings()
            {
                blend   = BlendState.AlphaBlend,
                depth   = DepthStencilState.DepthRead,
                effect  = null,
                mode    = SpriteSortMode.Deferred,
                sampler = SamplerState.PointClamp
            };
            Resources.LoadRenderTarget2D("UI_nearest", this, GraphicsHelper.screen.Width, GraphicsHelper.screen.Height, false, SurfaceFormat.Color, DepthFormat.Depth16, 0, RenderTargetUsage.DiscardContents, settings_target);
            RenderTargetRenderer nearest = RenderTargetRenderer.MakeRenderTargetRenderer("UI_nearest", new RenderTargetSettings(), 2);

            //materials[1] = Resources.LoadAsset(new Material().GetType(), "shader_noise", this) as Material;
            //nearest.settings.effect = materials[1];
            //nearest.settings.effect.CurrentTechnique = nearest.settings.effect.Techniques["RCDCLSB"];
            //nearest.settings.effect.Parameters["S"].SetValue(Random.Range());
            //nearest.settings.effect.Parameters["N"].SetValue(0.0005f);

            sky_bottom_gradient = new Gradient(
                new Color[]
            {
                new Color(112, 181, 255),
                new Color(181, 112, 255),
                new Color(255, 71, 71),
                new Color(25, 25, 94),
                new Color(0, 0, 25),
                new Color(0, 0, 25),
                new Color(25, 25, 94),
                new Color(255, 71, 71),
                new Color(181, 112, 255),
                new Color(112, 181, 255)
            },
                new float[]
            {
                0.0f,
                0.11f,
                0.25f,
                0.30f,
                0.35f,
                0.65f,
                0.70f,
                0.75f,
                0.89f,
                1.0f
            });

            sky_sun_gradient = new Gradient(
                new Color[]
            {
                new Color(255, 255, 196),
                new Color(255, 128, 128),
                new Color(255, 128, 64),
                new Color(255, 128, 64),
                new Color(255, 128, 128),
                new Color(255, 255, 196)
            },
                new float[]
            {
                0.0f,
                0.25f,
                0.35f,
                0.65f,
                0.75f,
                1.0f
            });

            sky_sun_glow_gradient = new Gradient(
                new Color[]
            {
                new Color(255, 255, 196, 64),
                new Color(255, 0, 0, 128),
                new Color(255, 196, 196, 255),
                new Color(255, 196, 196, 255),
                new Color(255, 0, 0, 128),
                new Color(255, 255, 196, 64)
            },
                new float[]
            {
                0.0f,
                0.25f,
                0.35f,
                0.65f,
                0.75f,
                1.0f
            });

            sky_moon_gradient = new Gradient(
                new Color[]
            {
                new Color(0.75f, 0.75f, 1.0f, 1.0f),
                new Color(0.75f, 0.75f, 1.0f, 1.0f),
                new Color(1.0f, 1.0f, 0.75f, 1.0f),
                new Color(0.75f, 0.75f, 1.0f, 1.0f),
                new Color(0.75f, 0.75f, 1.0f, 1.0f)
            },
                new float[]
            {
                0.0f,
                0.25f,
                0.5f,
                0.75f,
                1.0f
            }
                );

            sky_stars_gradient = new Gradient(
                new Color[]
            {
                new Color(255, 255, 255, 0),
                new Color(255, 255, 255, 32),
                new Color(255, 255, 255, 255),
                new Color(255, 255, 255, 32),
                new Color(255, 255, 255, 0)
            },
                new float[]
            {
                0.0f,
                0.25f,
                0.5f,
                0.75f,
                1.0f
            });

            sky_top_gradient = new Gradient(
                new Color[]
            {
                new Color(25, 25, 128),
                new Color(50, 50, 128),
                new Color(110, 25, 110),
                new Color(0, 0, 25),
                new Color(0, 0, 0),
                new Color(0, 0, 0),
                new Color(0, 0, 25),
                new Color(110, 25, 110),
                new Color(50, 50, 128),
                new Color(25, 25, 128)
            },
                new float[]
            {
                0.0f,
                0.11f,
                0.25f,
                0.30f,
                0.35f,
                0.65f,
                0.70f,
                0.75f,
                0.89f,
                1.0f
            });

            title_gradient = new Gradient(
                new Color[]
            {
                new Color(255, 255, 255),
                new Color(255, 255, 255),
                new Color(255, 255, 128),
                new Color(255, 255, 255),
                new Color(255, 255, 255)
            },
                new float[]
            {
                0.0f,
                0.25f,
                0.5f,
                0.75f,
                1.0f
            }
                );

            skyline_gradient = new Gradient(
                new Color[]
            {
                new Color(0.5f, 0.5f, 0.5f, 1.0f),
                new Color(0.5f, 0.5f, 0.5f, 1.0f),
                new Color(0.0f, 0.0f, 0.0f, 1.0f),
                new Color(0.1f, 0.1f, 0.1f, 1.0f),
                new Color(0.25f, 0.25f, 0.25f, 1.0f),
                new Color(0.5f, 0.5f, 0.5f, 1.0f)
            },
                new float[]
            {
                0.0f,
                0.20f,
                0.25f,
                0.5f,
                0.75f,
                1.0f
            }
                );

            skyline_windows_gradient = new Gradient(
                new Color[]
            {
                new Color(125, 175, 195, 255),
                new Color(175, 125, 195, 128),
                new Color(16, 16, 16, 255),
                new Color(175, 125, 195, 128),
                new Color(125, 175, 195, 255)
            },
                new float[]
            {
                0.0f,
                0.25f,
                0.5f,
                0.75f,
                1.0f
            }
                );

            skyline_glow_gradient = new Gradient(
                new Color[]
            {
                new Color(125, 175, 195, 0),
                new Color(175, 125, 195, 196),
                new Color(255, 255, 127, 255),
                new Color(175, 125, 195, 196),
                new Color(125, 175, 195, 0)
            },
                new float[]
            {
                0.0f,
                0.25f,
                0.5f,
                0.75f,
                1.0f
            }
                );

            sky_glow_gradient = new Gradient(
                new Color[]
            {
                new Color(125, 175, 195, 0),
                new Color(175, 125, 195, 32),
                new Color(255, 255, 127, 128),
                new Color(175, 125, 195, 32),
                new Color(125, 175, 195, 0)
            },
                new float[]
            {
                0.0f,
                0.25f,
                0.5f,
                0.75f,
                1.0f
            }
                );

            sky_top      = new UIImage("Backdrop", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.TopLeft), new UIAlignment(UIAlignment.Alignment.TopLeft), UIObject.flags.None, "blank", "UI_dithered");
            sky_stars    = new UIImage("Stars", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "stars", "UI_dithered");
            sky_moon     = new UIImage("Moon", new Rectangle(0, 0, 128, 128), new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "moon", "UI_dithered");
            sky_bottom   = new UIImage("Backdrop_gradient", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "gradient_white_to_transparent", "UI_dithered");
            sky_sun_glow = new UIImage("Sun_glow", new Rectangle(0, 0, 2000, 2000), new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "glow_center_circle", "UI_dithered");
            sky_sun      = new UIImage("Sun", new Rectangle(0, 0, 128, 128), new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "sun", "UI_dithered");

            sky_glow = new UIImage("Glow", new Rectangle(0, 0, GraphicsHelper.screen.Width * 2, GraphicsHelper.screen.Height * 2), new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "glow_bottom_circle", "UI_dithered");

            skyline         = new UIImage[5];
            skyline_windows = new UIImage[5];
            skyline_glow    = new UIImage[5];

            skyline[0]         = new UIImage("Skyline0", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_0", "UI_nearest");
            skyline_windows[0] = new UIImage("Skyline0_window", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_0_window", "UI_nearest");
            skyline_glow[0]    = new UIImage("Skyline0_glow", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_0_glow", "UI_nearest");
            skyline[1]         = new UIImage("Skyline1", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_1", "UI_nearest");
            skyline_windows[1] = new UIImage("Skyline0_window", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_1_window", "UI_nearest");
            skyline_glow[1]    = new UIImage("Skyline1_glow", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_1_glow", "UI_nearest");
            skyline[2]         = new UIImage("Skyline2", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_2", "UI_nearest");
            skyline_windows[2] = new UIImage("Skyline0_window", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_2_window", "UI_nearest");
            skyline_glow[2]    = new UIImage("Skyline2_glow", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_2_glow", "UI_nearest");
            skyline[3]         = new UIImage("Skyline3", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_3", "UI_nearest");
            skyline_windows[3] = new UIImage("Skyline0_window", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_3_window", "UI_nearest");
            skyline_glow[3]    = new UIImage("Skyline3_glow", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_3_glow", "UI_nearest");
            skyline[4]         = new UIImage("Skyline4", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_4", "UI_nearest");
            skyline_windows[4] = new UIImage("Skyline0_window", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_4_window", "UI_nearest");
            skyline_glow[4]    = new UIImage("Skyline4_glow", GraphicsHelper.screen, new UIAlignment(UIAlignment.Alignment.Center), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "skyline_4_glow", "UI_nearest");

            title = new UIText("Title", new UIAlignment(UIAlignment.Alignment.TopLeft), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "microtype", "I am poor and hungry", 128);
            //title.bounds = new Rectangle(title.bounds.X + 16, title.bounds.Y + 16, title.bounds.Width, title.bounds.Height);

            //logo = new UIImage("Logo", new Rectangle(0, 0, 100, 100), new UIAlignment(UIAlignment.Alignment.BottomRight), new UIAlignment(UIAlignment.Alignment.Center), UIObject.flags.None, "monogameLogo");
        }
예제 #2
0
        public static RenderTarget2DWrapper LoadRenderTarget2D(string name, Scene parent, int width, int height, bool mipMap, SurfaceFormat surfaceFormat, DepthFormat depthFormat, int multiSampleCount, RenderTargetUsage usage, RenderTargetSettings settings)
        {
            RenderTarget2DWrapper target  = new RenderTarget2DWrapper(new RenderTarget2D(GraphicsHelper.graphicsDevice, width, height, mipMap, surfaceFormat, depthFormat, multiSampleCount, usage));
            ResourceManager       manager = instance.resourceManagers[target.GetType()];

            if (manager.ContainsResource(name))
            {
                if (target != manager.GetResource(name))
                {
                    throw new AssetExceptions.AssetAlreadyExists("Cannot resolve difference between existing RenderTarget2D and new RenderTarget2D\nExisting RenderTarget2D: " + instance.resourceManager_renderTarget2D.GetResource(name) + "\nNew RenderTarget2D" + target);
                }
            }
            else
            {
                manager.AddResource(name, target);
                RenderTargetBatch batch = new RenderTargetBatch(name, target, settings);
                RenderManager.AddRenderTargetBatch(batch);
                return(target);
            }
            RenderTarget2DWrapper wrapper = manager.GetResource(name) as RenderTarget2DWrapper;
            Type type = wrapper.GetType();

            if (parent != null)
            {
                parent.assets.AddAsset(name, type);
            }
            else
            {
                // TODO: Log a warning that unbound assets will not unload when a scene switch occurs
            }

            return(wrapper);
        }