Example #1
0
		/// <summary>
		/// Initialize
		/// </summary>
		protected override void Initialize()
		{
#if !XBOX360
			// Add screenshot capturer. Works only on windows platform.
			// Note: Don't do this in constructor,
			// we need the correct window name for screenshots!
			this.Components.Add(new ScreenshotCapturer(this));
#endif

			// Remember device
			device = graphics.GraphicsDevice;

			// Remember resolution
			width = graphics.GraphicsDevice.Viewport.Width;
			height = graphics.GraphicsDevice.Viewport.Height;
			backBufferDepthFormat = graphics.PreferredDepthStencilFormat;
			remMultiSampleType = device.PresentationParameters.MultiSampleType;
			
            //if (remMultiSampleType == MultiSampleType.NonMaskable)
			//	remMultiSampleType = MultiSampleType.None;
			
            remMultiSampleQuality = device.PresentationParameters.MultiSampleQuality;
			remDepthBuffer = device.DepthStencilBuffer;

			// Update resolution if it changes and restore device after it was lost
			Window.ClientSizeChanged += new EventHandler(Window_ClientSizeChanged);
			graphics.DeviceReset += new EventHandler(graphics_DeviceReset);
			graphics_DeviceReset(null, EventArgs.Empty);
			
			// Create matrices for our shaders, this makes it much easier to manage
			// all the required matrices and we have to do this ourselfs since there
			// is no fixed function support and theirfore no Device.Transform class.
			WorldMatrix = Matrix.Identity;
			aspectRatio = (float)width / (float)height;
			ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(
				FieldOfView, aspectRatio, NearPlane, FarPlane);

			// ViewMatrix is updated in camera class
			ViewMatrix = Matrix.CreateLookAt(
				new Vector3(0, 0, 15), Vector3.Zero, Vector3.Up);

            // Init global manager classes, which will be used all over the place ^^
            lineManager2D = new LineManager2D();
            //lineManager3D = new LineManager3D();
            ui = new UIRenderer();
            // Create font and numbers font
			font = new TextureFont();

			// Make sure we can use PS1 or PS2, see UsePS and UsePS20
			if (device.GraphicsDeviceCapabilities.PixelShaderVersion.Major >= 2 &&
				GameSettings.Default.PerformanceSettings < 2)
				GameSettings.Default.PerformanceSettings = 2;
			else if (
				device.GraphicsDeviceCapabilities.PixelShaderVersion.Major >= 1 &&
				GameSettings.Default.PerformanceSettings < 1)
				GameSettings.Default.PerformanceSettings = 1;

			// Init post screen glow
			glowShader =
				//new PostScreenMenu();
				new PostScreenGlow();

			// Init effect manager
			effectManager = new EffectManager();

			// Init light position
			LightDirection = new Vector3(2, -7, 5);

			base.Initialize();

			device.RenderState.DepthBufferEnable = true;

			// Always create depth buffer from now on
			RenderToTexture.alwaysCreateRenderTargetDepthBuffer = true;
		} // Initialize()
Example #2
0
            /// <summary>
            /// Render
            /// </summary>
            /// <returns>True if effect is at end and has to be removed</returns>
            public bool Render(Vector3 camPos, EffectManager effectManager)
            {
                // Max. distance for visible effects.
                const float MaxDistance = BaseGame.FarPlane;// *0.66f;

                // Calculate current size
                float timePercent = maxTime == 0 ? 0 : (float)time / (float)maxTime;
                float currentSize = size + (endSize - size) * timePercent;

                // Calculate alpha, always 100% for instant effects.
                // Else it will fade in from 0-10% and fade out from 75-100%.
                // Explosion effects don't fade in, they just fade out at end (80-100%)
                Color currentColor = color;

                /*obs
                if (IsExplosion)
                {
                    if (timePercent > 0.8f)
                        currentColor = ColorHelper.FromArgb((byte)
                            (color.A * (1.0f - (timePercent - 0.8f) * 5.0f)), color);
                    AnimatedTexture aniTex =
                        effectManager.explosionTextures[EffectTextureNum[(int)type]];
                    //obs: aniTex.Select((int)(timePercent * aniTex.AnimationLength));
                    Billboard.Render(aniTex,
                        (int)(timePercent * aniTex.AnimationLength),
                        Billboard.BlendMode.NormalAlphaBlending,
                        position, currentSize, rotation, currentColor);
                } // if (IsExplosion)
                else
                 */
                {
                    float alpha = 1.0f;
                    if (IsLightEffect)
                    {
                        // Don't change color, but change size
                        if (timePercent > 0.5f)
                            currentSize = currentSize *
                                (1.0f - (timePercent - 0.5f) * 1.9f);
                    } // if (IsLightEffect)
                    else if (maxTime > 0 &&
                        timePercent < 0.1f)
                        alpha = timePercent * 10.0f;
                    else if (type == EffectType.Smoke)
                        alpha = 1.0f - (timePercent - 0.1f) / 0.9f;
                    else if (timePercent > 0.75f)
                        alpha = 1.0f - (timePercent - 0.75f) * 4.0f;

                    // Fade out if really far away!
                    if (distance > MaxDistance * 0.75f)
                        alpha *= 1.0f -
                            ((distance - MaxDistance * 0.75f) / (MaxDistance * 0.25f));

                    if (alpha != 1.0f)
                    {
                        if (alpha > 1.0f)
                            alpha = 1.0f;
                        if (alpha < 0.0f)
                            alpha = 0.0f;

                        currentColor = ColorHelper.FromArgb((byte)(color.A * alpha), color);
                    } // if (alpha)

                    //obs:
                    //effectManager.effectTextures[EffectTextureNum[(int)type]].Select();
                    if (IsRing)
                        Billboard.RenderOnGround(
                            effectManager.effectTextures[EffectTextureNum[(int)type]],
                            position, currentSize, rotation, currentColor,
                            vecGroundRight, vecGroundUp);
                    else if (IsLightEffect)
                        Billboard.Render(
                            effectManager.effectTextures[EffectTextureNum[(int)type]].
                            XnaTexture, Billboard.BlendMode.LightEffect,
                            position, currentSize, currentColor);
                    else
                        Billboard.Render(
                            effectManager.effectTextures[EffectTextureNum[(int)type]],
                            position, currentSize, rotation, currentColor);
                } // else

                // Increase time
                time += BaseGame.ElapsedTimeThisFrameInMs;//.MsLastFrame;
                // Quit if time is over, also quit if out of visible area!
                if (time >= maxTime ||
                    distance > MaxDistance)
                    return true;

                return false;
            }