Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Vertex Transform vs SetTransform(D3DTS_WORLD..

  1. #1

    Vertex Transform vs SetTransform(D3DTS_WORLD..

    I would like to have some advice on this.

    I was transforming each vertex of my meshes in DirectX 9 before using DrawPrimitive. I thought that was the common method to rotate, translate and scale meshes. Then I found that instead, I could use SetTransform(D3DTS_WORLD... saving the processing to transform each vertex.

    Now I'm thinking on an optimization method, in which I could sort the meshes by texture, shaders, etc, and then make a large vertex buffer to store several transformed meshes that share those elements. That way I could draw a batch of meshes in one go with DrawPrimitive. The problem of that is that I have to return to the old method of transforming each vertex, instead of using the World transform.

    Then what's optimal? Drawing several buffers transformed fastly with the World matrix, or drawing a large buffer containing vertices transformed one by one?

  2. #2

    Vertex Transform vs SetTransform(D3DTS_WORLD..

    Hmm.... :think:

    I am currently transforming my vertices using D3DXVec3Transform wich works fine.
    I dont know what method is faster.. The idea of Changing the world transformation matrix never occured in me.

    If changing the world matrix seems to be faster then you could do the following:
    >>Put all the data in a large vertexbuffer
    >>Split the data in different objects/meshes, each with their own world transformation matrix.
    >>Every time you render, you set the world matrix for a specific object/mesh and then render it.
    After that you set the world matrix for the next one .. and render that one as well. In this way you could render all your data from a single Vertexbuffer and use the world matrix.

    I didn't test this, so i dont know wheter it is possible, but it seems ok to me.

    Good luck

    BTW: Using indexbuffers is also a good way to improve preformance.. At least it occupies less Video-Ram. Maybe you should consider using DrawIndexedPrimitive instead of DrawPrimitive.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  3. #3

    Vertex Transform vs SetTransform(D3DTS_WORLD..

    You are right, I forgot it's possible to split the drawing with DrawPrimitive's parameters. :mrgreen:

    I am currently transforming my vertices using D3DXVec3Transform wich works fine. Smile
    I dont know what method is faster.. The idea of Changing the world transformation matrix never occured in me.
    Yes, it's faster. Because your don't have to do that operation of multiplying by the transformation matrix each vertex. But the trick only works for position and normals, not for texture coordinates. I kept half of my transformation code to update U,V. I realized transforming the World matrix would work from watching code about animation skinning. I tried it with the camera, lights and relative transformations, and it seems to work correctly in every case. They also use D3DTS_WORLDMATRIX(index), but I still don't understand what is it for... maybe it's for saving the state of the World matrix while crawling the skinning tree.

    BTW: Using indexbuffers is also a good way to improve preformance.. At least it occupies less Video-Ram. Maybe you should consider using DrawIndexedPrimitive instead of DrawPrimitive. Smile
    Good advice, but I can't use it because I need more control over the texture coordinates.

  4. #4

    Vertex Transform vs SetTransform(D3DTS_WORLD..

    Yes, it's faster. Because your don't have to do that operation of multiplying by the transformation matrix each vertex.
    Hmm... i doubt it. I think that the per vertex transformation must be done anyway. The only difference is: doing it Internally in D3D or do it yourself. I dont understand why the World matrix method is faster. :?
    If you noticed any speed increases , those probably only exist due the fact that the D3D implementation works faster than that one you wrote.

    I am not completely sure about this.. the above is my own conclusion.

    But the trick only works for position and normals, not for texture coordinates.
    I dont understand why you want to transform the U,V coordinates. This is not nessecary when you preform ordinary translations, rotations etc.
    The only reason why i think you should change these coords, is animation and things like that.


    Good advice, but I can't use it because I need more control over the texture coordinates.
    Sorry but i dont understand why you have more control over vertex-coords when using DrawPrimitive instead of DrawIndexedPrimitive.
    The only difference between these two is the way the vertex data is interpreted.
    Even with an indexbuffer, you can still use vertex-coords the same way as before
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  5. #5

    Vertex Transform vs SetTransform(D3DTS_WORLD..

    Well, I'm not willing to sell the method, I think everyone should experiment make their own conclusions. I'm just sharing that I found the World transformation to be faster and it fits my needs. To test the speed of that transformation I loaded two 3D models and rotated them, one realtive to the other. The I switched the World transformation off, and you might not believe me, but instead of going faster, it went slower without the World transformation. Maybe because without the transformation both models ended at the same position, increasing the Z comparissons. Anyway, the World transformation doesn't consume significant time, and I'm sure the time wasted by the vertex transformation loop is proportional to the number of vertex. So, I'm keeping with the World transform. On the other hand, that's the method to transform skinning bones. If I find I'm wrong I have no problem on switching back to per vertex transform

    I dont understand why you want to transform the U,V coordinates. This is not nessecary when you preform ordinary translations, rotations etc.
    The only reason why i think you should change these coords, is animation and things like that. Smile
    Exactly! It's a feature available in my engine. And I'm using tiled textures, there is no way to use them with Indexed primitives.

  6. #6

    Vertex Transform vs SetTransform(D3DTS_WORLD..

    To test the speed of that transformation I loaded two 3D models and rotated them, one realtive to the other. The I switched the World transformation off, and you might not believe me, but instead of going faster, it went slower without the World transformation. Maybe because without the transformation both models ended at the same position, increasing the Z comparissons.
    Okay.. You tested it.. Great :razz:. I will try the world-transformation method too.

    Good luck
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  7. #7

    Vertex Transform vs SetTransform(D3DTS_WORLD..

    Great! Please post your results.

    By the way, do you know what's the largest size for a vertex buffer? I can't find that information, and I need it to make the batch primitives.

  8. #8

    Vertex Transform vs SetTransform(D3DTS_WORLD..

    of course.. I will post my results :razz:

    No i dont know that for sure.. but i think this is limited to the available ammount of video-memory.
    Since there is no good way of retrieving the ammount of available memory, i think you must pick a maximum yourself e.g 250.000 vertices.
    This maximum will influence the ammount of video-ram required for your game.
    I do know for sure that it cant be bigger than 2^32 vertices ,because that's the highest value an vertex-index can have, but i think you already knew that. BTW: 2^32 seems big enough to me.

    If a were you i should ask this on the MSDN forums or take a look at the list of device-capabilities.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  9. #9

    Vertex Transform vs SetTransform(D3DTS_WORLD..

    Okay.. i did some tests and i agree that using the world-matrix gives a small speed increase :razz:

    I render 12 cubes, each at a different position.
    I have a 500Mhz Pentium III with a Geforce 2 MX/MX 400.

    FPS:
    Without worldmatrix transforms: approx 117
    With worldmatrix transforms: approx 124

    It was hard to get these values because the fps sometimes jumped form 125 tot 108. So these value's are not very reliable.

    Maybe i must calculate the approx fps for every 20 secs. This might give a better view on this.

    I also like to know your test results
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  10. #10

    Vertex Transform vs SetTransform(D3DTS_WORLD..

    I think the higher benefit is when rendering more complex geometry, I'll make some tests on that.

    By the way, I started working on my optimization method, hope to get good results.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •