private void TestRendering()
        {
            renderer = new RenderTargetRenderer(Camera.Main);
            renderer.PerformRender(this.ContentManagerName, "MainCameraTexture");

            ImageData imageData = ImageData.FromTexture2D(renderer.Texture);

            // verify that colors are what they should be:
            if (imageData.GetPixelColor(1, 1).R != 255)
            {
                throw new Exception("Control case failed - top-left pixel is not red");
            }


            var pixelColor = imageData.GetPixelColor(1, 11);

            if (pixelColor.R == 255)
            {
                throw new Exception("Transparency from PNGs is not rendering correctly");
            }

            if (imageData.GetPixelColor(SolidColorTransparencyTestSprite.Texture.Width + 1, 11).R == 255)
            {
                throw new Exception("Transparency from Sprite Alpha is not rendering correctly");
            }
        }
Пример #2
0
        private void ConfigureTreeVisualizer <AIContext>(IBehaviorNode <AIContext> behavior)
        {
            visualizer.Prepare(new MinimalColorPainter(), level.Context.Behavior);
            renderer = new RenderTargetRenderer(batch =>
            {
                spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);

                visualizer.RenderTree(spriteBatch);
                spriteBatch.End();
            },
                                                GraphicsDevice,
                                                new Vector2(GraphicsDevice.Viewport.Width * 2, visualizer.TreeSize.Y));
        }
Пример #3
0
        public MediaPlayer2D(
            RenderTargetRenderer renderer,
            DuiBrowser duiBrowser,
            string playerName,
            float globalVolume,
            float soundAttenuation,
            float soundMaxDistance,
            float soundMinDistance)
            : base(duiBrowser, playerName, globalVolume, soundAttenuation, soundMaxDistance, soundMinDistance)
        {
            this.renderTarget = renderer;

            ClientScript.Self.AddTick(this.CalculateVolume);
            ClientScript.Self.AddTick(this.Draw);
            ClientScript.Self.AddTick(this.CalculateDistance);
        }
Пример #4
0
        private async Task <IMediaPlayer> CreateVideoPlayer(Screen screen)
        {
            IMediaPlayer videoPlayer;

            var duiBrowser = await DuiBrowserPool.Instance.AcquireDuiBrowser(screen);

            if (screen.Is3DRendered)
            {
                var scaleform = await ScaleformRendererPool.Instance.AcquireScaleformRenderer(
                    screen.PositionalSettings,
                    duiBrowser.TxdName,
                    duiBrowser.TxnName);

                videoPlayer = new MediaPlayer3D(
                    scaleform,
                    duiBrowser,
                    screen.Name,
                    screen.BrowserSettings.GlobalVolume,
                    screen.BrowserSettings.SoundAttenuation,
                    screen.BrowserSettings.SoundMaxDistance,
                    screen.BrowserSettings.SoundMinDistance);
            }
            else
            {
                var renderTarget = new RenderTargetRenderer(
                    screen.TargetSettings.ModelName,
                    screen.TargetSettings.RenderTargetName,
                    duiBrowser.TxdName,
                    duiBrowser.TxnName);

                videoPlayer = new MediaPlayer2D(
                    renderTarget,
                    duiBrowser,
                    screen.Name,
                    screen.BrowserSettings.GlobalVolume,
                    screen.BrowserSettings.SoundAttenuation,
                    screen.BrowserSettings.SoundMaxDistance,
                    screen.BrowserSettings.SoundMinDistance);
            }

            return(videoPlayer);
        }
Пример #5
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");
        }