XNA Creators Club Online
Page 1 of 1 (16 items)
Sort Posts: Previous Next

Very poor performance when using Matrix.Createtranslation

Last post 10/2/2009 4:01 AM by increator. 15 replies.
  • 9/27/2009 1:16 PM

    Very poor performance when using Matrix.Createtranslation

    Im trying to render one game map. It's size is 256x256*8. In OpenGL i was using glTranslatef().
    In XNA i use Matrix.CreateTranslation in main loop but FPS is very low when i use higher values for X,Y,Z.

    Full code:
    1 using System; 
    2 using Microsoft.Xna.Framework; 
    3 using Microsoft.Xna.Framework.Graphics; 
    4 using Microsoft.Xna.Framework.Input; 
    5  
    6 using CitySimu.GameObjects; 
    7  
    8  
    9 namespace WindowsGame2 
    10
    11     /// <summary> 
    12     /// This is the main type for your game 
    13     /// </summary> 
    14     public class Game1 : Microsoft.Xna.Framework.Game 
    15     { 
    16  
    17         GraphicsDeviceManager graphics; 
    18         SpriteBatch spriteBatch; 
    19          
    20         VertexPositionTexture[] vertices; 
    21  
    22         Matrix world; 
    23  
    24         Matrix projection;       
    25  
    26         Camera camera; 
    27  
    28         
    29         private float _FPS = 0f, _TotalTime = 0f, _DisplayFPS = 0f; 
    30          
    31         public Game1() 
    32         { 
    33             graphics = new GraphicsDeviceManager( this ); 
    34             Content.RootDirectory = "Content"
    35  
    36             graphics.PreferredBackBufferWidth = 800; 
    37             graphics.PreferredBackBufferHeight = 600; 
    38             graphics.SynchronizeWithVerticalRetrace = false
    39             IsFixedTimeStep = false
    40  
    41             camera = new Camera( new Vector3( 0, 20, -40 ), Vector3.Zero ); 
    42         } 
    43  
    44         private void InitializeVertices() 
    45         { 
    46             vertices = new VertexPositionTexture[ 20 ]; 
    47  
    48             vertices[ 0 ] = new VertexPositionTexture( new Vector3( 0, 1, 1 ), new Vector2( 0, 0 ) ); 
    49             vertices[ 1 ] = new VertexPositionTexture( new Vector3( 1, 1, 1 ), new Vector2( 0, 0 ) ); 
    50             vertices[ 2 ] = new VertexPositionTexture( new Vector3( 1, 1, 0 ), new Vector2( 0, 0 ) ); 
    51             vertices[ 3 ] = new VertexPositionTexture( new Vector3( 0, 1, 0 ), new Vector2( 0, 0 ) ); 
    52  
    53             vertices[ 4 ] = new VertexPositionTexture( new Vector3( 1, 1, 1 ), new Vector2( 0, 0 ) ); 
    54             vertices[ 5 ] = new VertexPositionTexture( new Vector3( 0, 1, 1 ), new Vector2( 0, 0 ) ); 
    55             vertices[ 6 ] = new VertexPositionTexture( new Vector3( 0, 0, 1 ), new Vector2( 0, 0 ) ); 
    56             vertices[ 7 ] = new VertexPositionTexture( new Vector3( 1, 0, 1 ), new Vector2( 0, 0 ) ); 
    57  
    58             vertices[ 8 ] = new VertexPositionTexture( new Vector3( 0, 1, 1 ), new Vector2( 0, 0 ) ); 
    59             vertices[ 9 ] = new VertexPositionTexture( new Vector3( 1, 1, 1 ), new Vector2( 0, 0 ) ); 
    60             vertices[ 10 ] = new VertexPositionTexture( new Vector3( 1, 1, 0 ), new Vector2( 0, 0 ) ); 
    61             vertices[ 11 ] = new VertexPositionTexture( new Vector3( 0, 1, 0 ), new Vector2( 0, 0 ) ); 
    62  
    63             vertices[ 12 ] = new VertexPositionTexture( new Vector3( 0, 1, 1 ), new Vector2( 0, 0 ) ); 
    64             vertices[ 13 ] = new VertexPositionTexture( new Vector3( 1, 1, 1 ), new Vector2( 0, 0 ) ); 
    65             vertices[ 14 ] = new VertexPositionTexture( new Vector3( 1, 1, 0 ), new Vector2( 0, 0 ) ); 
    66             vertices[ 15 ] = new VertexPositionTexture( new Vector3( 0, 1, 0 ), new Vector2( 0, 0 ) ); 
    67         } 
    68  
    69         private void InitializeCamera() 
    70         { 
    71  
    72             float AspectRatio = ( float )graphics.GraphicsDevice.Viewport.Width / 
    73  
    74             ( float )graphics.GraphicsDevice.Viewport.Height; 
    75  
    76             Matrix.CreatePerspectiveFieldOfView( MathHelper.PiOver4, AspectRatio, 
    77  
    78             4.0f, 1000.0f, out projection ); 
    79         }  
    80  
    81         /// <summary> 
    82         /// Allows the game to perform any initialization it needs to before starting to run. 
    83         /// This is where it can query for any required services and load any non-graphic 
    84         /// related content.  Calling base.Initialize will enumerate through any components 
    85         /// and initialize them as well. 
    86         /// </summary> 
    87         protected override void Initialize() 
    88         { 
    89             InitializeVertices(); 
    90             InitializeCamera(); 
    91  
    92             graphics.GraphicsDevice.RenderState.CullMode = CullMode.CullClockwiseFace; 
    93  
    94             base.Initialize(); 
    95         } 
    96  
    97         /// <summary> 
    98         /// LoadContent will be called once per game and is the place to load 
    99         /// all of your content. 
    100         /// </summary> 
    101         protected override void LoadContent() 
    102         { 
    103             // Create a new SpriteBatch, which can be used to draw textures. 
    104             spriteBatch = new SpriteBatch( GraphicsDevice ); 
    105         } 
    106  
    107         /// <summary> 
    108         /// UnloadContent will be called once per game and is the place to unload 
    109         /// all content. 
    110         /// </summary> 
    111         protected override void UnloadContent() 
    112         { 
    113             // TODO: Unload any non ContentManager content here 
    114         }     
    115  
    116         /// <summary> 
    117         /// Allows the game to run logic such as updating the world, 
    118         /// checking for collisions, gathering input, and playing audio. 
    119         /// </summary> 
    120         /// <param name="gameTime">Provides a snapshot of timing values.</param> 
    121         protected override void Update( GameTime gameTime ) 
    122         { 
    123             // Allows the game to exit 
    124             if ( Keyboard.GetState( PlayerIndex.One ).IsKeyDown(Keys.Escape )) 
    125                 this.Exit(); 
    126             // TODO: Add your update logic here 
    127             base.Update( gameTime ); 
    128         } 
    129  
    130  
    131          
    132         /// <summary> 
    133         /// This is called when the game should draw itself. 
    134         /// </summary> 
    135         /// <param name="gameTime">Provides a snapshot of timing values.</param> 
    136         ///  
    137         protected override void Draw( GameTime gameTime ) 
    138         { 
    139             GraphicsDevice.Clear( Color.DarkSlateBlue ); 
    140              
    141  
    142             // Calculate the Frames Per Second 
    143             float ElapsedTime = ( float )gameTime.ElapsedRealTime.TotalSeconds; 
    144             _TotalTime += ElapsedTime; 
    145  
    146             if ( _TotalTime >= 1 ) 
    147             { 
    148                 _DisplayFPS = _FPS; 
    149                 _FPS = 0; 
    150                 _TotalTime = 0; 
    151             } 
    152             _FPS += 1; 
    153  
    154             // Format the string appropriately 
    155             string FpsText = _DisplayFPS.ToString() + " FPS"
    156             Window.Title = FpsText; 
    157  
    158             GraphicsDevice.VertexDeclaration = new VertexDeclaration( graphics.GraphicsDevice, VertexPositionTexture.VertexElements ); 
    159              
    160             BasicEffect effect = new BasicEffect( graphics.GraphicsDevice, null ); 
    161        
    162             for ( int y = 0; y < 5; y++ ) 
    163             { 
    164                 for ( int x = 0; x < 5; x++ ) 
    165                 { 
    166                     for ( int z = 0; z < 5; z++ ) 
    167                     { 
    168                         world = Matrix.CreateTranslation( 1.0f * x, 1.0f*z, 1.0f * y );// new Vector3( 1.0f * y, 0.0f, 1.0f * x ) ); 
    169                          
    170                         effect.World = world;                     
    171  
    172                         effect.Projection = projection; 
    173  
    174                         effect.View = Matrix.CreateLookAt( camera.Position, camera.LookAt, Vector3.Up ); 
    175                          
    176                         effect.TextureEnabled = false
    177  
    178                         effect.GraphicsDevice.RenderState.FillMode = FillMode.WireFrame; 
    179  
    180                         effect.Begin(); 
    181  
    182                         foreach ( EffectPass pass in effect.CurrentTechnique.Passes ) 
    183                         { 
    184  
    185                             pass.Begin(); 
    186  
    187                             GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>( PrimitiveType.TriangleStrip, vertices, 0, 18 ); 
    188  
    189                             pass.End(); 
    190  
    191                         } 
    192  
    193                         effect.End(); 
    194                     } 
    195                 } 
    196             } 
    197             base.Draw( gameTime ); 
    198         } 
    199  
    200        
    201     } 
    202
    203  


    As you see Effect stuff is all in main loop. Is this the problem here?

    How to get better performance or how to restructure this code, so it doesn't drop FPS to 1-2 when using higher loop X,Y,Z values.



    For example if X,Y,Z in loop are X:256, Y:256, Z:8 then FPS is only 1-2.



    Move the effect stuff to other place?

    Of course in the final app i will do culling and such stuff but this code FPS is very poor even if X,Y,Z are for example 25,25,8.




    Any hint, suggestions or snippet is welcome.
    Im just a bit new to XNA.




  • 9/27/2009 1:46 PM In reply to

    Re: Very poor performance when using Matrix.Createtranslation

    what you were doing in OpenGL is commonly called "immediate mode" drawing I believe, which when implemented in XNA like your code above, issues a LOT of calls to the graphics card, which is a big performance hit on 360.

    In other words, the use of Matrix.CreateTranslation() is not the real problem I suspect... instead I believe the problem is that you are calling Effect.Begin(), Pass.Begin(), Pass.End(), Effect.End() for every single object in your scene.

    To optimize this, I would suggest that you instead make a large vertex array (big enough to hold all of your objects), and translate the vertices into world space ahead of time.  then you can draw your entire world in 1 effect pass, with 1 draw call, which will greatly speed in your performance on the 360.  From what I understand, a key to good graphical performance on the 360 is to reduce the number of times you call any of the draw commands like GraphicsDevice.DrawUserPrimitives<>, etc.

    I recently had to refactor some code in my Pixel Boarder game to do the same (I was drawing each object individually, now I batch them into many fewer draw calls), and the performance increase was noticeable.

    hope that helps!
  • 9/27/2009 1:58 PM In reply to

    Re: Very poor performance when using Matrix.Createtranslation

    Just to mention i don't have 360, using only PC.


    Does your suggestions apply to PC also?
  • 9/27/2009 2:01 PM In reply to

    Re: Very poor performance when using Matrix.Createtranslation

    Hi there,

    You are also creating a new instance of BasicEffect every frame which is wasteful - just create one at class level and reuse.

    Cheers,

    Rod


    Rod MacDougall
    Gallus Games | Twitter
  • 9/27/2009 2:10 PM In reply to

    Re: Very poor performance when using Matrix.Createtranslation

    Just had an afterthought...

    Have you tried moving your effect.Begin() and effect.End() calls to before and after your nested for loops?  Not sure if that would work/help (I only do 2D stuff at the moment with SpriteBatch) but worth a try...

    Cheers,

    Rod
    Rod MacDougall
    Gallus Games | Twitter
  • 9/27/2009 2:17 PM In reply to

    Re: Very poor performance when using Matrix.Createtranslation

    I did as you suggested, moved the BasicEffect away to Initialization.
    And also moved the Begin / End out of the loop.


    Still low FPS.



    EDIT:

    PixelFriends
    Can you describe your implementation more closely?
    How you restructured this?


    Of course in the meantime i will work on my own but any snippet is very helpful.
  • 9/28/2009 3:51 AM In reply to

    Re: Very poor performance when using Matrix.Createtranslation

    OK guys, i found a good tutorial about drawing with vertex buffer.
    http://bobobobo.wordpress.com/2009/02/16/drawing-primitives-in-xna-from-a-vertex-buffer/

    I tried this, it works OK.


    But now i have problems with Matrix.CreateTranslation.

    How do i translate the vertices before they are drawn?
    I need to loop X,Y,Z and use the Matrix.CreateTranslation.



    Where is the correct place to put that Matrix.CreateTranslation ?




  • 9/28/2009 8:00 AM In reply to

    Re: Very poor performance when using Matrix.Createtranslation

    Add another method called TransformVertices()

    Call this method after you call InitializeVertices()

    It will do something along these lines:

    (you might want to pass in the world matrix as an argument to TransformVertices to make it more flexible - so you can transform with whatever matrix you like rather than the one built into the method - as shown below)

            void TransformVertices()  
            {  
                Matrix world = Matrix.CreateTranslation(da de da);  
                TransformVertices(world);  
            }  
     
            void TransformVertices(Matrix world)  
            {  
                VertexPositionTexture v;  
     
                for (int i = 0; i < vertices.Length; i++)  
                {  
                    v = vertices[i];  
                    v.Position = Vector3.Transform(v.Position, world);                
                    vertices[i] = v;  
                }  
            }  
     



    or alternatively do this transform directly in InitializeVertices when you build the vertices. But I would go with the separate method because its nice to build vertices in local space and keep that clean, then transform later at will.

    Game hobbyist hell-bent on coding a diabolical Matrix
  • 9/28/2009 10:08 AM In reply to

    Re: Very poor performance when using Matrix.Createtranslation

    The posters before me already explained it, but if you're looking for some cold, hard data -- I did some benchmarks a while ago that measure how many DrawPrimitive() / DrawUserPrimitive() calls the GraphicsDevice can handle both on the PC (with a GeForce 8) and on the XBox 360. The graph can be found on this page: Nuclex Framework - PrimitiveBatch.

    My own solution to the draw many small things problem also happens to be explained on the above page :) - it's a general purpose vertex batcher which collects vertices in a big array and sends them to the GPU in batches of 8192 even while you are still adding vertices to the array to keep the GPU busy (8192 seemed to be the optimal size for the XBox 360 for the vertex generation speeds that were typical in my own code).

    The pre-translation of vertices as shown by Craig Martin is required in any case, so you won't get around that one.

    Check out my website and blog for some interesting articles and useful utility classes!
    Nuclex Framework: threaded particles, skinnable GUI, vector fonts, texture atlasses and lots more.
    WiX XNA Installer: Professional-looking MSI installer template for XNA games.
  • 9/28/2009 2:10 PM In reply to

    Re: Very poor performance when using Matrix.Createtranslation

    As suggested, drawing multiple objects at once (with 1 draw call) is the key.

    currently in your code you're sacrificing speed to save memory, because you have enough vertices stored in memory for 1 object, and you have to keep reusing those verts to draw each object (which takes time).

    what we are suggesting instead is that you sacrifice memory for speed, by keeping vertices in memory for ALL objects, and then drawing them all at once, instead of 1-by-1.

    let us know if you need more help.
  • 9/28/2009 2:56 PM In reply to

    Re: Very poor performance when using Matrix.Createtranslation

    Many thanks for your replies. I will dig more into this all and will let you know if i can't get this to work.

    Another question, maybe you guys can suggest something on this problem also.



    Whole game map (world) is read into dynamic array before rendering.
    The map is stored as a 3D array of block_info structures. The size of this array is fixed at 256x256x8. This corresponds to x and y co-ordinates from 0 to 255 and z co-ordinates from 0 to 7.

    Im working on the map editor and this must be display any changes made by user immediately.
    So if user clicks somewhere on the map with mouse and changes map blocks then array data changes in PC memory.
    I repeat: not the data sent to vertex buffer changes but ARRAY content changes. Array just has so named ID numbers, where each ID tells what block sits at that X,Y,Z. If user changes block on map then this ID changes in array.



    But how renderer should know about these changes made by user? So whenever map is modified by user (at the same time data changes in array). How to tell to renderer that it must re-render map?


    Polling array data every frame?


    I have such thing in my Delphi map editor prototype and it is awful way. Performance is very poor.




    I always think about that and just can't get any good idea.




    Do you have any?








  • 9/28/2009 4:40 PM In reply to

    Re: Very poor performance when using Matrix.Createtranslation

    Wrap the 3D array in a class with an overridden indexer (eg. int this[int x, int y, int z]).

    When a new ID is assigned, the indexer not only changes the array but also sets either a dirty flag (if you want to rebuild the vertex buffer from scratch) or records which entries have changed in a list (if you have a vertex array and want to be clever about only updating those parts that have changed).

    In a game I working on I have something similar. There are buildings which can be placed on a map. The map has a grid which contains references for each building that is placed on a map cell. Buildings have a PositionChanged event, so whenever a building is added to the map, the map subscribes to this event and when the building is moved, the map will update. In addition to that, the map keeps a list of all buildings placed on it so I don't have to walk cell-by-cell through the map and collect unique buildings when the buildings are rendered each frame.

    Check out my website and blog for some interesting articles and useful utility classes!
    Nuclex Framework: threaded particles, skinnable GUI, vector fonts, texture atlasses and lots more.
    WiX XNA Installer: Professional-looking MSI installer template for XNA games.
  • 9/28/2009 9:38 PM In reply to

    Re: Very poor performance when using Matrix.Createtranslation



    If I were to optimize just the core loop, here are a few things I would do:

    Call Matrix.CreateTranslation() once before the loop.  Inside the loop, I would modify just the m41, m42, and m43 members for x, y, z.  The translation matrix is really a simple matrix that looks like this:

    1 0 0 0
    0 1 0 0
    0 0 1 0
    x y z 1

    So all you really have to do is take an identity matrix and modify m41, m42, and m43.

    If you consider that the Matrix is a value type, CreateTranslation() is returning a copy of the matrix it was using locally.  So the function first creates a matrix and copies the values into its local matrix, then the return value copies the values into your matrix.

    Next, I would create the view matrix once outside the loop.  The view matrix will benefit from the same optimization.  It doesn't appear to be changing inside the loop.

    This will cut down the amount of matrix allocations and copy operations in the tight loop.
  • 9/29/2009 5:53 PM In reply to

    Re: Very poor performance when using Matrix.Createtranslation

    Craig Martin.


    About your code. I did as you said.

    Matrix world = Matrix.CreateTranslation(da de da); 



    Should i put this into X,Y,Z loop?


    Something like this?

    void TransformVertices()   
            { 
                for ( int x = 0; x < 5; x++ ) 
                { 
                    for ( int y = 0; y < 5; y++ ) 
                    { 
                        for ( int z = 0; z < 5; z++ ) 
                        { 
                            Matrix world = Matrix.CreateTranslation(x, y, z); 
                            TransformVertices( world ); 
                        } 
                    } 
                } 
                 
            } 



    This doesn't work. It just displays one cube and after that TransformVertices()  it moves the cube far away somewhere and i see only one simple line on screen.

    I guess that im not using your code correctly?

    What im doing wrong?
  • 9/30/2009 9:36 AM In reply to

    Re: Very poor performance when using Matrix.Createtranslation

    You are currently drawing each Map block one at a time.
    At initialization you pre-build the vertices for a single map block at a zero local origin.

    Then at draw time, you loop through each map block position, and issue a draw call for a single block, translated to the current map block position via the world matrix.

    So if your map is 25 x 25 x 8, that is 5000 individual draw calls, which is too many by an order of 10.

    So what has been suggested is to pre-build the vertices for ALL the blocks, at the correct world position, and then just render them all with one draw call using an Identity world matrix (zero world origin).

    So to do that you need to change both your InitializeVertices method, and your Draw method.

    The InitializeVertices method needs to allocate one big array of vertices to hold the vertices for every map block.

            int xMapSize = 64; 
            int yMapSize = 8; 
            int zMapSize = 64; 
            int numberOfVerticesPerBlock = 24; 
            VertexPositionTexture[] mapVertices; 
     
            public void InitializeVertices() 
            { 
                mapVertices = new VertexPositionTexture[xMapSize * yMapSize * zMapSize * numberOfVerticesPerBlock]; 
                int vertexOffset = 0; 
     
                for (int x = 0; x < xMapSize; x++) 
                { 
                    for (int y = 0; y < yMapSize; y++) 
                    { 
                        for (int z = 0; z < zMapSize; z++) 
                        { 
                            AddVerticesForOneBlock(vertexOffset); 
     
                            Matrix world = Matrix.CreateScale(9) * Matrix.CreateTranslation(x * 10, z * 10, y * 10); 
                            TransformVertices(vertexOffset, world); 
     
                            vertexOffset += numberOfVerticesPerBlock; 
                        } 
                    } 
                } 
            } 
     
            void AddVerticesForOneBlock(int offset) 
            { 
                mapVertices[offset + 0] = new VertexPositionTexture(new Vector3(0, 0, 0), new Vector2(0, 0)); 
                mapVertices[offset + 1] = new VertexPositionTexture(new Vector3(0, 1, 0), new Vector2(0, 0)); 
                mapVertices[offset + 2] = new VertexPositionTexture(new Vector3(0, 1, 1), new Vector2(0, 0)); 
                mapVertices[offset + 3] = new VertexPositionTexture(new Vector3(0, 0, 0), new Vector2(0, 0)); 
                mapVertices[offset + 4] = new VertexPositionTexture(new Vector3(0, 1, 1), new Vector2(0, 0)); 
                mapVertices[offset + 5] = new VertexPositionTexture(new Vector3(0, 0, 1), new Vector2(0, 0)); 
     
                mapVertices[offset + 6] = new VertexPositionTexture(new Vector3(1, 0, 0), new Vector2(0, 0)); 
                mapVertices[offset + 7] = new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(0, 0)); 
                mapVertices[offset + 8] = new VertexPositionTexture(new Vector3(0, 1, 0), new Vector2(0, 0)); 
                mapVertices[offset + 9] = new VertexPositionTexture(new Vector3(1, 0, 0), new Vector2(0, 0)); 
                mapVertices[offset + 10] = new VertexPositionTexture(new Vector3(0, 1, 0), new Vector2(0, 0)); 
                mapVertices[offset + 11] = new VertexPositionTexture(new Vector3(0, 0, 0), new Vector2(0, 0)); 
     
                mapVertices[offset + 12] = new VertexPositionTexture(new Vector3(1, 0, 1), new Vector2(0, 0)); 
                mapVertices[offset + 13] = new VertexPositionTexture(new Vector3(1, 1, 1), new Vector2(0, 0)); 
                mapVertices[offset + 14] = new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(0, 0)); 
                mapVertices[offset + 15] = new VertexPositionTexture(new Vector3(1, 0, 1), new Vector2(0, 0)); 
                mapVertices[offset + 16] = new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(0, 0)); 
                mapVertices[offset + 17] = new VertexPositionTexture(new Vector3(1, 0, 0), new Vector2(0, 0)); 
     
                mapVertices[offset + 18] = new VertexPositionTexture(new Vector3(0, 0, 1), new Vector2(0, 0)); 
                mapVertices[offset + 19] = new VertexPositionTexture(new Vector3(0, 1, 1), new Vector2(0, 0)); 
                mapVertices[offset + 20] = new VertexPositionTexture(new Vector3(1, 1, 1), new Vector2(0, 0)); 
                mapVertices[offset + 21] = new VertexPositionTexture(new Vector3(0, 0, 1), new Vector2(0, 0)); 
                mapVertices[offset + 22] = new VertexPositionTexture(new Vector3(1, 1, 1), new Vector2(0, 0)); 
                mapVertices[offset + 23] = new VertexPositionTexture(new Vector3(1, 0, 1), new Vector2(0, 0)); 
            } 
     
            void TransformVertices(int offset, Matrix world) 
            { 
                VertexPositionTexture v; 
     
                for (int i = offset; i < offset + numberOfVerticesPerBlock; i++) 
                { 
                    v = mapVertices[i]; 
                    v.Position = Vector3.Transform(v.Position, world); 
                    mapVertices[i] = v; 
                } 
            } 
     


    And the Draw method now just does one DrawPrimitive call.

            public void Draw(GameTime gameTime) 
            { 
                GraphicsDevice.VertexDeclaration = vertexDeclaration; 
                GraphicsDevice.RenderState.DepthBufferEnable = true
                GraphicsDevice.RenderState.CullMode = CullMode.None; 
                GraphicsDevice.RenderState.AlphaBlendEnable = false
     
                effect.World = Matrix.Identity; 
                effect.Projection = Camera.ProjectionMatrix; 
                effect.View = Camera.ViewMatrix; 
                effect.EnableDefaultLighting(); 
                effect.TextureEnabled = true
                effect.Texture = testTexture; 
     
                effect.Begin(); 
                foreach (EffectPass pass in effect.CurrentTechnique.Passes) 
                { 
                    pass.Begin(); 
                    GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, mapVertices, 0, mapVertices.Length / numberOfVerticesPerBlock * 8); 
                    pass.End(); 
                } 
                effect.End(); 
            } 
     


    Game hobbyist hell-bent on coding a diabolical Matrix
  • 10/2/2009 4:01 AM In reply to

    Re: Very poor performance when using Matrix.Createtranslation

    Thanks alot Greg, you have done big work explaining and coding this.
    I got it working, atleast in wireframe mode. Seems promising.

    I will limit rendering only to cameras visible area. I have tested it in Delphi app and this algo seems to work fine.

    e = camera "eye" look. 
     
         x1 = int(e.x) - visibleRange; 
         y1 = int(e.z) - visibleRange; 
         x2 = int(e.x) + visibleRange; 
         y2 = int(e.z) + visibleRange; 
     
        if (x1 < 0) 
          x1 = 0; 
        if (y1 < 0) 
          y1 = 0; 
        if (x2 > 255) 
          x2 = 255; 
        if (y2 > 255) 
          y2 = 255; 
     
     
    and last just looping with new x1,y1,x2,y2 values through the map... 

    Of course i will modify code by myself and will post the results here for you all to see.
    Will try it with textures also.
Page 1 of 1 (16 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG