Esempio n. 1
0
        public static void ReportRendererCrash(string logfile, string gameName, string minimumRequirementsPage, VRageRender.MyRenderExceptionEnum type)
        {
            string format;
            switch(type)
            {
                case VRageRender.MyRenderExceptionEnum.GpuNotSupported:
                    format = APP_ERROR_MESSAGE_LOW_GPU;
                    break;
                case VRageRender.MyRenderExceptionEnum.DriverNotInstalled:
                    format = APP_ERROR_MESSAGE_DRIVER_NOT_INSTALLED;
                    break;
                default:
                    format = APP_ERROR_MESSAGE_LOW_GPU;
                    break;
            }

            string text = String.Format(format, logfile, gameName, minimumRequirementsPage);
            Sandbox.MyMessageBox.Show(IntPtr.Zero, text, gameName, MessageBoxOptions.OkOnly | MessageBoxOptions.SystemModal | MessageBoxOptions.IconExclamation | MessageBoxOptions.SetForeground);
        }
 private bool nebula_selector(VRageRender.MyImpostorProperties properties)
 {
     return properties.ImpostorType == VRageRender.MyImpostorType.Nebula;
 }
        //  Update position, check collisions, etc. and draw if particle still lives.
        //  Return false if particle dies/timeouts in this tick.
        public bool Draw(VRageRender.MyBillboard billboard)
        {
            
            MyTransparentGeometry.StartParticleProfilingBlock("Distance calculation");
            //  This time is scaled according to planned lifespan of the particle

            // Distance for sorting
            billboard.DistanceSquared = (float)Vector3D.DistanceSquared(MyTransparentGeometry.Camera.Translation, m_actualPosition);

            MyTransparentGeometry.EndParticleProfilingBlock();

            // If distance to camera is really small don't draw it.
            if (billboard.DistanceSquared <= 0.1f)
            {
                return false;
            }

            MyTransparentGeometry.StartParticleProfilingBlock("Quad calculation");

            MyTransparentGeometry.StartParticleProfilingBlock("actualRadius");
            float actualRadius = 1;
            Radius.GetInterpolatedValue<float>(m_normalizedTime, out actualRadius);
            MyTransparentGeometry.EndParticleProfilingBlock();

            billboard.ContainedBillboards.Clear();

            billboard.Near = m_generation.GetEffect().Near;
            billboard.Lowres = m_generation.GetEffect().LowRes || VRageRender.MyRenderConstants.RenderQualityProfile.LowResParticles;
            billboard.CustomViewProjection = -1;
            billboard.ParentID = -1;

            float alpha = 1;

            if (Type == MyParticleTypeEnum.Point)
            {
                MyTransparentGeometry.StartParticleProfilingBlock("GetBillboardQuadRotated");
                GetBillboardQuadRotated(billboard, ref m_actualPosition, actualRadius, m_actualAngle);
                MyTransparentGeometry.EndParticleProfilingBlock();
            }
            else if (Type == MyParticleTypeEnum.Line)
            {
                if (MyUtils.IsZero(Velocity.LengthSquared()))
                    Velocity = MyUtils.GetRandomVector3Normalized();

                MyQuadD quad = new MyQuadD();

                MyPolyLineD polyLine = new MyPolyLineD();
                polyLine.LineDirectionNormalized = MyUtils.Normalize(Velocity);

                if (m_actualAngle > 0)
                {
                    polyLine.LineDirectionNormalized = Vector3.TransformNormal(polyLine.LineDirectionNormalized, Matrix.CreateRotationY(MathHelper.ToRadians(m_actualAngle)));
                }

                polyLine.Point0 = m_actualPosition;
                polyLine.Point1.X = m_actualPosition.X + polyLine.LineDirectionNormalized.X * actualRadius;
                polyLine.Point1.Y = m_actualPosition.Y + polyLine.LineDirectionNormalized.Y * actualRadius;
                polyLine.Point1.Z = m_actualPosition.Z + polyLine.LineDirectionNormalized.Z * actualRadius;

                if (m_actualAngle > 0)
                { //centerize
                    polyLine.Point0.X = polyLine.Point0.X - polyLine.LineDirectionNormalized.X * actualRadius * 0.5f;
                    polyLine.Point0.Y = polyLine.Point0.Y - polyLine.LineDirectionNormalized.Y * actualRadius * 0.5f;
                    polyLine.Point0.Z = polyLine.Point0.Z - polyLine.LineDirectionNormalized.Z * actualRadius * 0.5f;
                    polyLine.Point1.X = polyLine.Point1.X - polyLine.LineDirectionNormalized.X * actualRadius * 0.5f;
                    polyLine.Point1.Y = polyLine.Point1.Y - polyLine.LineDirectionNormalized.Y * actualRadius * 0.5f;
                    polyLine.Point1.Z = polyLine.Point1.Z - polyLine.LineDirectionNormalized.Z * actualRadius * 0.5f;
                }

                polyLine.Thickness = Thickness;
                var camPos = MyTransparentGeometry.Camera.Translation;
                MyUtils.GetPolyLineQuad(out quad, ref polyLine, camPos);

                if (this.m_generation.AlphaAnisotropic)
                {
                    float angle = 1 - Math.Abs(Vector3.Dot(MyUtils.Normalize(MyTransparentGeometry.Camera.Forward), polyLine.LineDirectionNormalized));
                    float alphaCone = (float)Math.Pow(angle, 0.5f);
                    alpha = alphaCone;
                }

                billboard.Position0 = quad.Point0;
                billboard.Position1 = quad.Point1;
                billboard.Position2 = quad.Point2;
                billboard.Position3 = quad.Point3;
            }
            else if (Type == MyParticleTypeEnum.Trail)
            {
                if (Quad.Point0 == Quad.Point2) //not moving particle
                    return false;
                if (Quad.Point1 == Quad.Point3) //not moving particle was previous one
                    return false;
                if (Quad.Point0 == Quad.Point3) //not moving particle was previous one
                    return false;

                billboard.Position0 = Quad.Point0;
                billboard.Position1 = Quad.Point1;
                billboard.Position2 = Quad.Point2;
                billboard.Position3 = Quad.Point3;

                //if (this.m_generation.AlphaAnisotropic)
             /*   { //Trails are anisotropic by default (nobody wants them to see ugly)
                    Vector3 lineDir = Vector3.Normalize(Quad.Point1 - Quad.Point0);
                    float angle = 1 - Math.Abs(Vector3.Dot(MyMwcUtils.Normalize(MyCamera.ForwardVector), lineDir));
                    float alphaCone = (float)Math.Pow(angle, 0.3f);
                    alpha = alphaCone;
                }*/
            }
            else
            {
                throw new NotSupportedException(Type + " is not supported particle type");
            }

            MyTransparentGeometry.EndParticleProfilingBlock();

            MyTransparentGeometry.StartParticleProfilingBlock("Material calculation");

            Vector4 color;
            Color.GetInterpolatedValue<Vector4>(m_normalizedTime, out color);

            var material1 = MyTransparentMaterials.GetMaterial("ErrorMaterial");
            var material2 = MyTransparentMaterials.GetMaterial("ErrorMaterial");
            float textureBlendRatio = 0;
            if ((Flags & ParticleFlags.BlendTextures) != 0)
            {
                float prevTime, nextTime, difference;
                Material.GetPreviousValue(m_normalizedTime, out material1, out prevTime);
                Material.GetNextValue(m_normalizedTime, out material2, out nextTime, out difference);

                if (prevTime != nextTime)
                    textureBlendRatio = (m_normalizedTime - prevTime) * difference;
            }
            else
            {
                Material.GetInterpolatedValue(m_normalizedTime, out material1);
            }

            MyTransparentGeometry.EndParticleProfilingBlock();
                     
            //This gets 0.44ms for 2000 particles
            MyTransparentGeometry.StartParticleProfilingBlock("billboard.Start");


            billboard.Material = material1.Name;
            billboard.BlendMaterial = material2.Name;
            billboard.BlendTextureRatio = textureBlendRatio;
            billboard.EnableColorize = false;

            billboard.Color = color * alpha * m_generation.GetEffect().UserColorMultiplier;

            MyTransparentGeometry.EndParticleProfilingBlock();

            return true;
        }
        public static VRageRender.MyBillboard AddBillboardParticle(MyAnimatedParticle particle, VRageRender.MyBillboard effectBillboard, bool sort)
        {
            //MyBillboard billboard = m_preallocatedParticleBillboards.Allocate();
            //VRageRender.MyBillboard billboard = new VRageRender.MyBillboard();
            VRageRender.MyBillboard billboard = VRageRender.MyRenderProxy.BillboardsPoolWrite.Allocate();
            if (billboard != null)
            {
                MyTransparentGeometry.StartParticleProfilingBlock("item.Value.Draw");
                if (particle.Draw(billboard) == true)
                {
                    if (!sort)
                        effectBillboard.ContainedBillboards.Add(billboard);

                    billboard.CustomViewProjection = -1;
                }
                else
                    billboard = null;

                MyTransparentGeometry.EndParticleProfilingBlock();
            }

            return billboard;
        }
 public void OnModeChanged(VRageRender.MyWindowModeEnum mode, int width, int height)
 {
 }
 public static void CreateBillboard(VRageRender.MyBillboard billboard, ref MyQuadD quad, string material, string blendMaterial, float textureBlendRatio,
     ref Color color, ref Vector3D origin, bool colorize = false, bool near = false, bool lowres = false)
 {
     Debug.Assert(material != null);
     CreateBillboard(billboard, ref quad, material, blendMaterial, textureBlendRatio, ref color, ref origin, Vector2.Zero, colorize, near, lowres);
 }
Esempio n. 7
0
        private static void GetBillboardQuadRotated(VRageRender.MyBillboard billboard, ref Vector3D position, Vector2 radius, ref Matrix transform, Vector3 left, Vector3 up)
        {
            //	Two main vectors of a billboard rotated around the view axis/vector
            Vector3D billboardAxisX = new Vector3D();
            billboardAxisX.X = radius.X * left.X;
            billboardAxisX.Y = radius.X * left.Y;
            billboardAxisX.Z = radius.X * left.Z;

            Vector3D billboardAxisY = new Vector3D();
            billboardAxisY.X = radius.Y * up.X;
            billboardAxisY.Y = radius.Y * up.Y;
            billboardAxisY.Z = radius.Y * up.Z;

            Vector3 v1 = Vector3.TransformNormal(billboardAxisX + billboardAxisY, transform);
            Vector3 v2 = Vector3.TransformNormal(billboardAxisX - billboardAxisY, transform);




            //	Coordinates of four points of a billboard's quad
            billboard.Position0.X = position.X + v1.X;
            billboard.Position0.Y = position.Y + v1.Y;
            billboard.Position0.Z = position.Z + v1.Z;

            billboard.Position1.X = position.X - v2.X;
            billboard.Position1.Y = position.Y - v2.Y;
            billboard.Position1.Z = position.Z - v2.Z;

            billboard.Position2.X = position.X - v1.X;
            billboard.Position2.Y = position.Y - v1.Y;
            billboard.Position2.Z = position.Z - v1.Z;

            billboard.Position3.X = position.X + v2.X;
            billboard.Position3.Y = position.Y + v2.Y;
            billboard.Position3.Z = position.Z + v2.Z;

        }
Esempio n. 8
0
        /// <summary>
        /// Return quad whos face is always looking to the camera. 
        /// IMPORTANT: This bilboard looks same as point vertexes (point sprites) - horizontal and vertical axes of billboard are always parallel to screen
        /// That means, if billboard is in the left-up corner of screen, it won't be distorted by perspective. If will look as 2D quad on screen. As I said, it's same as GPU points.
        /// </summary>
        private static void GetBillboardQuadRotated(VRageRender.MyBillboard billboard, ref Vector3D position, float radius, float angle)
        {
            float angleCos = radius * (float)Math.Cos(angle);
            float angleSin = radius * (float)Math.Sin(angle);

            //	Two main vectors of a billboard rotated around the view axis/vector
            Vector3D billboardAxisX = new Vector3D();
            billboardAxisX.X = angleCos * MyTransparentGeometry.Camera.Left.X + angleSin * MyTransparentGeometry.Camera.Up.X;
            billboardAxisX.Y = angleCos * MyTransparentGeometry.Camera.Left.Y + angleSin * MyTransparentGeometry.Camera.Up.Y;
            billboardAxisX.Z = angleCos * MyTransparentGeometry.Camera.Left.Z + angleSin * MyTransparentGeometry.Camera.Up.Z;

            Vector3D billboardAxisY = new Vector3D();
            billboardAxisY.X = -angleSin * MyTransparentGeometry.Camera.Left.X + angleCos * MyTransparentGeometry.Camera.Up.X;
            billboardAxisY.Y = -angleSin * MyTransparentGeometry.Camera.Left.Y + angleCos * MyTransparentGeometry.Camera.Up.Y;
            billboardAxisY.Z = -angleSin * MyTransparentGeometry.Camera.Left.Z + angleCos * MyTransparentGeometry.Camera.Up.Z;

            //	Coordinates of four points of a billboard's quad
            billboard.Position0.X = position.X + billboardAxisX.X + billboardAxisY.X;
            billboard.Position0.Y = position.Y + billboardAxisX.Y + billboardAxisY.Y;
            billboard.Position0.Z = position.Z + billboardAxisX.Z + billboardAxisY.Z;

            billboard.Position1.X = position.X - billboardAxisX.X + billboardAxisY.X;
            billboard.Position1.Y = position.Y - billboardAxisX.Y + billboardAxisY.Y;
            billboard.Position1.Z = position.Z - billboardAxisX.Z + billboardAxisY.Z;

            billboard.Position2.X = position.X - billboardAxisX.X - billboardAxisY.X;
            billboard.Position2.Y = position.Y - billboardAxisX.Y - billboardAxisY.Y;
            billboard.Position2.Z = position.Z - billboardAxisX.Z - billboardAxisY.Z;

            billboard.Position3.X = position.X + billboardAxisX.X - billboardAxisY.X;
            billboard.Position3.Y = position.Y + billboardAxisX.Y - billboardAxisY.Y;
            billboard.Position3.Z = position.Z + billboardAxisX.Z - billboardAxisY.Z;
        }
 //  Draws sprite batch at specified SCREEN position (in screen coordinates, not normalized coordinates).
 internal static void DrawSpriteBatch(Texture texture, Vector2 position, Rectangle? sourceRectangle, Color color, Vector2 rightVector, Vector2 origin, float scale, VRageRender.Graphics.SpriteEffects effects, float layerDepth)
 {
     //m_spriteBatch.Draw(texture, SharpDXHelper.ToSharpDX(position), SharpDXHelper.ToSharpDX(sourceRectangle), SharpDXHelper.ToSharpDX(color), rotation, SharpDXHelper.ToSharpDX(origin), scale, effects, layerDepth);
     DrawSprite(texture, position, sourceRectangle, color, rightVector, origin, scale, effects, layerDepth);
 }
Esempio n. 10
0
 static void DrawSprite(string texture, Rectangle destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, VRageRender.Graphics.SpriteEffects effects, float layerDepth, bool waitTillLoaded = true)
 {
     var destination = new RectangleF(destinationRectangle.X, destinationRectangle.Y, destinationRectangle.Width, destinationRectangle.Height);
     DrawSprite(texture, ref destination, false, ref sourceRectangle, color, rotation, ref origin, effects, layerDepth, waitTillLoaded);
 }
Esempio n. 11
0
 static void DrawSprite(string texture, ref RectangleF destination, bool scaleDestination, ref Rectangle? sourceRectangle, Color color, float rotation, ref Vector2 origin, VRageRender.Graphics.SpriteEffects effects, float depth, bool waitTillLoaded = true)
 {
     VRageRender.MyRenderProxy.DrawSprite(texture, ref destination, scaleDestination, ref sourceRectangle, color, rotation, Vector2.UnitX, ref origin, effects, depth, waitTillLoaded);
 }
Esempio n. 12
0
 static void DrawSprite(string texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, float scale, VRageRender.Graphics.SpriteEffects effects, float layerDepth, bool waitTillLoaded = true)
 {
     var destination = new RectangleF(position.X, position.Y, scale, scale);
     DrawSprite(texture, ref destination, true, ref sourceRectangle, color, rotation, ref origin, effects, layerDepth, waitTillLoaded);
 }
Esempio n. 13
0
 //  Draws sprite batch at specified SCREEN position (in screen coordinates, not normalized coordinates).
 public static void DrawSpriteBatch(string texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, float scale, VRageRender.Graphics.SpriteEffects effects, float layerDepth, bool waitTillLoaded = true)
 {
     DrawSprite(texture, position, sourceRectangle, color, rotation, origin, scale, effects, layerDepth, waitTillLoaded);
 }
Esempio n. 14
0
 public static void DrawSprite(string texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, VRageRender.Graphics.SpriteEffects effects, float layerDepth)
 {
     var destination = new RectangleF(position.X, position.Y, scale.X, scale.Y);
     DrawSprite(texture, ref destination, true, ref sourceRectangle, color, rotation, ref origin, effects, layerDepth);
 }
        public void OnModeChanged(VRageRender.MyWindowModeEnum windowMode, int width, int height)
        {
            if (windowMode == VRageRender.MyWindowModeEnum.Window)
            {
                FormBorderStyle = FormBorderStyle.FixedSingle;
                TopMost = false;
            }
            else if (windowMode == VRageRender.MyWindowModeEnum.FullscreenWindow)
            {
                FormBorderStyle = FormBorderStyle.None;
                TopMost = false; // false for fullscreen window, shouldn't matter for true fullscren
                SizeGripStyle = SizeGripStyle.Hide;
            }
            else if(windowMode == VRageRender.MyWindowModeEnum.Fullscreen)
            {
                FormBorderStyle = FormBorderStyle.None;
                // Fullscreen used to have same settings as FullscreenWindow, but Dx11 render required change for Shadow Play to work.
                // It still seems like TopMost and SizeGripStyle should carry over from other branches.
            }

            ClientSize = new System.Drawing.Size(width, height);

            WinApi.DEVMODE mode = new WinApi.DEVMODE();
            WinApi.EnumDisplaySettings(null, WinApi.ENUM_CURRENT_SETTINGS, ref mode);
            VRage.Trace.MyTrace.Watch("Current display settings", string.Format("{0}x{1}", mode.dmPelsWidth, mode.dmPelsHeight));
            if (MyFakes.MOVE_WINDOW_TO_CORNER)
            {
                Location = new System.Drawing.Point(mode.dmPelsWidth - width, 0);
            }
            else
            {
                Location = new System.Drawing.Point(mode.dmPelsWidth / 2 - width / 2, mode.dmPelsHeight / 2 - height / 2);
            }

            // TODO: OP! Should be on different place
            Show();
            Activate();

            MySandboxGame.Static.UpdateMouseCapture();
        }
 internal static void DrawSprite(Texture texture, Vector2 position, Rectangle? sourceRectangle, Color color, Vector2 rightVector, Vector2 origin, float scale, VRageRender.Graphics.SpriteEffects effects, float layerDepth)
 {
     var destination = new RectangleF(position.X, position.Y, scale, scale);
     DrawSprite(texture, null, ref destination, true, ref sourceRectangle, color, rightVector, ref origin, effects, layerDepth);
 }
Esempio n. 17
0
        //  Update position, check collisions, etc. and draw if particle still lives.
        //  Return false if particle dies/timeouts in this tick.
        public bool Draw(VRageRender.MyBillboard billboard)
        {
            if (Pivot != null && !MyParticlesManager.Paused)
            {
                if (PivotRotation != null)
                {
                    Matrix pivotRotationTransform =
                      Matrix.CreateRotationX(MathHelper.ToRadians(m_actualPivotRotation.X) * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS) *
                      Matrix.CreateRotationY(MathHelper.ToRadians(m_actualPivotRotation.Y) * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS) *
                      Matrix.CreateRotationZ(MathHelper.ToRadians(m_actualPivotRotation.Z) * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS);

                    m_actualPivot = Vector3.TransformNormal(m_actualPivot, pivotRotationTransform);
                }

                m_actualPivot = Vector3D.TransformNormal(m_actualPivot, m_generation.GetEffect().WorldMatrix);
            }

            var actualPosition = m_actualPosition + m_actualPivot;
            
            MyTransparentGeometry.StartParticleProfilingBlock("Distance calculation");
            //  This time is scaled according to planned lifespan of the particle

            // Distance for sorting
            billboard.DistanceSquared = (float)Vector3D.DistanceSquared(MyTransparentGeometry.Camera.Translation, actualPosition);

            MyTransparentGeometry.EndParticleProfilingBlock();

            // If distance to camera is really small don't draw it.
            if (billboard.DistanceSquared <= 0.1f)
            {
                return false;
            }

            MyTransparentGeometry.StartParticleProfilingBlock("Quad calculation");

            MyTransparentGeometry.StartParticleProfilingBlock("actualRadius");
            float actualRadius = 1;
            Radius.GetInterpolatedValue<float>(m_normalizedTime, out actualRadius);
            MyTransparentGeometry.EndParticleProfilingBlock();

            float actualAlphaCutout = 0;
            if (AlphaCutout != null)
            {
                MyTransparentGeometry.StartParticleProfilingBlock("AlphaCutout calculation");

                AlphaCutout.GetInterpolatedValue<float>(m_normalizedTime, out actualAlphaCutout);

                MyTransparentGeometry.EndParticleProfilingBlock();
            }

            billboard.ContainedBillboards.Clear();

            billboard.Near = m_generation.GetEffect().Near;
            billboard.Lowres = VRageRender.MyRenderConstants.RenderQualityProfile.LowResParticles;
            billboard.CustomViewProjection = -1;
            billboard.ParentID = -1;
            billboard.AlphaCutout = actualAlphaCutout;
            billboard.UVOffset = Vector2.Zero;
            billboard.UVSize = Vector2.One;



            float alpha = 1;


            Matrix transform = Matrix.Identity;
            Vector3 normal = Vector3.Forward;

            Vector3 actualVelocity = (Vector3)(m_actualPosition - m_previousPosition);

            float radiusBySpeed = m_generation.RadiusBySpeed;
            if (radiusBySpeed > 0)
            {
                float actualSpeed = actualVelocity.Length();
                actualRadius = Math.Max(actualRadius, actualRadius * m_generation.RadiusBySpeed * actualSpeed);
            }


            if (Type == MyParticleTypeEnum.Point)
            {
                MyTransparentGeometry.StartParticleProfilingBlock("GetBillboardQuadRotated");
               
                Vector2 actualRadiusV2 = new Vector2(actualRadius, actualRadius);

                if (Thickness > 0)
                {
                    actualRadiusV2.Y = Thickness;
                }

                if (m_generation.RotationReference == MyRotationReference.Camera)
                {
                    transform =
                       Matrix.CreateFromAxisAngle(MyTransparentGeometry.Camera.Right, m_actualAngle.X) *
                       Matrix.CreateFromAxisAngle(MyTransparentGeometry.Camera.Up, m_actualAngle.Y) *
                       Matrix.CreateFromAxisAngle(MyTransparentGeometry.Camera.Forward, m_actualAngle.Z);

                    GetBillboardQuadRotated(billboard, ref actualPosition, actualRadiusV2, ref transform, MyTransparentGeometry.Camera.Left, MyTransparentGeometry.Camera.Up);
                }
                else if (m_generation.RotationReference == MyRotationReference.Local)
                {
                    transform = Matrix.CreateFromAxisAngle(m_generation.GetEffect().WorldMatrix.Right, m_actualAngle.X) *
                    Matrix.CreateFromAxisAngle(m_generation.GetEffect().WorldMatrix.Up, m_actualAngle.Y) *
                    Matrix.CreateFromAxisAngle(m_generation.GetEffect().WorldMatrix.Forward, m_actualAngle.Z);

                    GetBillboardQuadRotated(billboard, ref actualPosition, actualRadiusV2, ref transform, m_generation.GetEffect().WorldMatrix.Left, m_generation.GetEffect().WorldMatrix.Up);
                }
                else if (m_generation.RotationReference == MyRotationReference.Velocity)
                {
                    if (actualVelocity.LengthSquared() < 0.00001f)
                        return false;

                    Matrix velocityRef = Matrix.CreateFromDir(Vector3.Normalize(actualVelocity));

                    transform = Matrix.CreateFromAxisAngle(velocityRef.Right, m_actualAngle.X) *
                    Matrix.CreateFromAxisAngle(velocityRef.Up, m_actualAngle.Y) *
                    Matrix.CreateFromAxisAngle(velocityRef.Forward, m_actualAngle.Z);

                    GetBillboardQuadRotated(billboard, ref actualPosition, actualRadiusV2, ref transform, velocityRef.Left, velocityRef.Up);
                }
                else if (m_generation.RotationReference == MyRotationReference.VelocityAndCamera)
                {
                    if (actualVelocity.LengthSquared() < 0.0001f)
                        return false;

                    Vector3 cameraToPoint = Vector3.Normalize(m_actualPosition - MyTransparentGeometry.Camera.Translation);
                    Vector3 velocityDir = Vector3.Normalize(actualVelocity);

                    Vector3 sideVector = Vector3.Cross(cameraToPoint, velocityDir);
                    Vector3 upVector = Vector3.Cross(sideVector, velocityDir);

                    Matrix velocityRef = Matrix.CreateWorld(m_actualPosition, velocityDir, upVector);

                    transform = Matrix.CreateFromAxisAngle(velocityRef.Right, m_actualAngle.X) *
                    Matrix.CreateFromAxisAngle(velocityRef.Up, m_actualAngle.Y) *
                    Matrix.CreateFromAxisAngle(velocityRef.Forward, m_actualAngle.Z);

                    GetBillboardQuadRotated(billboard, ref actualPosition, actualRadiusV2, ref transform, velocityRef.Left, velocityRef.Up);
                }
                else if (m_generation.RotationReference == MyRotationReference.LocalAndCamera)
                {
                    Vector3 cameraToPoint = Vector3.Normalize(m_actualPosition - MyTransparentGeometry.Camera.Translation);
                    Vector3 localDir = m_generation.GetEffect().WorldMatrix.Forward;
                    float dot = cameraToPoint.Dot(localDir);
                    Matrix velocityRef;
                    if (dot >= 0.9999f)
                    {
                        // TODO Petr: probably not correct, at least it does not produce NaN positions
                        velocityRef = Matrix.CreateTranslation(m_actualPosition);
                    }
                    else
                    {
                        Vector3 sideVector = Vector3.Cross(cameraToPoint, localDir);
                        Vector3 upVector = Vector3.Cross(sideVector, localDir);

                        velocityRef = Matrix.CreateWorld(m_actualPosition, localDir, upVector);
                    }

                    transform = Matrix.CreateFromAxisAngle(velocityRef.Right, m_actualAngle.X) *
                    Matrix.CreateFromAxisAngle(velocityRef.Up, m_actualAngle.Y) *
                    Matrix.CreateFromAxisAngle(velocityRef.Forward, m_actualAngle.Z);

                    GetBillboardQuadRotated(billboard, ref actualPosition, actualRadiusV2, ref transform, velocityRef.Left, velocityRef.Up);
                }
                else
                {
                    System.Diagnostics.Debug.Fail("Unknown RotationReference enum");
                }

                MyTransparentGeometry.EndParticleProfilingBlock();
            }
            else if (Type == MyParticleTypeEnum.Line)
            {
                if (MyUtils.IsZero(Velocity.LengthSquared()))
                    Velocity = MyUtils.GetRandomVector3Normalized();

                MyQuadD quad = new MyQuadD();

                MyPolyLineD polyLine = new MyPolyLineD();
                //polyLine.LineDirectionNormalized = MyUtils.Normalize(Velocity);
                if (actualVelocity.LengthSquared() > 0)
                    polyLine.LineDirectionNormalized = MyUtils.Normalize(actualVelocity);
                else
                    polyLine.LineDirectionNormalized = MyUtils.Normalize(Velocity);

                if (m_actualAngle.Z != 0)
                {
                    polyLine.LineDirectionNormalized = Vector3.TransformNormal(polyLine.LineDirectionNormalized, Matrix.CreateRotationY(m_actualAngle.Z));
                }

                polyLine.Point0 = actualPosition;
                polyLine.Point1.X = actualPosition.X - polyLine.LineDirectionNormalized.X * actualRadius;
                polyLine.Point1.Y = actualPosition.Y - polyLine.LineDirectionNormalized.Y * actualRadius;
                polyLine.Point1.Z = actualPosition.Z - polyLine.LineDirectionNormalized.Z * actualRadius;

                if (m_actualAngle.LengthSquared() > 0)
                { //centerize
                    polyLine.Point0.X = polyLine.Point0.X - polyLine.LineDirectionNormalized.X * actualRadius * 0.5f;
                    polyLine.Point0.Y = polyLine.Point0.Y - polyLine.LineDirectionNormalized.Y * actualRadius * 0.5f;
                    polyLine.Point0.Z = polyLine.Point0.Z - polyLine.LineDirectionNormalized.Z * actualRadius * 0.5f;
                    polyLine.Point1.X = polyLine.Point1.X - polyLine.LineDirectionNormalized.X * actualRadius * 0.5f;
                    polyLine.Point1.Y = polyLine.Point1.Y - polyLine.LineDirectionNormalized.Y * actualRadius * 0.5f;
                    polyLine.Point1.Z = polyLine.Point1.Z - polyLine.LineDirectionNormalized.Z * actualRadius * 0.5f;
                }

                polyLine.Thickness = Thickness;
                var camPos = MyTransparentGeometry.Camera.Translation;
                MyUtils.GetPolyLineQuad(out quad, ref polyLine, camPos);

                transform.Forward = polyLine.LineDirectionNormalized;

                billboard.Position0 = quad.Point0;
                billboard.Position1 = quad.Point1;
                billboard.Position2 = quad.Point2;
                billboard.Position3 = quad.Point3;
            }
            else if (Type == MyParticleTypeEnum.Trail)
            {
                if (Quad.Point0 == Quad.Point2) //not moving particle
                    return false;
                if (Quad.Point1 == Quad.Point3) //not moving particle was previous one
                    return false;
                if (Quad.Point0 == Quad.Point3) //not moving particle was previous one
                    return false;

                billboard.Position0 = Quad.Point0;
                billboard.Position1 = Quad.Point1;
                billboard.Position2 = Quad.Point2;
                billboard.Position3 = Quad.Point3;
            }
            else
            {
                throw new NotSupportedException(Type + " is not supported particle type");
            }

            if (this.m_generation.AlphaAnisotropic)
            {
                normal = Vector3.Normalize(Vector3.Cross(billboard.Position0 - billboard.Position1, billboard.Position0 - billboard.Position2));

                Vector3 forward = (billboard.Position0 + billboard.Position1 + billboard.Position2 + billboard.Position3) / 4 - MyTransparentGeometry.Camera.Translation;

                //Vector3 forward = MyTransparentGeometry.Camera.Forward;

                float angle = Math.Abs(Vector3.Dot(MyUtils.Normalize(forward), normal));


                float alphaCone = 1 - (float)Math.Pow(1 - angle, 4);
                alpha = alphaCone;
            }


            MyTransparentGeometry.EndParticleProfilingBlock();

            MyTransparentGeometry.StartParticleProfilingBlock("Material calculation");

            Vector4 color = Vector4.One;
            if (Color.GetKeysCount() > 0)
            {
                Color.GetInterpolatedValue<Vector4>(m_normalizedTime, out color);
            }

            if (m_arrayIndex != -1)
            {
                Vector3 arraySize = m_generation.ArraySize;
                if (arraySize.X > 0 && arraySize.Y > 0)
                {
                    int arrayOffset = m_generation.ArrayOffset;
                    int arrayModulo = m_generation.ArrayModulo == 0 ? (int)arraySize.X * (int)arraySize.Y : m_generation.ArrayModulo;

                    m_arrayIndex = m_arrayIndex % arrayModulo + arrayOffset;

                    float xDiv = 1.0f / arraySize.X;
                    float yDiv = 1.0f / arraySize.Y;
                    int xIndex = m_arrayIndex % (int)arraySize.X;
                    int yIndex = m_arrayIndex / (int)arraySize.X;

                    billboard.UVOffset = new Vector2(xDiv * xIndex, yDiv * yIndex);
                    billboard.UVSize = new Vector2(xDiv, yDiv);
                }
            }


            var material1 = MyTransparentMaterials.GetMaterial("ErrorMaterial");
            var material2 = MyTransparentMaterials.GetMaterial("ErrorMaterial");
            float textureBlendRatio = 0;
            if ((Flags & ParticleFlags.BlendTextures) != 0)
            {
                float prevTime, nextTime, difference;
                Material.GetPreviousValue(m_normalizedTime, out material1, out prevTime);
                Material.GetNextValue(m_normalizedTime, out material2, out nextTime, out difference);

                if (prevTime != nextTime)
                    textureBlendRatio = (m_normalizedTime - prevTime) * difference;
            }
            else
            {
                Material.GetInterpolatedValue(m_normalizedTime, out material1);
            }

            MyTransparentGeometry.EndParticleProfilingBlock();
                     
            //This gets 0.44ms for 2000 particles
            MyTransparentGeometry.StartParticleProfilingBlock("billboard.Start");

            if (material1 != null)
                billboard.Material = material1.Name;

            billboard.BlendMaterial = material2.Name;
            billboard.BlendTextureRatio = textureBlendRatio;
            billboard.EnableColorize = false;

            billboard.Color = color * alpha * m_generation.GetEffect().UserColorMultiplier;
            billboard.ColorIntensity = ColorIntensity;
            billboard.SoftParticleDistanceScale = SoftParticleDistanceScale;

            MyTransparentGeometry.EndParticleProfilingBlock();

            return true;
        }
 internal static void DrawSprite(BaseTexture texture, CubeMapFace? face, ref RectangleF destination, bool scaleDestination, ref Rectangle? sourceRectangle, Color color, Vector2 rightVector, ref Vector2 origin, VRageRender.Graphics.SpriteEffects effects, float depth)
 {
     DrawSpriteMain(texture, face, ref destination, scaleDestination, sourceRectangle, color, rightVector, ref origin, effects, depth);
 }
Esempio n. 19
0
 private static void GetBillboardQuadRotated(VRageRender.MyBillboard billboard, ref Vector3D position, Vector2 radius, ref Matrix transform)
 {
     GetBillboardQuadRotated(billboard, ref position, radius, ref transform, MyTransparentGeometry.Camera.Left, MyTransparentGeometry.Camera.Up);
 }
 public static void CreateBillboard(VRageRender.MyBillboard billboard, ref MyQuadD quad, string material,
     ref Vector4 color, ref Vector3D origin, Vector2 uvOffset, bool colorize = false, bool near = false, bool lowres = false, int customViewProjection = -1, float reflection = 0)
 {
     CreateBillboard(billboard, ref quad, material, "Test", 0, ref color, ref origin, uvOffset, colorize, near, lowres, customViewProjection, reflection);
 }
 public static void CreateBillboard(VRageRender.MyBillboard billboard, ref MyQuadD quad, string material,
     ref Color color, ref Vector3D origin, Vector2 uvOffset, bool colorize = false, bool near = false, bool lowres = false)
 {
     Debug.Assert(material != null);
     CreateBillboard(billboard, ref quad, material, null, 0, ref color, ref origin, uvOffset, colorize, near, lowres);
 }
 public static void CreateBillboard(VRageRender.MyBillboard billboard, ref MyQuadD quad, string material, string blendMaterial, float textureBlendRatio,
 ref Vector4 color, ref Vector3D origin, bool colorize = false, bool near = false, bool lowres = false, int customViewProjection = -1, float reflection = 0)
 {
     CreateBillboard(billboard, ref quad, material, blendMaterial, textureBlendRatio, ref color, ref origin, Vector2.Zero, colorize, near, lowres, customViewProjection, reflection);
 }
        //  This method is like a constructor (which we can't use because billboards are allocated from a pool).
        //  It starts/initializes a billboard. Refs used only for optimalization
        public static void CreateBillboard(VRageRender.MyBillboard billboard, ref MyQuadD quad, string material, string blendMaterial, float textureBlendRatio,
            ref Color color, ref Vector3D origin, Vector2 uvOffset, bool colorize = false, bool near = false, bool lowres = false, float reflectivity = 0)
        {
            Debug.Assert(material != null);
            
            if (string.IsNullOrEmpty(material) || !MyTransparentMaterials.ContainsMaterial(material))
            {
                material = "ErrorMaterial";
                color = Vector4.One;
            }

            billboard.Material = material;
            billboard.BlendMaterial = blendMaterial;
            billboard.BlendTextureRatio = textureBlendRatio;

            quad.Point0.AssertIsValid();
            quad.Point1.AssertIsValid();
            quad.Point2.AssertIsValid();
            quad.Point3.AssertIsValid();


            //  Billboard vertexes
            billboard.Position0 = quad.Point0;
            billboard.Position1 = quad.Point1;
            billboard.Position2 = quad.Point2;
            billboard.Position3 = quad.Point3;

            billboard.UVOffset = uvOffset;

            EnableColorize = colorize;

            if (EnableColorize)
                billboard.Size = (float)(billboard.Position0 - billboard.Position2).Length();

            //  Distance for sorting
            //  IMPORTANT: Must be calculated before we do color and alpha misting, because we need distance there
            billboard.DistanceSquared = (float)Vector3D.DistanceSquared(MyRenderCamera.Position, origin);

            //  Color
            billboard.Color = color;
            billboard.ColorIntensity = 1;
            billboard.Reflectivity = reflectivity;

            billboard.Near = near;
            billboard.Lowres = lowres;
            billboard.ParentID = -1;

            //  Alpha depends on distance to camera. Very close bilboards are more transparent, so player won't see billboard errors or rotating billboards
            var mat = MyTransparentMaterials.GetMaterial(billboard.Material);
            if (mat.AlphaMistingEnable)
                billboard.Color *= MathHelper.Clamp(((float)Math.Sqrt(billboard.DistanceSquared) - mat.AlphaMistingStart) / (mat.AlphaMistingEnd - mat.AlphaMistingStart), 0, 1);

            billboard.Color *= mat.Color;

            billboard.ContainedBillboards.Clear();
        }
Esempio n. 24
0
        public void OnModeChanged(VRageRender.MyWindowModeEnum windowMode, int width, int height)
        {
            if (!MyFakes.ENABLE_DX11_RENDERER)
            {
                if (windowMode == VRageRender.MyWindowModeEnum.Window)
                {
                    FormBorderStyle = FormBorderStyle.FixedSingle;
                    TopMost = false;
                }
                else
                {
                    FormBorderStyle = FormBorderStyle.None;
                    TopMost = false; // false for fullscreen window, shouldn't matter for true fullscren
                    SizeGripStyle = SizeGripStyle.Hide;
                }
            }
            else
            {
                if (windowMode == VRageRender.MyWindowModeEnum.Window)
                {
                    FormBorderStyle = FormBorderStyle.FixedSingle;
                    TopMost = false;
                }
                else if (windowMode == VRageRender.MyWindowModeEnum.FullscreenWindow)
                {
                    FormBorderStyle = FormBorderStyle.None;
                    TopMost = false; // false for fullscreen window, shouldn't matter for true fullscren
                    SizeGripStyle = SizeGripStyle.Hide;
                }
                else if(windowMode == VRageRender.MyWindowModeEnum.Fullscreen)
                {
                    FormBorderStyle = FormBorderStyle.None;
                }
            }

            ClientSize = new System.Drawing.Size(width, height);

            WinApi.DEVMODE mode = new WinApi.DEVMODE();
            WinApi.EnumDisplaySettings(null, WinApi.ENUM_CURRENT_SETTINGS, ref mode);
            VRage.Trace.MyTrace.Watch("Current display settings", string.Format("{0}x{1}", mode.dmPelsWidth, mode.dmPelsHeight));
            if (MyFakes.MOVE_WINDOW_TO_CORNER)
            {
                Location = new System.Drawing.Point(mode.dmPelsWidth - width, 0);
            }
            else
            {
                //if (MyFakes.ENABLE_DX11_RENDERER)
                //{
                //    Location = new System.Drawing.Point(0, 0);
                //}
                //else
                //{
                //    Location = new System.Drawing.Point(mode.dmPelsWidth / 2 - width / 2, mode.dmPelsHeight / 2 - height / 2);
                //}

                Location = new System.Drawing.Point(mode.dmPelsWidth / 2 - width / 2, mode.dmPelsHeight / 2 - height / 2);
            }

            // TODO: OP! Should be on different place
            Show();
            Activate();
        }