Jump to content
  • Advertisement
Sign in to follow this  
fromthefuture

How to transform each object individually?

This topic is 2659 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have this question, lets say my scene consists of 10 objects, and I need them all to have simple animations (such as one obj rotating and moving to the left, another moving down etc). Does that mean that each object needs a DrawIndexedPrimitive call? I'm asking because my scene consists of 1000s of individual polygons. And I want to be able to set an individual transform on each polygon to animate it in a unique way, does that mean I need 1000 DIP calls? How can this be done to maintain decent performance? Just to give more details on what I'm doing: I want to make a text editor but so that the individual letters can be animated in 3D space. So I have an indexed polygon for each letter, and what I want to do is lets say at one point apply a gravity field to each letter and make them all fall down, or apply a vortex and make them spin. But I need a way to set a transform per object while maintaining decent performance. Any ideas on how to do this?

Share this post


Link to post
Share on other sites
Advertisement
Hi, I don't exactly what is DrawIndexedPrimitive, I guess it send a draw command to render a mesh from an array of vertex attributes.
If you want to issue such a command only once, you can store the transformation matrix of an individual quad into its vertex attributes and apply the transformation into a vertex shader.

Share this post


Link to post
Share on other sites

Hi, I don't exactly what is DrawIndexedPrimitive, I guess it send a draw command to render a mesh from an array of vertex attributes.
If you want to issue such a command only once, you can store the transformation matrix of an individual quad into its vertex attributes and apply the transformation into a vertex shader.


I'm not exactly sure what you mean, can you give an example? I'm using DX9 w/ C++ but a general example would work also. Are you saying I should add D3DXMATRIX to my vertex format, and then use the vertex shader to transform each individual vertex? I have used vertex shaders before, but I'm not very familiar with them. Can I really accomplish this via this method? I'm sure that what I'm trying to do is a common problem, since in almost every game there are usually a bunch (100+) objects moving around.

Share this post


Link to post
Share on other sites
Sorry, I never used DX. So I can not provide an example. But I am almost sure this technique can be implemented in DX.

The main idea is to pass the model matrix (which must be D3DXMATRIX ) as a vertex attribute, as you do for the position or the color of a vertex.
Then you retrieve that matrix from a vertex shader, and just multiply it with the vertex position.

The technique will work, but you might need to do some benchmarking to measure to exact gain.

What is sure, is that it will save the matrix multiplication on the CPU and the multiple DIP calls, which saves CPU-GPU bandwith.

Share this post


Link to post
Share on other sites

Sorry, I never used DX. So I can not provide an example. But I am almost sure this technique can be implemented in DX.

The main idea is to pass the model matrix (which must be D3DXMATRIX ) as a vertex attribute, as you do for the position or the color of a vertex.
Then you retrieve that matrix from a vertex shader, and just multiply it with the vertex position.

The technique will work, but you might need to do some benchmarking to measure to exact gain.

What is sure, is that it will save the matrix multiplication on the CPU and the multiple DIP calls, which saves CPU-GPU bandwith.


Great, this looks like a plausible solution, I will try to look over the SDK samples, I think they have a few where they use VS for animation, Thanks ericbeg :)
P.S Your PXL lib, looks pretty cool, I'm actually looking for a small OGL lib that can do stereo rendering, can your camera class be used for that?

Share this post


Link to post
Share on other sites
You are welcome. Good luck with the implementation.

About PXL and stereo rendering, you can easily used two camera objects as the left and right eyes. Then render the scene twice from each camera. Once you have the two images, you can used whatever stereoscopy technique.

Share this post


Link to post
Share on other sites
What are you trying to do looks very similar to common particle systems (in your case one particle = 1 letter), maybe search for something about them and try to implement it exactly like a particle system.

Anyway, isn't it a huge waste to store the full 4x4 transformation matrix for each of your objects ("particles")? If you don't need scaling, you should do the same approach with just 3-element array for position and 3-element array for rotation (or maybe 4 - quaternion). And moreover - if you wanted to store a full transformation matrix for each of your polygons, you would have to build and update those matrices on CPU, and vertex shader would only multiply by them. That's doesn't sound like the best way how to split the strain between the CPU and GPU (just a guess, I didn't test it).
If you used your CPU just to update the position and rotation, you could do the transformation on the GPU, in vertex shader.

Share this post


Link to post
Share on other sites

You are welcome. Good luck with the implementation.

About PXL and stereo rendering, you can easily used two camera objects as the left and right eyes. Then render the scene twice from each camera. Once you have the two images, you can used whatever stereoscopy technique.



Thanks, actually tried doing just a plain 2 cam approach, the results are ok, but I read that if you use asymmetrical frustrums then the 3D will be much more "pleasing" to the eye, that why I want to use OpenGL, because DX doesn't allow asymmetry. But thanks anyways, I'll continue looking.


What are you trying to do looks very similar to common particle systems (in your case one particle = 1 letter), maybe search for something about them and try to implement it exactly like a particle system.


I also though that this resembles a particle system, but considering that I have every object (letter) that has individual transform (I guess meaning that I can't use instancing) can I still use this?


Anyway, isn't it a huge waste to store the full 4x4 transformation matrix for each of your objects ("particles")? If you don't need scaling, you should do the same approach with just 3-element array for position and 3-element array for rotation (or maybe 4 - quaternion). And moreover - if you wanted to store a full transformation matrix for each of your polygons, you would have to build and update those matrices on CPU, and vertex shader would only multiply by them. That's doesn't sound like the best way how to split the strain between the CPU and GPU (just a guess, I didn't test it).
If you used your CPU just to update the position and rotation, you could do the transformation on the GPU, in vertex shader.


But isn't that what ericbeg said? I'm going to try to squeze a matrix into my vertex structure, at each frame I would iterate over each vertex, updating it's transform matrix with the transform matrix of the polygon that it belongs to (this is being done on the cpu I belive) and then inside the vertex shader I would just multiply the vertex's transform by the worldViewProjection matrix to get the final transformed vertex. I'm not sure if that what you were saying, if not please correct me.

Some more questions regarding your post: How much of an impact would storing a full matrix per vertex have on the overall performance? If I use a quaternion do I have to implement all the quaternion functions on the gpu or does HLSL come with those functions already (from what I remember I tried using them for camera rotations back in the day, and didn't get too far since I had no clue about how they worked despite reading a million articles about them).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!