Пример #1
0
        public override void Render(DwarfTime gameTime,
                                    ChunkManager chunks,
                                    Camera camera,
                                    SpriteBatch spriteBatch,
                                    GraphicsDevice graphicsDevice,
                                    Effect effect,
                                    bool renderingForWater)
        {
            base.Render(gameTime, chunks, camera, spriteBatch, graphicsDevice, effect, renderingForWater);

            if (!IsVisible)
            {
                return;
            }

            if (CurrentAnimation != null && CurrentAnimation.CurrentFrame >= 0 && CurrentAnimation.CurrentFrame < CurrentAnimation.Primitives.Count)
            {
                CurrentAnimation.PreRender();
                SpriteSheet = CurrentAnimation.SpriteSheet;
                effect.Parameters["xTexture"].SetValue(SpriteSheet.GetTexture());

                if (OrientationType != OrientMode.Fixed)
                {
                    if (camera.Projection == Camera.ProjectionMode.Perspective)
                    {
                        if (OrientationType == OrientMode.Spherical)
                        {
                            float  xscale      = GlobalTransform.Left.Length();
                            float  yscale      = GlobalTransform.Up.Length();
                            float  zscale      = GlobalTransform.Forward.Length();
                            Matrix rot         = Matrix.CreateRotationZ(BillboardRotation);
                            Matrix bill        = Matrix.CreateBillboard(GlobalTransform.Translation, camera.Position, camera.UpVector, null);
                            Matrix noTransBill = bill;
                            noTransBill.Translation = Vector3.Zero;

                            Matrix worldRot = Matrix.CreateScale(new Vector3(xscale, yscale, zscale)) * rot * noTransBill;
                            worldRot.Translation = bill.Translation;
                            effect.Parameters["xWorld"].SetValue(worldRot);
                        }
                        else
                        {
                            Vector3 axis = Vector3.Zero;

                            switch (OrientationType)
                            {
                            case OrientMode.XAxis:
                                axis = Vector3.UnitX;
                                break;

                            case OrientMode.YAxis:
                                axis = Vector3.UnitY;
                                break;

                            case OrientMode.ZAxis:
                                axis = Vector3.UnitZ;
                                break;
                            }

                            Matrix worldRot = Matrix.CreateConstrainedBillboard(GlobalTransform.Translation, camera.Position, axis, null, null);
                            effect.Parameters["xWorld"].SetValue(worldRot);
                        }
                    }
                    else
                    {
                        Matrix rotation = Matrix.CreateRotationY(-(float)Math.PI * 0.25f) * Matrix.CreateTranslation(GlobalTransform.Translation);
                        effect.Parameters["xWorld"].SetValue(rotation);
                    }
                }
                else
                {
                    effect.Parameters["xWorld"].SetValue(GlobalTransform);
                }


                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    CurrentAnimation.Primitives[CurrentAnimation.CurrentFrame].Render(graphicsDevice);
                }
            }
        }
Пример #2
0
        public void Render(DwarfTime gameTime,
                           ChunkManager chunks,
                           Camera camera,
                           SpriteBatch spriteBatch,
                           GraphicsDevice graphicsDevice,
                           Shader effect,
                           bool renderingForWater)
        {
            if (!IsVisible)
            {
                return;
            }

            if (CurrentAnimation == null || CurrentAnimation.CurrentFrame < 0 ||
                CurrentAnimation.CurrentFrame >= CurrentAnimation.Primitives.Count)
            {
                return;
            }

            GamePerformance.Instance.StartTrackPerformance("Render - Sprite");

            // Everything that draws should set it's tint, making this pointless.
            Color origTint = effect.VertexColorTint;

            ApplyTintingToEffect(effect);


            CurrentAnimation.PreRender();
            SpriteSheet = CurrentAnimation.SpriteSheet;
            var currDistortion = VertexNoise.GetNoiseVectorFromRepeatingTexture(GlobalTransform.Translation);
            var distortion     = currDistortion * 0.1f + prevDistortion * 0.9f;

            prevDistortion = distortion;
            switch (OrientationType)
            {
            case OrientMode.Spherical:
            {
                Matrix bill = Matrix.CreateBillboard(GlobalTransform.Translation, camera.Position, camera.UpVector, null) * Matrix.CreateTranslation(distortion);
                //Matrix noTransBill = bill;
                //noTransBill.Translation = Vector3.Zero;

                //Matrix worldRot = noTransBill;
                //worldRot.Translation = bill.Translation;// + VertexNoise.GetNoiseVectorFromRepeatingTexture(bill.Translation);
                effect.World = bill;
                break;
            }

            case OrientMode.Fixed:
            {
                Matrix rotation = GlobalTransform;
                rotation.Translation = rotation.Translation + distortion;
                effect.World         = rotation;
                break;
            }

            case OrientMode.YAxis:
            {
                Matrix worldRot = Matrix.CreateConstrainedBillboard(GlobalTransform.Translation, camera.Position, Vector3.UnitY, null, null);
                worldRot.Translation = worldRot.Translation + distortion;
                effect.World         = worldRot;
                break;
            }
            }

            effect.MainTexture = SpriteSheet.GetTexture();

            if (DrawSilhouette)
            {
                Color oldTint = effect.VertexColorTint;
                effect.VertexColorTint           = SilhouetteColor;
                graphicsDevice.DepthStencilState = DepthStencilState.None;
                var oldTechnique = effect.CurrentTechnique;
                effect.CurrentTechnique = effect.Techniques[Shader.Technique.Silhouette];
                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    CurrentAnimation.Primitives[CurrentAnimation.CurrentFrame].Render(graphicsDevice);
                }

                graphicsDevice.DepthStencilState = DepthStencilState.Default;
                effect.VertexColorTint           = oldTint;
                effect.CurrentTechnique          = oldTechnique;
            }

            if (EnableWind)
            {
                effect.EnableWind = true;
            }

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                CurrentAnimation.Primitives[CurrentAnimation.CurrentFrame].Render(graphicsDevice);
            }
            effect.VertexColorTint = origTint;
            effect.EnableWind      = false;

            GamePerformance.Instance.StopTrackPerformance("Render - Sprite");
        }
Пример #3
0
        public void Render(DwarfTime gameTime,
                           ChunkManager chunks,
                           Camera camera,
                           SpriteBatch spriteBatch,
                           GraphicsDevice graphicsDevice,
                           Shader effect,
                           bool renderingForWater)
        {
            ApplyTintingToEffect(effect);

            if (!IsVisible)
            {
                return;
            }

            if (CurrentAnimation != null && CurrentAnimation.CurrentFrame >= 0 && CurrentAnimation.CurrentFrame < CurrentAnimation.Primitives.Count)
            {
                CurrentAnimation.PreRender();
                SpriteSheet = CurrentAnimation.SpriteSheet;
                if (OrientationType != OrientMode.Fixed)
                {
                    if (camera.Projection == Camera.ProjectionMode.Perspective)
                    {
                        if (OrientationType == OrientMode.Spherical)
                        {
                            float  xscale      = GlobalTransform.Left.Length();
                            float  yscale      = GlobalTransform.Up.Length();
                            float  zscale      = GlobalTransform.Forward.Length();
                            Matrix rot         = Matrix.CreateRotationZ(BillboardRotation);
                            Matrix bill        = Matrix.CreateBillboard(GlobalTransform.Translation, camera.Position, camera.UpVector, null);
                            Matrix noTransBill = bill;
                            noTransBill.Translation = Vector3.Zero;

                            Matrix worldRot = Matrix.CreateScale(new Vector3(xscale, yscale, zscale)) * rot * noTransBill;
                            worldRot.Translation = DistortPosition ? bill.Translation + VertexNoise.GetNoiseVectorFromRepeatingTexture(bill.Translation) : bill.Translation;
                            effect.World         = worldRot;
                        }
                        else
                        {
                            Vector3 axis = Vector3.Zero;

                            switch (OrientationType)
                            {
                            case OrientMode.XAxis:
                                axis = Vector3.UnitX;
                                break;

                            case OrientMode.YAxis:
                                axis = Vector3.UnitY;
                                break;

                            case OrientMode.ZAxis:
                                axis = Vector3.UnitZ;
                                break;
                            }

                            Matrix worldRot = Matrix.CreateConstrainedBillboard(GlobalTransform.Translation, camera.Position, axis, null, null);
                            worldRot.Translation = DistortPosition ? worldRot.Translation + VertexNoise.GetNoiseVectorFromRepeatingTexture(worldRot.Translation) : worldRot.Translation;
                            effect.World         = worldRot;
                        }
                    }
                    else
                    {
                        Matrix rotation = Matrix.CreateRotationY(-(float)Math.PI * 0.25f) * Matrix.CreateTranslation(GlobalTransform.Translation);
                        rotation.Translation = DistortPosition ? rotation.Translation + VertexNoise.GetNoiseVectorFromRepeatingTexture(rotation.Translation) : rotation.Translation;
                        effect.World         = rotation;
                    }
                }
                else
                {
                    Matrix rotation = GlobalTransform;
                    rotation.Translation = DistortPosition ? rotation.Translation + VertexNoise.GetNoiseVectorFromRepeatingTexture(rotation.Translation) : rotation.Translation;
                    effect.World         = rotation;
                }


                effect.MainTexture = SpriteSheet.GetTexture();
                if (DrawSilhouette)
                {
                    Color oldTint = effect.VertexColorTint;
                    effect.VertexColorTint           = SilhouetteColor;
                    graphicsDevice.DepthStencilState = DepthStencilState.None;
                    var oldTechnique = effect.CurrentTechnique;
                    effect.CurrentTechnique = effect.Techniques[Shader.Technique.Silhouette];
                    foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                    {
                        pass.Apply();
                        CurrentAnimation.Primitives[CurrentAnimation.CurrentFrame].Render(graphicsDevice);
                    }

                    graphicsDevice.DepthStencilState = DepthStencilState.Default;
                    effect.VertexColorTint           = oldTint;
                    effect.CurrentTechnique          = oldTechnique;
                }

                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    CurrentAnimation.Primitives[CurrentAnimation.CurrentFrame].Render(graphicsDevice);
                }
            }
        }