Jump to content

  • Log In with Google      Sign In   
  • Create Account


Making a mesh appear face by face

  • You cannot reply to this topic
8 replies to this topic

#1 AvengerDr   Members   -  Reputation: 596

Like
0Likes
Like

Posted 14 July 2014 - 03:12 AM

Hi all, I'd like to build this animation effect. It should animate over time the appearance of a mesh by having its faces appear either randomly (ie from zero faces to all of them) or through some sort of pattern (ie given a starting face, have all the others appear through an expanding radius). One simple way to do it would be to animate the VertexBuffer, but it doesn't seem the brightest idea. 

 

Another idea I had would be to use a Vertex Struct having Alpha information and then in the vertex shader fetch from a 1D texture (or float array, which would be faster?) the corresponding alpha value for the given vertex. Perhaps it would be necessary to have a vertexId value in the vertex struct itself? So in the shader I could do (HLSL)

output.color.a = alphaValues[input.vertexId];

In theory if I set all three face vertices' alpha to zero, that face should disappear, correct? Assume that I am not using indices.

Are there any other possibly better ways to do it?


--Avengers UTD Chronicles - My game development blog

Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 12452

Like
4Likes
Like

Posted 14 July 2014 - 03:18 AM

DrawIndexedPrimitive(), DrawIndexed(), glDrawElements()—they all take the number of primitives to draw or the number of elements to process (which can be derived given the number of primitives to draw).

Why don’t you just draw starting with 0 triangles and slowly go up to the total triangles in the mesh?


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 AvengerDr   Members   -  Reputation: 596

Like
0Likes
Like

Posted 14 July 2014 - 03:23 AM

That's actually true, I didn't think about that! Thanks!

 

However, in that way the only possible appearance pattern would be the order in which the vertices were defined. I guess if I wanted to have some control, I could presort the vertices accordingly before rendering. I must have a habit of overthinking things :(


--Avengers UTD Chronicles - My game development blog

#4 L. Spiro   Crossbones+   -  Reputation: 12452

Like
0Likes
Like

Posted 14 July 2014 - 03:36 AM

If you want more control you can add a vertex parameter that is simply a single float value set randomly between 0 and 1.
The vertex buffer is created alongside your main vertex buffer and set to stream 1 (while the vertex buffer you normally use is set to stream 0).

The values from 0 to 1 indicate how long it takes each vertex to go from 0 alpha to full alpha.
When you want to begin the effect (generating different alpha buffers allows the effect to be different for each instance of the mesh) you put a per-instance timer from 0 to 1 that takes however long you want the effect to be (if you want it to last 5 seconds then it takes 5 seconds to go from 0 to 1) and inside the vertex shader each vertex’s alpha is set to saturate( fFadeTime * inRandomTime ) where inRandomTime is the special random number in the stream-1 vertex buffer.

 

Draw the whole vertex buffer every frame while increasing fFadeTime in the shader slowly.

 

Every vertex will fade in at random speeds in random spots until the whole mesh is displayed.

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#5 Buckeye   Crossbones+   -  Reputation: 3829

Like
7Likes
Like

Posted 14 July 2014 - 05:34 AM

You don't have to arrange the vertex buffer for the desired order. Create an index buffer for the order in which you want the faces to appear. When you want the faces to appear in a particular order, use the appropriate index buffer and draw the appropriate number of faces each frame. You can have several index buffers for various ways the faces are to appear/disappear. There may be a performance hit if one of the index buffers skips around a lot and you get cache misses. If so, then, when all the faces have appeared, switch back to the fastest index buffer.


Edited by Buckeye, 14 July 2014 - 05:34 AM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#6 unbird   Crossbones+   -  Reputation: 4882

Like
1Likes
Like

Posted 14 July 2014 - 06:23 AM

Another alternative (and assuming a newer API like DX10+) you could also use SV_PrimitiveID. Generate a alpha in you pixel shader procedurally or use the ID as a lookup index into a buffer/texture.



#7 AvengerDr   Members   -  Reputation: 596

Like
0Likes
Like

Posted 14 July 2014 - 10:27 AM

Thanks all, I'll try to implement my own version as soon as possible!

 

 

When you want to begin the effect (generating different alpha buffers allows the effect to be different for each instance of the mesh) you put a per-instance timer from 0 to 1 that takes however long you want the effect to be (if you want it to last 5 seconds then it takes 5 seconds to go from 0 to 1) and inside the vertex shader each vertex’s alpha is set to saturate( fFadeTime * inRandomTime ) where inRandomTime is the special random number in the stream-1 vertex buffer.

 

Just one clarification: if those two are both values between [0 and 1] with inRandomTime not changing over time, won't alpha = saturate(fFadeTime * inRandomTime) be equal to inRandomTime when fFadeTime reaches 1? Ie if inRandomTime is 0.5 when the timer has reached 1, the alpha value would be saturate(1 * 0.5) = 0.5


--Avengers UTD Chronicles - My game development blog

#8 L. Spiro   Crossbones+   -  Reputation: 12452

Like
0Likes
Like

Posted 14 July 2014 - 01:08 PM

I meant store (1.0f / (Rand( 0.1f, 1.0f )).

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#9 C0lumbo   Crossbones+   -  Reputation: 2133

Like
0Likes
Like

Posted 14 July 2014 - 11:31 PM


However, in that way the only possible appearance pattern would be the order in which the vertices were defined. I guess if I wanted to have some control, I could presort the vertices accordingly before rendering. I must have a habit of overthinking things sad.png

 

If you're using a simple single index buffer approach, you could still get a decent amount of variation.

 

Instead of starting at the start of the buffer, and increasing the count every time you render, start at some randomised point in the middle of the index buffer, and as you increase the desired number of triangles, randomise whether you're going to add the extra triangle by increasing the count alone, or by increasing the count and moving back the start point.

 

If the effect doesn't feel sufficiently randomised, then have 3 or 4 different index buffers to choose from at random, and the result will probably be noisy enough to appear completely random to the player.







PARTNERS