Jump to content
  • Advertisement
Sign in to follow this  
AvengerDr

Making a mesh appear face by face

This topic is 1438 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 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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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 :(

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites


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.

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!