Reputation: 73
I want to do something like that in screen transition using OpenGL(with shaders). I have been looking for some tutorial or something like that, but without any effect.
How can I achieve that effect?
Upvotes: 3
Views: 2827
Reputation: 394
Here is a method avoiding to fiddle with polygons and also allowing more varied effects:
Simply use a mask. I explain for one piece first: just draw your main textured quad falling in a random direction, but use a second texture to get its alpha. That second texture(the mask) is just a black image with a white piece drawn on it. Note that it allows to have any shape, not just a polygon. Now, it's already possible to do the effect you want by simply drawing the main quad several times using different masks, but that need many textures.
So, to use only one mask texture for all pieces, you can use shaders and instead of directly using the value of the mask as alpha, instead use the value N (or a range around N) to mean only opaque for piece N. You now just need to increment N before rendering each piece. To create the mask, draw a bitmap (with an image editor) with black zigzag and flood fill the created polygons with each shade of gray from your palette. If you need a lot of pieces you can use more than one channel.
BtW it should be easy to generate that mask using bitmap functions : simply create a bitmap, draw some random lines, scan it and use flood fill on each empty pixel, incrementing the color each time. At least that seems simpler than handling polygons cutting.
Now, what I like is that you can have irregular edges for free, and since you have a second texture, you can also use it to add effects on the main one, like your black borders or even shatered glass edges with various transparency levels.
Upvotes: 0
Reputation: 397
Just some ideas of how you can make a start..
google for random polygon code, or triangulating a rectangle Perlin noise, Voronoi Diagrams (as mentioned above) etc
Upvotes: 3
Reputation: 6797
One of the most popular algorithms for this kind of shattering effect involves Voronoi Diagrams. Researching that subject will give you details on an algorithm that can be highly controllable and give you a similar effect.
However, it produces convex polygons as cells. Your image has some concave pieces but a VD would be a very good start. You could, for example, achieve similar effects by merging some of the resulting polygons from a Voronoi Diagram.
Upvotes: 1