   how can I shatter my glass?
  hi guys,  I want to write an effect like shattering the image completely with shards of glass falling to the bottom, but I don''t have a good idea about how to break the glass into pieces, and the breaking algorithm should be simple and vivid,especially the shape of the piece should be as regular as possible, because they must be "falling".is it a "Mission Impossible"? please give some advice...Thanks a lot!
  This is just of my mind. Dunno if it works, performance ratio, visual effects, etc, but i think it might work.Say you have a rectangular window you want to break.Then model the window as it has alreday been shattered, but just not moved yet. If doing proper, the window will look "whole" while you keep the pieces at it''s original position. Then, when you break the glass, simply let gravity take the different pieces, and it will fall apart.   Electron"The truth can be changed simply by the way you accept it.""''General failure trying to read from file'' - who is General Failure, and why is he reading my file??"   ;  thank you,Electron!I think it should be a good idea when I''ve shattered the glass, but now, I have no idea about how to shatter it.;  I''ve seen it done on PS2. It''s perfectly doable. They didn''t tell me how they did it at the time, but I know how I''d approach it.Firstly, you''ve got your glass primitive. For the sake of simplicity, let''s say that it''s a quad (though this should work with any shape). Let''s also say that the place you hit the glass doesn''t matter - the glass will shatter evenly.All you really need to do is repeatedly ''slice'' this quad to get smaller pieces. Generate a bunch of places which are perpendicular to the glass, and use them to cut the glass into pieces.After that, just take Electron''s advice and treat it like a particle system. All the pieces would be convex shapes, so you should be able to draw them with triangle fans.   Richard "Superpig" Fine- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.Enginuity1 | Enginuity2 | Enginuity3 | Enginuity4 | Enginuity5ry. .ibu cy. .y''ybu. .abu ry. dy. "sy. .ubu py. .ebu ry. py. .ibu gy." fy. .ibu ny. .ebuPreserve wildlife: pickle a squirrel today! ;  How about generating the shards from the original piece of glass? Take your original impact/breakage point and create a bunch of random planes perpendicular to the glass and passing though the impact point. Perhaps jitter these about a bit to get something more random. Then use these to slice your original poly into lots of little ones (could be a slow process, you might have to choose only a few slicing planes).Then just animate your falling shards however you want (probably want to take impact velocity into account).Edit: I just realised you'd not get the radial fracture lines like this. So perhaps generate your random planes, then jitter these outwards from the center in groups. Each group should then provide both radial and outward fracture lines.   [edited by - OrangyTang on February 5, 2004 11:56:47 AM];  If you''re feeling really enterprising, try this out. As suggested, map your "glass" image onto a quad at first. Then, in texture space relative to the quad, locate the breaking point or point of impact. Have a number of lines which will radiate from the breaking point out to the edges of the quad in a star-burst type shape. Then, use recursive subdivision and displacement to make the lines jittered; randomly pick a point on the line, and split the line into two lines each connecting to that point, then randomly displace the point a short distance. Repeat this a few times for each line in your original star-burst and you should get a nice crackly pattern. Each time you create a subdivision, store the set of points generated in that pass. This should create several "rings" which are roughly concentric circles, but jittered by the displacement effect. Connect adjacent points in each ring to produce a spider-web sort of effect, with concentric "cracks" forming along larger, radial cracks.At this point you can simply use each of the generated points and edges as polys, and split the original quad into however many polygons you like. However, if you feel really sneaky, try overlaying the original set of points onto the texture you are "breaking." The broken image, even with none of the pieces moved, should now have lines across it where the glass has "fractured." Now you can do a simple pass on the overlay: for 2 or 3 pixels above and/or to the left of each line segment, place a white pixel. For 2 or 3 pixels below and/or to the right of a segment, place a black or dark green pixel. This should produce a bevel effect along the cracks, which will move along with the individual glass pieces, creating the illusion that each piece is solid and has depth.Finally, if you''re utterly insane, try coming up with a filter that will take your crack pattern and create a more realistic shading for the edges (i.e. not just light-and-dark) based on the slopes of the lines. Instead of overlaying the colored cracks onto your original image texture, overlay a solid white/red/pink/whatever map, similar to how you would use masking colors for transparent pixels. Then, as each frame of the shattered texture is rendered, look at the slope of the key-colored line in screen space, and use that slope to generate the highlighting. Re-overlay this lighting back onto the original texture just before rendering. If you do it right, you should end up with the highlights and shadows on the glass "shards" moving as the pieces fall down, which would add a huge amount of realism and polish to the effect.Of course, if you don''t have that much free time to play with, model each poly as a prism (i.e. give it depth) and simply Phong shade the top edge. Angle the camera appropriately so that you see the top/left edges of each shard as it falls.   PiQ Software  -  Tiny KeyCounter  -  Freon 2/7 Raytracing Accelerator;  thank you, all the warmhearted men, OrangyTang,ApochPiQ and superpig!I''ve learnt a lot~~;  i''m not trying to get off the topic of game developement, but i thought i''d point out this reminds me so much of ff x-2 entering battles ;  Shattering effects can be great fun, though. They also work great with sprites - take your quad, subdivide it a couple of times and split those smaller quads into triangles, and then give each triangle angular and linear velocities. Combined with explosions, it makes a neat ''boss destroyed'' effect ;  Having read all those wise posts from such an intelligent people  , I can't say nothing more that could help you. Hovewer, Tetrowar, my last game used something similiar to your 'shattered glass' effect for splash screen. Game is 2d tetris written in SDL, but it can help you a bit. I'll post here my glass breaking algorithm. You can watch working in Tetrowar, www.pongowar.prv.pl, game's in download section.void spliceScreen(SDL_Surface* what) {   bool x_done, y_done;   x_done = y_done = false; // is it end of splicing? int pos_x, pos_y;   pos_x = pos_y = 0; // where we are now int x_divider,y_divider; // length of blocks    SDL_Rect block;  //log("* Before splicing");    while (!x_done)    {x_divider = (rand()%PART_BLOCK_MAX_SIZE_X)+PART_BLOCK_MIN_SIZE_X; // min 10, max 60if (pos_x+x_divider >= SCR_SIZE_X) { x_done = true;  x_divider = SCR_SIZE_X - pos_x;    //log("* it's the end of x splicing"); } y_done = false;    while (!y_done) {  y_divider = (rand()%PART_BLOCK_MAX_SIZE_Y)+PART_BLOCK_MIN_SIZE_Y; // min 10, max 60  if (pos_y+y_divider >= SCR_SIZE_Y)   {    block.x = pos_x;    block.y = pos_y;    block.w = x_divider;    block.h = SCR_SIZE_Y - pos_y; // clipPartMgr.emitParticleBlock(block,what);    y_done = true;    pos_y = 0;    pos_x+=x_divider;    //log("* it's the end of y splicing");    continue;   }    else   {block.x = pos_x;    block.y = pos_y;    block.w = x_divider;    block.h = y_divider;    PartMgr.emitParticleBlock(block,what);  pos_y += y_divider;//log("* emited one particle");    continue;    }    }    }  }EDIT: fixed code tags    [edited by - Koshmaar on February 8, 2004 9:14:33 AM]