Jump to content
  • Advertisement

Archived

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

Arrummzen

Objects that mutate in real time and efficency?

This topic is 5274 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

I have found the best way to work with non-mutating objects to be 1: Create Vertex buffer 2: Move the object around by changeing the world transformation. I now have to work with objects that change shape in real time, and therfor I can''t just change the world transformation. Do I have to recreate the Vertex buffer everytime? Thank you for your time, Arrummzen

Share this post


Link to post
Share on other sites
Advertisement
The world transformation is used to move from object space to world space. It has nothing to do with deforming your mesh.

And, to answer your question - not necessarily. There are a wide variety of methods for morphing a mesh, the most common one probably being a "tweening" method (google). You can also do deformations in the vertex shader, or manually alter your vertices.

Share this post


Link to post
Share on other sites
yeah, morphing and object is alot harder than just moving it around with a matrix.

easyest and slowest way to do it, is to use a dynamic vertex buffer (which allows for rapid change) and loop through each vertex in it each frame and move each vertex in it indvidually.

you could use a vertex shader, which does esentially the same thing but real time. like when the system goes to render each vertex in your vertex buffer, it runs some special code which looks like assembly (that you write yourself) on the vertex, allowing you to move it or whatever. this is alot faster, and also conciderably harder. it sounds like your new at this, so i wouldnt take this route.

the third way (and im a little shaky about this) is to use tweening. which stands for in-be-tweening. what it does is, if you have to meshes, whith the same # of vertices, say a square and a diamond. dx has some built in stuff which will make it easy to interpolate the vertices between the 2 meshses, so you could make the square morph into the diamond. i would go this route, and i think the sdk actually has a demo on this, hopefully you wont have to use vertex shaders to accomplish this effect but you might. in which case it would infinantly complicate the project, comming from a beginner level. stick with it though and good luck

Share this post


Link to post
Share on other sites
1: What kind of performance hit can I expect when using a dynamic vertex buffer?

2: What is a vertex shater''s code like? I am comfortable with x86 ASM (perferably Intel syntax, but I can work with AT&T syntax as well)? Can I access system memory from this? All I would need to do is move a vertex from global memory to the location in the vertex buffer?

3: I don''t think tweening will work because the movement of the vertexs is not fully perdictable. I don''t want make an of this behavior predeffined.

Thank you for your time,
Arrummzen

Share this post


Link to post
Share on other sites
As I understand it, vedio memory is memory maped and can be accessed like conventonal memory, its been a long time but as I recall I used to draw primitive user interfaces by writing characters directly to video memory.

And I believe that the vertex buffer is written to video memory as well. What I would like to do is "copy" a byte range (for every buffer) every frame from normal memory to video memory. Is that possible/efficent?

Thank you for your time,
Arrummzen

EDIT: My other option would be to add a condition to check and see if the vertex needs to be changed and then only recreate the Vertex Buffer as needed, but that would require many more instructions than simply copying it. movsd is fairly quick...

Thank you for your time,
Arrummzen



[edited by - Arrummzen on June 7, 2004 3:42:10 AM]

Share this post


Link to post
Share on other sites
quote:
2: What is a vertex shater's code like? I am comfortable with x86 ASM (perferably Intel syntax, but I can work with AT&T syntax as well)? Can I access system memory from this? All I would need to do is move a vertex from global memory to the location in the vertex buffer?


read this, and that and also this. This should answer some questions.

3 techniques to modify your vertices:
- tweening -> Use for morphing between two meshes. Consists in deducing a vertex given a source vertex, a destination vertex and a coefficient telling how much to mix those two. Easily done on the GPU using vertex shaders.
- skinning -> You displace the vertices according to bones. Imagine your skin as ... the skin mesh and your bones as ... the skeleton of the skin mesh. Now move the wrist bone, this will displace the flesh around it. Typically used in character animation. Can be done on the GPU as well as on the CPU depending on your constraints (number of bones, density of the skin mesh, ...)
- recomputing -> when you don't know if the source mesh and destination mesh will have the same number of vertices or if the mesh has to be computed from some algorithm (deformation of a solid, procedural mesh, height mapping, ...) not done on the GPU because of limited possibilities of vertex shaders (will change with vs 3.0 and with time).

Direct X handles the copy to video memory and persistance of information, no need to bother with that. Just create the vertex buffer with appropriate usage flags and use VB->Lock with proper flags.

In brief, you should tell for which purpose you need a dynamic VB so that you can choose one of the above methods.

Cheers,

Vincent

[edited by - vprat on June 7, 2004 7:47:14 AM]

[edited by - vprat on June 7, 2004 7:48:09 AM]

Share this post


Link to post
Share on other sites
quote:

What is a vertex shater''s code like?



It''s like this:


float4x4 matWorldViewProj;
float4 Light;
float Time;

struct VS_OUT
{
Pos : POSITION;
Norm : NORMAL;
Diffuse : COLOR0;
Tex : TEXCOORD0;
};

VS_OUT VShade(float4 Pos : POSITION, float4 Norm : NORMAL, float4 Tex : TEXCOORD0)
{
VS_OUT Out = (VS_OUT)0;
Out.Pos = mul(Pos,matWorldViewProj);
Out.Diffuse = dot(Norm,Light);
Out.Tex = Tex;
return Out;
}


As you can see, it''s just like C...for graphics.

Don''t let anyone trick you into thinking you have to use ASM for your shaders. There are 3 high level shader lanaguages: HLSL (for Direct3D), GLSL (for OpenGL), and Cg (a standard nVidia has been developing that is more or less the same as HLSL). Actually, you probably shouldn''t use the ASM anyway, unless you really know what you''re doing, because the compiler is probably a better optimizer than you are in the first place.

Share this post


Link to post
Share on other sites
Because 99.9% of the time my VBs won''t need to be changed I think I will stick with static VBs for now, but I will encapsolate my VB update code so that I can change it to something else latter if needed. Right now my app only uses 1-2% of the CPU time, so its not a big deal.

Thank you for your time,
Arrummzen

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!