Пример #1
0
        /// <summary>
        /// The draw with technique.
        /// </summary>
        /// <param name="effect">
        /// The effect.
        /// </param>
        /// <param name="technique">
        /// The technique.
        /// </param>
        public override void DrawWithEffect(ShaderManager.EFFECT_ID effect, string technique)
        {
            // code from Riemers XNA tutorial
            foreach (ModelMesh mesh in this.ObjectModel.Meshes)
            {
                int count = 0;
                foreach (ModelMeshPart mmp in mesh.MeshParts)
                {
                    if (count < this.ModelTextures.Count)
                    {
                        ShaderManager.SetValue("Texture", this.ModelTextures[count++]);
                    }

                    if (effect == ShaderManager.EFFECT_ID.STATICMODEL)
                    {
                        ShaderManager.SetValue("isGround", this is Ground);
                    }

                    ShaderManager.SetValue("life", Hero.GetHeroLife());
                    ShaderManager.SetValue("World", this.World);

                    ShaderManager.CommitChanges();
                    mmp.Effect = ShaderManager.GetEffect(effect);
                }

                foreach (Effect e in mesh.Effects)
                {
                    e.CurrentTechnique = e.Techniques[technique];
                }

                mesh.Draw();
            }
        }
Пример #2
0
        /// <summary>
        /// The add scene.
        /// </summary>
        /// <param name="scene">
        /// The scene.
        /// </param>
        public static void AddScene(Scene scene)
        {
            scene.Visible = false;

            scenes.Add(scene);

            if (scene.TopMost && vd == null)
            {
                // set up the vertices and add the effect
                overlayVertexArray = new VertexPositionColor[4];

                overlayVertexArray[0] =
                    new VertexPositionColor(
                        new Vector3(
                            -game.GraphicsDevice.Viewport.Width / 2.0f,
                            -game.GraphicsDevice.Viewport.Height / 2.0f,
                            0.0f),
                        Color.TransparentBlack);
                overlayVertexArray[1] =
                    new VertexPositionColor(
                        new Vector3(
                            -game.GraphicsDevice.Viewport.Width / 2.0f, game.GraphicsDevice.Viewport.Height / 2.0f, 0.0f),
                        Color.TransparentBlack);
                overlayVertexArray[2] =
                    new VertexPositionColor(
                        new Vector3(
                            game.GraphicsDevice.Viewport.Width / 2.0f, -game.GraphicsDevice.Viewport.Height / 2.0f, 0.0f),
                        Color.TransparentBlack);
                overlayVertexArray[3] =
                    new VertexPositionColor(
                        new Vector3(
                            game.GraphicsDevice.Viewport.Width / 2.0f, game.GraphicsDevice.Viewport.Height / 2.0f, 0.0f),
                        Color.TransparentBlack);

                vd = new VertexDeclaration(game.GraphicsDevice, VertexPositionColor.VertexElements);

                vb = new VertexBuffer(game.GraphicsDevice, VertexPositionColor.SizeInBytes * 4, BufferUsage.None);
                vb.SetData(overlayVertexArray);

                Vector4 overlayColor = Color.Black.ToVector4();
                overlayColor.W = 0.85f;

                ShaderManager.AddEffect(ShaderManager.EFFECT_ID.OVERLAY, "overlay", game);
                ShaderManager.SetCurrentEffect(ShaderManager.EFFECT_ID.OVERLAY);
                ShaderManager.SetValue("OverlayColor", overlayColor);
                ShaderManager.CommitChanges();
            }
        }
Пример #3
0
        /// <summary>
        /// The draw.
        /// </summary>
        /// <param name="gameTime">
        /// The game time.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// </exception>
        public override void Draw(GameTime gameTime)
        {
            if (this.HeaderText == null)
            {
                throw new ArgumentNullException("HeaderText should not be null");
            }

            if (this.BodyText == null)
            {
                throw new ArgumentNullException("BodyText should not be null");
            }

            if (this.TextBoxSize == null)
            {
                throw new ArgumentNullException("TextBoxSize should not be null");
            }

            // draw the texture
            ShaderManager.SetCurrentEffect(ShaderManager.EFFECT_ID.TEXTURE);

            ShaderManager.SetValue("World", Matrix.CreateTranslation(this.Position3D));
            ShaderManager.SetValue("View", this.scene.Camera.View);
            ShaderManager.SetValue("Projection", this.scene.Camera.Perspective);

            ShaderManager.SetValue("tex", this.TextTexture);

            ShaderManager.CommitChanges();

            ShaderManager.Begin();
            ShaderManager.GetCurrentEffect().Techniques["TextureTechnique"].Passes[0].Begin();

            this.GraphicsDevice.VertexDeclaration = TextureSpriteVertexDeclaration;
            this.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, this.textSprite, 0, 2);

            ShaderManager.GetCurrentEffect().Techniques["TextureTechnique"].Passes[0].End();

            ShaderManager.End();
            this.DrawPhysicsVertices();
        }
Пример #4
0
        private static Texture2D RenderToTarget(Model model, ModelAnimationPlayer player, Microsoft.Xna.Framework.Game game, Matrix world, out Texture2D Sillouette)
        {
            DepthStencilBuffer old = ShadowMapManager.SetupShadowMap(game.GraphicsDevice, ref renderTarget, ref depthBuffer);

            BoundingSphere bs = new BoundingSphere();

            bool first = true;

            foreach (ModelMesh mesh in model.Meshes)
            {
                if (first)
                {
                    bs    = mesh.BoundingSphere;
                    first = false;
                }
                else
                {
                    bs = BoundingSphere.CreateMerged(bs, mesh.BoundingSphere);
                }
            }

            bs.Center.X = bs.Center.Z;
            bs.Radius  *= 1.5f;

            ShaderManager.AddEffect(ShaderManager.EFFECT_ID.PHYSICS, "PhysicsRenderer", game);
            ShaderManager.SetCurrentEffect(ShaderManager.EFFECT_ID.PHYSICS);
            ShaderManager.SetValue("World", world);

            Matrix m = Matrix.Identity;

            m.M33 = 0;
            m.M43 = 0.5f;
            ShaderManager.SetValue("Projection", m);


            Matrix view;

            view = Matrix.CreateTranslation(-bs.Center) * Matrix.CreateScale(1 / bs.Radius, 1 / bs.Radius, 1);

            ShaderManager.SetValue("Projection", m);
            ShaderManager.SetValue("View", view);
            ShaderManager.SetValue("usingBones", player != null);

            if (player != null)
            {
                ShaderManager.SetValue("Bones", player.GetSkinTransforms());
            }

            ShaderManager.CommitChanges();
            List <Effect> effects = new List <Effect>();

            game.GraphicsDevice.Clear(Color.Black);

            foreach (ModelMesh mesh in model.Meshes)
            {
                effects.Clear();

                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    effects.Add(part.Effect);
                    part.Effect = ShaderManager.GetCurrentEffect();
                }
                mesh.Draw();
                for (int i = 0; i < mesh.MeshParts.Count; i++)
                {
                    mesh.MeshParts[i].Effect = effects[i];
                }
            }

            ShadowMapManager.ResetGraphicsDevice(game.GraphicsDevice, old);

            Color[] textureColors = new Color[(int)(TextureSize.X * TextureSize.Y)];
            renderTarget.GetTexture().GetData <Color>(textureColors);

            Sillouette = new Texture2D(game.GraphicsDevice, (int)TextureSize.X, (int)TextureSize.Y);
            Sillouette.SetData <Color>(textureColors);
            return(renderTarget.GetTexture());
        }