Making a mesh appear face by face

Started by
7 comments, last by C0lumbo 9 years, 9 months ago

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
Advertisement
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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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.

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

You don't forget how to play when you grow old; you grow old when you forget how to play.

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.

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

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

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


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.

This topic is closed to new replies.

Advertisement