Results 1 to 3 of 3
  1. #1
    abuckau907's Avatar
    Join Date
    Dec 2012
    Gender
    male
    Location
    other side of the wire
    Posts
    1,342
    Reputation
    162
    Thanks
    239
    My Mood
    Cold

    xna 4 - rendering terrain - CullMode and Wireframe

    I'm using XNA 4.0 in C# (.net framework 4.0) (windows xp sp3, so directx9)

    Loading a .png as a height-map and creating terrain from that data. basically following tutorial at reimers.net
    (.png is < 256x256 -- not very large, not too many points in the buffers)

    Anyway, I get the terrain data created, that works fine. (as in the tutorial) I create an array if indices and vertices which can be used with GraphicsDevice.DrawUserIndexPrimitive() -- but this must send the data from cpu to gpu each frame, so there is a relatively small data size limit.

    So now I'm trying to use VertextBuffer and IndexBuffer, so the data can be stored on the gpu.

    The problem: When I draw it as wireframe, my fps drops WAY down...like 2-4 fps.

    The weird thing: When I was first rendering terrain, and sending the data from cpu to gpu, wireframe worked at 60fps just like FillMode = Solid. However, now that I'm using VertexBuffer and IndexBuffer, wireframe goes 2-4 fps I'm not sure why. It's not really a problem yet, because I plan to render the terrain solid ofc..but I'm curious as to why it's so much slower. The vertex/index buffers are on the gpu, so why is wireframe rendering taking so much longer? I even tried messing with Cullmode = none/clock/counter , which helped some, but still less fps than when sending the data each frame. Which doesn't make sense.

    Here the terrain section of my Draw() method.

    Code:
    ..
                _wireFrame = new RasterizerState();
                _wireFrame.CullMode = CullMode.None ; // tried CW And CCW: performance gain! but still < 40fps
                _wireFrame.FillMode = FillMode.WireFrame;
    ..
    ..
            public void Draw()
            {
             ..
             ..
                //Draw terrain
                _gameEngine.GraphicsDevice.RasterizerState = _wireFrame;  // _noCulling;
                _gameEngine.GraphicsDevice.Indices = _terrain.IndexBuffer;
                _gameEngine.GraphicsDevice.SetVertexBuffer(_terrain.VertexBuffer);
                _drawEffects.Parameters["xView"].SetValue(ViewMatrix);
                _drawEffects.Parameters["xProjection"].SetValue(Projecti********);
                _drawEffects.Parameters["xWorld"].SetValue(_terrain.WorldMatrix);
                foreach (EffectPass pass in _drawEffects.CurrentTechnique.Passes)
                  {
                    pass.Apply();
                    //_gameEngine.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList,_terrain._vertices, 0, _terrain._vertices.Length, _terrain._indices, 0, _terrain._indices.Length / 3, VertexPositionColor.VertexDeclaration);
                   _gameEngine.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, _terrain.VerticesCount, 0, _terrain.IndicesCount / 3);
                }
    (the commented line under pass.Apply() was my first method of drawing terrain. Now i store the data on gpu via vertex/index buffers.

    So, why the drop in speed?

    Any comments appreciated.

    edit:
    figured out the problem (well, not really)
    Basically WireFrame goes really slow if you have too many points on screen.
    Solid doesn't have this problem.




    So: Apparently when the terrain is rendered SOLID, cullmode doesn't matter. Setting it to None will still leave FPS at 60+ even if all the points are currently on screen.
    When you render it in WireFrame, cullmode matters and fps CRAWLS if you have too many points on screen.
    Just kind of took my by surprise, but I guess it should make sense.
    Since I'm not planning (yet?) on using wireframe for anything, it's not really a problem: a 512x512 image worth of points will show at 60+ fps, as long as it's Solid. I'll be doing stress tests soon.
    .
    .
    A Bunch of screenshots below
    (pretty cheesy, but cool at how many looks you can get with only modifying a few lines of code)
    .

    few different effects by only changing a couple lines of code


    and when you scale up the map coordinates (the two constants in my code that were = 1)
    you get semi-real world sized terrain. At the cost of a 256x256 picture. Pretty cool.
    Since I just got a few random heightmaps from google, it doesn't look "like a level", but you can see the potential.

    .
    .
    Next: I guess I should make some type of terrain editor, but the math behind line-of-sight and figuring out which poly the cursor would be on scares me a little. So for now I'm just going manually make a few heightmaps and work on loading them together and how to swap them in and out of memory as you move. And adding textures of course (and lod(?!)) so the ground looks better. And before that, actually keeping the player on the terrain and semi-realistic climb/slide physics. I know there are dozens of ways to do this, and it all depends on the type of game you're making. I'm going for semi-open world like most mmorpg's have where you can travel most of the world without a loading screen. If anyone wants to do something similar, or has advice, or questions, reply plz.

    moved to C# Programming Section due to lack of activity here

    mod please erase?
    Last edited by abuckau907; 01-21-2013 at 11:42 AM.
    'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
    --
     

    My posts have some inaccuracies/are wrong/wrong keyword(s) used.
    They're (maybe) pretty close, and I hope they helped you, not created confusion. Take with grain of salt.

    -if you give rep, please leave a comment, else it means less.

  2. #2
    Rechocto's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Posts
    128
    Reputation
    56
    Thanks
    107
    it's a bit hard to use at first, but you should check out a program called TeraGen

  3. #3
    abuckau907's Avatar
    Join Date
    Dec 2012
    Gender
    male
    Location
    other side of the wire
    Posts
    1,342
    Reputation
    162
    Thanks
    239
    My Mood
    Cold
    Thanks, I'll look into it if I ever get back into gaming. It was more of an exercise to learn, not make realistic scenes. I wanted to better understand how much data a scene actually takes / a good way of keeping that organized. It was basically copied verbatim from the site mentioned in op. Not much there, but I thought it was cool .
    'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
    --
     

    My posts have some inaccuracies/are wrong/wrong keyword(s) used.
    They're (maybe) pretty close, and I hope they helped you, not created confusion. Take with grain of salt.

    -if you give rep, please leave a comment, else it means less.

Similar Threads

  1. [Detected] Chams and Wireframe :D
    By Ardnez in forum Soldier Front Hacks
    Replies: 11
    Last Post: 08-28-2010, 07:59 AM
  2. [Release] Chams No Fog and wirefram works for Everything
    By Ertalvens in forum Combat Arms Hacks & Cheats
    Replies: 198
    Last Post: 09-14-2009, 07:23 AM
  3. What Does Skeleton and Wireframe do?
    By XSnapSX in forum CrossFire Hacks & Cheats
    Replies: 14
    Last Post: 08-03-2009, 11:48 PM
  4. Free Chams,CrossHair,WallHack,FullBright,and WireFrame
    By enriqueb4567 in forum Combat Arms Hacks & Cheats
    Replies: 97
    Last Post: 04-20-2009, 11:20 AM
  5. check out my chams and wireframe for int warrock
    By cjg333 in forum WarRock - International Hacks
    Replies: 17
    Last Post: 08-26-2007, 08:31 PM