Archived

This topic is now archived and is closed to further replies.

Pokemonster

Transform & Lightning

Recommended Posts

Hi there! I''m trying to figure out whats the best way to use T&L in my program. I''ve got a couple of 3d objects, each with it''s own world transformation matrix. The vertices have to be transformed into world space in order to be displayed. If I understand the secret behind T&L correctly, the trick is to define the vertices as untransformed. So each time in my renderloop, I set the desired transformation matrix, load the vertices into a vertex buffer and call "DrawPrimitive" and the vertices will be transformed by the GPU. My problem now, each object has its own transformation matrix, so I need to repeat the "set matrix" and "draw primitive" parts for each 3d object. Is this efficient ? or am I missing the point here ? ALex

Share this post


Link to post
Share on other sites
quote:
Original post by Pokemonster
Hi there!

I''m trying to figure out whats the best way to use T&L in my program.
I''ve got a couple of 3d objects, each with it''s own world transformation matrix. The vertices have to be transformed into world space in order to be displayed.
If I understand the secret behind T&L correctly, the trick is to define the vertices as untransformed.



Not really a trick, but yes

quote:

So each time in my renderloop, I set the desired transformation matrix,



Right.

quote:

load the vertices into a vertex buffer



It depends on the nature of your geometry. If it is static (ie Buildings) then it would be highly inefficient to create VBs every frame (creating VBs is expensive and should not be done in your rendering loop if it can be avoided). Instead you create your VBs before your rendering loop begins, lock-fill-unlock them.

If your geometry is of more dynamic nature (ie Billboards which have to be adjusted every frame to face the camera) then you would create a dynamic VB (call CreateVertexBuffer D3DUSAGE_DYNAMIC) - Dynamic VBs can be locked (preferably ONCE) every frame with a much lower performance penalty - and fill it every frame.

quote:

and call "DrawPrimitive" and the vertices will be transformed by the GPU.



Exactly.

quote:

My problem now, each object has its own transformation matrix, so I need to repeat the "set matrix" and "draw primitive" parts for each 3d object. Is this efficient ? or am I missing the point here ?



There is no general answer to this question. It depends on the amount of vertices you are rendering. But setting a new transformation matrix for every 20 triangles will surely incure severe performance penalties.

ALex

Share this post


Link to post
Share on other sites
There''s no way to get around the fact that you''ll need to set a different transform matrix for each object. It may be slower than not setting a new one.. but in the same way that drawing anything is slower than not drawing anything, if you get my meaning.

Share this post


Link to post
Share on other sites